a very simple solution (not the most elegant) for a watchdog is to create a cron job that executes a service that checks for another service's status.
sudo crontab -e
then put this line at the end of your crontab file (attention this will run evry minute of every day until you change crontab again)
* * * * * /usr/sbin/sample_service
then CTRL-X, Y, ENTER and reboot your machine.
this is an example of such a service:
#!/bin/bash
#
# watchdog
#
# Run as a cron job to keep an eye on what_to_monitor which should always
# be running. Restart what_to_monitor and send notification as needed.
#
# This needs to be run as root or a user that can start system services.
#
# Revisions: 0.1 (20100506), 0.2 (20100507)
NAME=sample_service
NAME2=sample_service2
START=/usr/sbin/$NAME
START2=/usr/sbin/$NAME2
NOTIFY=joe@gmail.com
NOTIFYCC=jim@mail.com
GREP=/bin/grep
PS=/bin/ps
NOP=/bin/true
DATE=/bin/date
# MAIL=/bin/mail
RM=/bin/rm
$PS -ef|$GREP -v grep|$GREP $NAME >/dev/null 2>&1
case "$?" in
0)
# It is running in this case so we do nothing.
echo "$NAME is RUNNING OK. Relax."
$NOP
;;
1)
echo "$NAME is NOT RUNNING. Starting $NAME and sending notices."
$START 2>&1 >/dev/null &
NOTICE=/tmp/watchdog.txt
echo "$NAME was not running and was started on `$DATE`" > $NOTICE
# $MAIL -n -s "watchdog notice" -c $NOTIFYCC $NOTIFY < $NOTICE
$RM -f $NOTICE
;;
esac
# GT06
$PS -ef|$GREP -v grep|$GREP $NAME2 >/dev/null 2>&1
case "$?" in
0)
# It is running in this case so we do nothing.
echo "$NAME2 is RUNNING OK. Relax."
$NOP
;;
1)
echo "$NAME2 is NOT RUNNING. Starting $NAME2 and sending notices."
$START2 2>&1 >/dev/null &
NOTICE=/tmp/watchdog.txt
echo "$NAME2 was not running and was started on `$DATE`" > $NOTICE
# $MAIL -n -s "watchdog notice" -c $NOTIFYCC $NOTIFY < $NOTICE
$RM -f $NOTICE
;;
esac
exit