Skip to content

Instantly share code, notes, and snippets.

@ukdave
Created April 20, 2015 07:31
Show Gist options
  • Save ukdave/dd17e3c638d446eebb89 to your computer and use it in GitHub Desktop.
Save ukdave/dd17e3c638d446eebb89 to your computer and use it in GitHub Desktop.
Generic watchdog script
* * * * * root /usr/local/bin/foo-watchdog.sh
/var/log/var/log/foo-watchdog.log {
rotate 5
daily
middingok
compress
copytruncate
}
#!/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