#! /bin/sh

# This script starts 'emailer', and will continually restart it
# anytime it is found to have died.

# The name of the host to be used:
NSI=example
# A settings file in the form "emailer.[hostname].ini" must be available:
INI=emailer.$NSI.ini
# The name of the PID tracking file, in the form "[hostname].emailer.pid":
PIDFILE=$NSI.emailer.pid

# loop forever checking
while  `echo yes > /dev/null`
do

#	echo "checking for emailer on $NSI"
	ps -ef | grep `cat $PIDFILE` | grep emailer > /dev/null
	if [ $? -eq 1 ]; then
		# the emailer is not running, start it up:
#		echo "starting emailer on $NSI"
		java -jar snw.emailer.jar -c $INI &
		echo $! > $PIDFILE
#	else
#		echo "sleeping"
	fi
	sleep 60
done
