.gitignore | ||
Dockerfile | ||
healthcheck.py | ||
README.md | ||
requirements.txt |
Healthcheck
A healthcheck script that pings services, and if they are unreachable, restarts any associated Docker containers.
This script was created in order to restart Cloudflare Tunnel containers that would become unresponsive and never recover without manually restarting them.
Tunnels becoming unresponsive happens regularly due to intermittent internet connectivity.
The containers are responsible for hosting the tunnels associated with the following services:
- Moshferatu.Dev (this site)
- Moshington
Running the Healthcheck Script
Prior to running the script, you must set the following environment variables (example values provided):
CHECK_INTERVAL=60
MOSHFERATU_DEV_URL=https://moshferatu.dev
MOSHFERATU_DEV_CONTAINER=moshferatu-dev-tunnel
MOSHINGTON_URL=https://moshington.com
MOSHINGTON_CONTAINER=moshington-tunnel
The healthcheck depends on python-dotenv
, so you can create a .env
file and place the variables in there.
Docker Container
The script can be run in a Docker container of its own.
The necessary Dockerfile is provided here.
Just build and run the container like any other, while making sure to set the necessary environment variables as mentioned above.
The Docker socket will need to be mounted as a volume, however.
An example of this can be found in the Healthcheck compose file.
This is necessary for the script to restart other containers running on the host.
Standalone Script
Make sure you have the dependencies listed in requirements.txt installed in addition to Docker.
Then, run the following command:
python ./healthcheck.py
Again, make sure to set the necessary environment variables before running the script.