Created
April 20, 2015 07:31
-
-
Save ukdave/dd17e3c638d446eebb89 to your computer and use it in GitHub Desktop.
Generic watchdog script
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
* * * * * root /usr/local/bin/foo-watchdog.sh |
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
/var/log/var/log/foo-watchdog.log { | |
rotate 5 | |
daily | |
middingok | |
compress | |
copytruncate | |
} |
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 | |
LOG=/var/log/foo-watchdog.log | |
PIDFILE=/var/run/foo.pid | |
# Check watchdog script isn't already running | |
count=`pgrep -c -f $0` | |
if [ $count -gt 2 ]; then | |
exit 0 | |
fi | |
# Restart process if PID file is present but the process is not running | |
if [ -f $PIDFILE ]; then | |
PROC_ID=`pgrep -u foo foo` | |
if [ -z $PROC_ID ]; then | |
echo "`date` - Foo has crashed - restarting.." >> $LOG | |
/etc/init.d/foo start >> $LOG 2>&1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment