Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheAlienKnight/10cf606ff05c78b65f9b38ccaca56afe to your computer and use it in GitHub Desktop.
Save TheAlienKnight/10cf606ff05c78b65f9b38ccaca56afe to your computer and use it in GitHub Desktop.
#!/bin/bash
status_code=$(curl --write-out %{http_code} --silent --output /dev/null https://server.tld)
logfile=bandaid-log-$(date -I).txt
if [[ "$status_code" -ne 200 ]] ; then
touch $logfile # This is only here for the sake of compatibility
echo "[$(date +%s)][Bandaid] Site status changed to $status_code" >> $logfile
echo "[$(date +%s)][Bandaid] Saving mastodon container logs for evaluation..." >> $logfile
tmp=$(date +%F_%T)
docker compose logs --since 5m > docker-bandaid-log-$(date +%F_%T).txt # This grabs *all* the container logs in docker-compose.yml, to help evaluate the root cause
echo "[$(date +%s)][Bandaid] Saved to docker-bandaid-log-$(tmp).txt" >> $logfile
echo "[$(date +%s)][Bandaid] Restarting the web container..." >> $logfile
docker compose restart web >> $logfile # Saves any errors that may come about Note: (You may be using docker-compose)
echo "[$(date +%s)][Bandaid] Done. Rechecking in 60s." >> $logfile
else
exit 0
fi
##########################
Example Crontab Entry (Recheck every 60s)
##########################
* * * * * bash /your/directory/check502.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment