health-check.sh 826 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. #Network check
  3. # Ping uses both exit codes 1 and 2. Exit code 2 cannot be used for docker health checks,
  4. # therefore we use this script to catch error code 2
  5. HOST=${HEALTH_CHECK_HOST}
  6. if [[ -z "$HOST" ]]
  7. then
  8. echo "Host not set! Set env 'HEALTH_CHECK_HOST'. For now, using default google.com" | ts '%Y-%m-%d %H:%M:%S'
  9. HOST="google.com"
  10. fi
  11. ping -c 1 $HOST
  12. STATUS=$?
  13. if [[ ${STATUS} -ne 0 ]]
  14. then
  15. echo "Network is down" | ts '%Y-%m-%d %H:%M:%S'
  16. exit 1
  17. fi
  18. echo "Network is up" | ts '%Y-%m-%d %H:%M:%S'
  19. #Service check
  20. #Expected output is 2 for both checks, 1 for process and 1 for grep
  21. OPENVPN=$(pgrep openvpn | wc -l )
  22. if [[ ${OPENVPN} -ne 1 ]]
  23. then
  24. echo "OpenVPN process not running" | ts '%Y-%m-%d %H:%M:%S'
  25. exit 1
  26. fi
  27. echo "OpenVPN process is running" | ts '%Y-%m-%d %H:%M:%S'
  28. exit 0