#!/bin/sh

# This shell script should be setuid to the owner of Empie ($DEITY).
# It should be made available in a public place for people to reboot
# the empire clients with.
#
# Author: Chris Metcalf (metcalf-christopher@CS.Yale.EDU)

EMPIRE=/yale/games/lib/empire/EMP
LOGFILE=$EMPIRE/empwatch_log
DEITY=metcalf
HOSTNAME=yale-zoo-suned

exec >> $LOGFILE 2>&1
echo "restart requested at `date`"			| tee /dev/tty
who am i

if [ $HOSTNAME != `hostname` ]
then
	echo "emprestart: must be run on $HOSTNAME"	| tee /dev/tty
	exit 1
fi

if skill -0 $DEITY empserver &&
	skill -0 $DEITY empire_tmserver &&
	skill -0 $DEITY killd
then if [ x$1 != x-f ]
     then
	echo "empire is currently running.  mail to $DEITY to restart." | 
		tee /dev/tty
	tail $LOGFILE  | /bin/mail $DEITY &
	exit 1
     else
	echo "empire is currently running.  This may disrupt some players!" |
		tee /dev/tty
     fi
fi
cd $EMPIRE/BIN
skill $DEITY empserver killd empire_tmserver emp_serv
../../BIN/esck -y
nice -1 empserver &
nice -1 empire_tmserver &
echo "empire restarted at `date`"		| tee /dev/tty
tail $LOGFILE | /bin/mail $DEITY &
