docker-transmission-openvpn/scripts/healthcheck.sh
Patrick Kishino 9d975aba54
merge in latest dev (#1712)
* Brush up proxy and rss plugin images, build for multiarch support #1483

* Escape special characters in rss-plugin input variables #1565

* Increase healthcheck ping timeout (#1627)

* Add DNS resolution checks (fix #1608) (#1617)

* Add dns resolution test to healthcheck script

* Add dns resolution test to start script

Co-authored-by: Patrick Kishino <patrick.a.kishino@gmail.com>

* Fix PIA infinite redirect on config download (see #1619) (#1620)

PIA download link was redirecting and setting a cookie, but those are
disabled by default unless `--cookie` or `--cookie-jar` are given. Since
the cookie was not set, the redirection was attempted again until we
reached the maximum redirection limit.

The `--cookie /dev/null` specifies an empty input cookie, which has the
effect to enable curl's handling of cookies.

Co-authored-by: Kristian Haugene <kristian@haugene.net>
Co-authored-by: clement-z <6691770+clement-z@users.noreply.github.com>
2021-02-12 09:23:42 +09:00

49 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
#Network check
# Ping uses both exit codes 1 and 2. Exit code 2 cannot be used for docker health checks,
# therefore we use this script to catch error code 2
HOST=${HEALTH_CHECK_HOST}
if [[ -z "$HOST" ]]
then
echo "Host not set! Set env 'HEALTH_CHECK_HOST'. For now, using default google.com"
HOST="google.com"
fi
# Check DNS resolution works
nslookup $HOST > /dev/null
STATUS=$?
if [[ ${STATUS} -ne 0 ]]
then
echo "DNS resolution failed"
exit 1
fi
ping -c 2 -w 10 $HOST # Get at least 2 responses and timeout after 10 seconds
STATUS=$?
if [[ ${STATUS} -ne 0 ]]
then
echo "Network is down"
exit 1
fi
echo "Network is up"
#Service check
#Expected output is 2 for both checks, 1 for process and 1 for grep
OPENVPN=$(pgrep openvpn | wc -l )
TRANSMISSION=$(pgrep transmission | wc -l)
if [[ ${OPENVPN} -ne 1 ]]; then
echo "Openvpn process not running"
exit 1
fi
if [[ ${TRANSMISSION} -ne 1 ]]; then
echo "transmission-daemon process not running"
exit 1
fi
echo "Openvpn and transmission-daemon processes are running"
exit 0