Created
July 21, 2020 06:32
-
-
Save coreymckrill/cd07a19c7f14dacea322d542210bb544 to your computer and use it in GitHub Desktop.
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/sh | |
# Watch for cloudflared failures and restart the service. | |
# | |
# This is necessary due to a known issue between cloudflared and Raspberry Pis: | |
# https://github.com/cloudflare/cloudflared/issues/23 | |
# | |
# Script based on reddit thread: | |
# https://www.reddit.com/r/pihole/comments/b94dcr/cloudflare_dns_over_https_doesnt_work_after_a/err2rbj/ | |
# | |
# Steps: | |
# | |
# Install procmail (for lockfile) | |
# sudo apt-get install procmail | |
# | |
# Place this script somewhere like ~/scripts/cloudflared-watchdog.sh | |
# | |
# Add a cron: | |
# * * * * * root /bin/sh /absolute/path/to/cloudflared-watchdog.sh | |
# | |
TEMP_STATUS="/tmp/cloudflared.status" | |
TEMP_ERR="/tmp/cloudflared.error" | |
TEMP_LOCK="/tmp/cloudflared-watchdog.lock" | |
lockfile -r 0 $TEMP_LOCK || exit 1 | |
sudo systemctl status cloudflared > $TEMP_STATUS | |
cat $TEMP_STATUS | grep "failed to connect to an HTTPS backend" > $TEMP_ERR | |
cat $TEMP_STATUS | grep "failed to perform an HTTPS request" >> $TEMP_ERR | |
if [ -s $TEMP_ERR ]; then | |
sudo systemctl restart cloudflared | |
fi | |
rm -f $TEMP_STATUS $TEMP_ERR $TEMP_LOCK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment