Last active
November 4, 2016 21:55
-
-
Save auckenox/6e61db976892b691c59f1a59cc1b4b60 to your computer and use it in GitHub Desktop.
basic watchdog for python (or other) scripts
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 | |
watchdog () { | |
datum=$(date -u) | |
scna="$(basename $1)" | |
ps -ef | grep $1 | grep -v grep; | |
if [[ $? -eq 0 ]]; then | |
echo "$datum - OK, $scna is running"; | |
else | |
echo "$datum - $1 died, resurrecting $scna now..."; | |
screen -d -m -S $scna /usr/bin/python $1 2>&1 /dev/null | |
fi | |
} | |
watchdog "/home/pi/locker-btn1.py" | |
watchdog "/home/pi/locker-btn2.py" | |
# add a cronjob to this script, one at reboot and one every minute */1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment