Created
March 31, 2020 23:29
-
-
Save RealLukeManning/c8e48b2cedafc7ab079e98d203ac1c9e to your computer and use it in GitHub Desktop.
Check status of Docker and attempt to restart the service it's stopped. If something goes wrong it will notify Telegram.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A simple bash script to check the current status of my Docker service | |
# If the 'rc.docker status' command returns anything other than "running" a message is sent to my Telegram bot | |
# The script will attempt to restart Docker and send the result to Telegram | |
TOKEN="" | |
CHAT_ID="" | |
URL="https://api.telegram.org/bot$TOKEN/sendMessage" | |
DOCKER_STATUS_FULL="$(/etc/rc.d/rc.docker status)" | |
DOCKER_STATUS=$(echo "$DOCKER_STATUS_FULL" | head -n1) | |
if [ "$DOCKER_STATUS" != "status of dockerd: running" ] | |
then | |
MESSAGE="Looks like we might have a problem with Docker! | |
$DOCKER_STATUS_FULL | |
Attempting to restart Docker..." | |
curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MESSAGE" | |
START_DOCKER="$(/etc/rc.d/rc.docker start)" | |
curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$START_DOCKER" | |
DOCKER_STATUS_FULL_RESTARTED="$(/etc/rc.d/rc.docker status)" | |
curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$DOCKER_STATUS_FULL_RESTARTED" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment