#!/bin/sh
#

# check -- Check to see if the MUSH's up and running
#          If not, restart and inform.
#
# By Corey@FunkyMush (Bill Braughton, wmb@sodapop.cc.LaTech.edu)

#
# Editor's note: If your restart script is not careful, this 
# autorestarter could cause you to lose old db's - make sure your
# restart script preserves the old indb and the one before that
# before you start using this! - Javelin
#

#
# Install a cron entry that looks like this:
# #  Minutes  Hours DofM Month DofW                Command
# #--------------------------------------------------------------------------
#  00,15,30,45  *    *     *    * /path-to-check/check > /dev/null 2>&1 &
# 

# We need to set up our path up so all of our commands will
# be found. Cron doesn't give us much of a path to work with.
# Modify this to have the path where this script lives.

PATH=/bin:/usr/bin:/usr/local/bin/:/usr/src/mush
export PATH

# Change this to where you will keep the report messages
# that will be mailed to you. In this directory, make a file
# called mush.good and one called mush.error. These get mailed
# to you when everything's ok, and when there's a problem.
MUSHMAIL=/usr/src/mush/game/check

# Change this to where the 'restart' script for your mush is
GAMEDIR=/usr/src/mush/game

# Your preferred e-mail address where all your your good/bad
# reports will be sent
EMAIL=

# Uncomment one of the following lines
# For BSD systems:
#mush=`ps -aux | fgrep conf | fgrep -v fgrep | wc -l`
# For SYSV systems:
#mush=`ps -ef | fgrep conf | fgrep -v fgrep | wc -l`

if [ $mush -gt 0 ]; then
  echo Your MUSH is up and running.
# Include this line if you like to get email that your MUSH is up
# every 15 minutes:
# mail $EMAIL < $MUSHMAIL/mush.good
  exit 0
else
  echo Your MUSH is not up and running.
# This line should contain what you type to restart your MUSH:
  $GAMEDIR/restart 
  mail $EMAIL < $MUSHMAIL/mush.error
fi

