2024-11-13 14:27:52 +00:00
# Healthcheck
2024-11-15 19:21:03 +00:00
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 ](https://moshferatu.dev/ ) (this site)
* [Moshington ](https://moshington.com/ )
2024-11-15 19:31:43 +00:00
## Running the Healthcheck Script
Prior to running the script, you must set the following environment variables (example values provided):
```shell
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 ](./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.
2024-11-15 19:52:11 +00:00
The Docker socket will need to be mounted as a volume, however.
An example of this can be found in the [Healthcheck compose file ](https://moshferatu.dev/moshferatu/docker-compose/src/branch/main/healthcheck.yaml ).
2024-11-15 19:52:54 +00:00
This is necessary for the script to restart other containers running on the host.
2024-11-15 19:31:43 +00:00
### Standalone Script
Make sure you have the dependencies listed in [requirements.txt ](./requirements.txt ) installed in addition to Docker.
Then, run the following command:
```shell
python ./healthcheck.py
```
Again, make sure to set the necessary environment variables before running the script.
2024-11-13 14:27:52 +00:00
---