diff --git a/Dockerfile b/Dockerfile index 39e85bf02..15483cb71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index d9ff37af5..e7c7ae2c9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh new file mode 100755 index 000000000..dc669e277 --- /dev/null +++ b/scripts/healthcheck.sh @@ -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 +