Originally posted on: https://blog.turboapi.dev/docker-check/
Making sure your application is running is critical to ensure that customers can always use your app. I recently had a problem where I realised I only had the TurboAPI status page (https://status.turboapi.dev) to monitor the uptime of my app.
So what could I do? Unfortunately, I can't use TurboAPI to monitor TurboAPI. But, like levelsio I love a quick and dirty script. So, I decided to write one that would do the following:
Like me, you are probably an IndieHacker running an app inside Docker on an Ubuntu server somewhere. To use it you need to simply generate some Slack webhook URL's and replace the "hooks.slack.com" link with them. Additionally, change "turboapi_app" with the name of your container.
Hope you enjoy!
#!/bin/bash
result=$( docker ps -q -f name=turboapi_app )
echo "Checking container's exist"
systemctl show --property ActiveState docker | grep 'ActiveState=active' &> /dev/null
if [ $? != 0 ]; then
message="🐳 Docker is Not Running!"
echo $message
curl -X POST --data-urlencode "payload={\"text\":\"${message}\"}" https://hooks.slack.com/services/XXX
fi
if [[ -n "$result" ]]; then
echo "Container exists"
else
message="🔴 TurboAPI Container does not exist"
curl -X POST --data-urlencode "payload={\"text\":\"${message}\"}" https://hooks.slack.com/services/XXXX
fi