I actually did mine using Dockerfile HEALTHCHECK (Search the page.).
Dockerfile exerpt: ADD healthcheck.sh /usr/local/bin/healthcheck.sh RUN chmod +x /usr/local/bin/healthcheck.sh HEALTHCHECK --interval=30s --timeout=12s --start-period=10s --retries=3 \ CMD /usr/local/bin/healthcheck.sh
healthcheck.sh: cat healthcheck.sh #!/bin/bash HOME_IP="<<<< PUT YOUR IP HERE >>>" VPN_IP=$(curl -s ipinfo.io/ip) echo $HOME_IP echo $VPN_IP
if [ "$HOME_IP" == "$VPN_IP" ]; then
echo "ERROR: Home IP (hard coded into this script as ${HOME_IP}) is the same
as your VPN IP."
exit 1
fi
I then have a crontab which runs every minute on the Docker host: */1 * * * * /usr/local/bin/healthcheck_transmission_checker.sh
healthcheck_transmission_checker.sh:
log(){
echo "$1" | logger -t [$0]
}
is_running="$(docker inspect --format='{{json .State.Running}}' transmission)"
case $is_running in
"true")
#log "Transmission is running."
health_status=$(docker inspect --format='{{json .State.Health.Status}}' transmission)
#log "Transmission health: $health_status"
if [ $health_status == "\"unhealthy\"" ]; then
log "Transmission is currently unhealthy."
log "STOPPING THE TRANSMISSION CONTAINER."
docker stop transmission
fi
;;
"false")
log "Is not running."
# TODO: Should add an email alert here at somepoint.
;;
*) log "Unknown state";;
esac