#!/bin/sh # this script is a watchdog to see whether the server is online # It tries to restart the server, and if it's # down it sends an email alert to admin # # Put a line in your crontab to run this every 30 minutes or so: # 0,30 * * * * /usr/local/bin/mysql.watchdog >/dev/null 2>&1 # For example # (friendly) Name of service SVC="mysql" # Admin's email EMAIL=josh@hewbert.com # the path to PID file PIDFILE=/var/db/mysql/`/bin/hostname -s`.pid # Path to the daemon executable or init script, including any options RC="/usr/local/etc/rc.d/mysql-server.sh start" # ---------------------------------------------------------- # check for pidfile if [ -f $PIDFILE ] ; then PID=`cat $PIDFILE` if kill -0 $PID; then STATUS="$SVC (pid $PID) running" RUNNING=1 else STATUS="$SVC (pid $PID?) not running" RUNNING=0 fi else STATUS="$SVC (no pid file) not running" RUNNING=0 fi if [ $RUNNING -eq 0 ]; then echo "$0 $ARG: $SVC not running, trying to start" if $RC ; then echo "$0 $ARG: $SVC started" mail $EMAIL -s "$0 $ARG: $SVC started" > /dev/null 2>&1 else echo "$0 $ARG: $SVC could not be started" mail $EMAIL -s \ "$0 $ARG: $SVC could not be started" > /dev/null 2>&1 fi fi