#!/bin/sh # @configure_input@ # # Optional arguments are port numbers. # If none are given, defaults to 4201. # prefix=@prefix@ exec_prefix=@exec_prefix@ # # You'll want to edit this to match the base directory of your muck's files. # This should be the directory containing the 'data' and 'muf' directories. # GAMEDIR="@localstatedir@/fbmuck" # If you want your database to be accessible by someone other than the # user the MUCK is running under, you should change this to the appropriate # umask value. 077 is owner-only. UMASK=077 # # The following are the paths to the db files to load, save to, and archive to. # DBOLD is the path and filename of the the previous database archive. # DBIN is the path and filename of the database to read in. # DBOUT is the path and filename of the database that the muck should save to. # # On a successful restart, DBIN is moved to DBOLD, and DBOUT is moved to DBIN, # then the server is started. The server will save it's db to DBOUT. # DBOLD="$GAMEDIR/data/std-db.old" DBIN="$GAMEDIR/data/std-db.db" DBOUT="$GAMEDIR/data/std-db.new" # # The ports that the MUCK server should listen to. This will be overridden if # this script is called with port number arguments. # PORTS=4201 # # It's doubtful you will want to change this, unless you compile a different # path and filename into the server. This is the file that deltadumps are # saved to. After a successful restart, these deltas will be appended to the # end of the DBIN file. # DELTAS="$GAMEDIR/data/deltas-file" # # This is the name of the netmuck program to run. You probably don't want to # change this unless you renamed the server program to something other than # fbmuck. # SERVER="@bindir@/fbmuck" # # This is the name of the file to log server restarts to. # RESTARTS_LOGFILE="$GAMEDIR/logs/restarts" # # This is the name of the file that the netmuck program creates that contains # the process ID of the server currently running in this game directory. # You probably don't want to change this unless you change the PID_FILE # #define in include/config.h # PIDFILE="$GAMEDIR/netmuck.pid" # # You probably won't need to edit anything after this line. # ############################################################################# ############################################################################# if [ -x /usr/ucb/ps ]; then PS="/usr/ucb/ps x" elif ps x >> /dev/null 2>&1 ; then PS="ps x" else PS="ps -e" fi cd $GAMEDIR # echo "Restarting at: `date`" umask $UMASK # Maximize resource limits ulimit -n `ulimit -Hn` ;# let us use all descriptors our hardlimit allows. ulimit -t `ulimit -Ht` ;# let us use all CPU time our hardlimit allows. if [ -r $PIDFILE -a -s $PIDFILE ]; then muckpid=`cat $PIDFILE` if [ "x$muckpid" != "x" ]; then serverexec=`basename $SERVER` muck=`${PS} | grep "${serverexec}" | awk '{print $1}' | egrep "\\<${muckpid}\\>" | wc -l` if [ $muck -gt 0 ]; then echo "This server is already running. Restart aborted." exit 0 fi fi fi datestamp=`date +%m%d%y%H%M` PANICDB="${DBOUT}.PANIC" if [ -r $PANICDB ]; then end=`tail -1 $PANICDB` if [ "x$end" = "x***END OF DUMP***" ]; then mv $PANICDB $DBOUT rm -f $DELTAS else echo "Warning: PANIC dump failed on "`date` | mail `whoami` fi fi if [ -r $DBOUT ]; then # mv $DBOLD $DBOLD.$datestamp mv -f $DBIN $DBOLD mv $DBOUT $DBIN fi if [ ! -r $DBIN ]; then echo "Hey\! The "$DBIN" file has to exist and be readable to restart the server\!" echo "Restart attempt aborted." exit fi end=`tail -1 $DBIN` if [ "x$end" != 'x***END OF DUMP***' ]; then echo "WARNING\! The "$DBIN" file is incomplete and therefore corrupt\!" echo "Restart attempt aborted." exit fi # nice -20 gzip -9 $DBOLD.$datestamp & if [ -r $DELTAS ]; then echo "Restoring from delta." end=`tail -1 $DELTAS` if [ "x$end" = "x***END OF DUMP***" ]; then cat $DELTAS >> $DBIN else echo "Last delta is incomplete. Truncating to previous dump." grep -n '^***END OF DUMP***' $DELTAS | tail -1 > .ftmp$$ llinum=`cut -d: -f1 < .ftmp$$` llcnt=`wc -l < .ftmp$$` if [ $llcnt -gt 0 ]; then head -$llinum $DELTAS >> $DBIN else echo "Hmm. No previous delta dump." fi rm .ftmp$$ fi rm -f $DELTAS fi dbsiz=`ls -1s $DBIN | awk '{print $1}'` diskfree=`df -k . | tail -1 | awk '{print $4}'` diskneeded=`expr $dbsiz \* 3` spacediff=`expr $diskneeded - $diskfree` if [ $diskfree -lt $diskneeded ]; then echo "WARNING: you have insufficient disk space." echo "The server is starting anyways, but you should immediately remove" echo "old log files, etc. to free up about ${spacediff}K more disk space." fi if [ "x$*" != "x" ]; then PORTS=$* fi touch $RESTARTS_LOGFILE echo "`date` - `who am i`" >> $RESTARTS_LOGFILE # echo "Server started at: `date`" $SERVER -gamedir $GAMEDIR -dbin $DBIN -dbout $DBOUT $PORTS