Merge pull request #708 from btimbermont/master

Added a health check
This commit is contained in:
Kristian Haugene 2019-03-09 16:44:02 +01:00 committed by GitHub
commit 0c2c47aa82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View File

@ -39,6 +39,9 @@ RUN apt-get update \
ADD openvpn/ /etc/openvpn/
ADD transmission/ /etc/transmission/
ADD tinyproxy /opt/tinyproxy/
ADD scripts /etc/scripts/
RUN chmod a+x /etc/scripts/healthcheck.sh
ENV OPENVPN_USERNAME=**None** \
OPENVPN_PASSWORD=**None** \
@ -129,7 +132,10 @@ ENV OPENVPN_USERNAME=**None** \
TRANSMISSION_WEB_HOME= \
DROP_DEFAULT_ROUTE= \
WEBPROXY_ENABLED=false \
WEBPROXY_PORT=8888
WEBPROXY_PORT=8888 \
HEALTH_CHECK_HOST=google.com
HEALTHCHECK --interval=5m CMD /etc/scripts/healthcheck.sh
# Expose port and run
EXPOSE 9091

View File

@ -167,6 +167,14 @@ If TRANSMISSION_PEER_PORT_RANDOM_ON_START is enabled then it allows traffic to t
|`UFW_EXTRA_PORTS` | Allows the comma separated list of ports through the firewall. Respects UFW_ALLOW_GW_NET. | `UFW_EXTRA_PORTS=9910,23561,443`|
|`UFW_DISABLE_IPTABLES_REJECT` | Prevents the use of `REJECT` in the `iptables` rules, for hosts without the `ipt_REJECT` module (such as the Synology NAS). | `UFW_DISABLE_IPTABLES_REJECT=true`|
### Health check option
Because your VPN connection can sometimes fail, Docker will run a health check on this container every 5 minutes to see if the container is still connected to the internet. By default, this check is done by pinging google.com once. You change the host that is pinged.
| Variable | Function | Example |
|----------|----------|-------|
| `HEALTH_CHECK_HOST` | this host is pinged to check if the network connection still works | `google.com` |
### Permission configuration options
By default the startup script applies a default set of permissions and ownership on the transmission download, watch and incomplete directories. The GLOBAL_APPLY_PERMISSIONS directive can be used to disable this functionality.

22
scripts/healthcheck.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
# 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 'HEATH_CHECK_HOST'. For now, using default google.com"
HOST="google.com"
fi
ping -c 1 $HOST
STATUS=$?
if [ $STATUS -ne 0 ]
then
echo "Network is down"
exit 1
fi
echo "Network is up"
exit 0