#!/bin/sh
#
-
# usage: restart
+#
+# REQUIRED: You must set this to the path to your game directory.
+# E.g.: /home/mush/game
+GAMEDIR=`pwd`
-#-- options
-
-# If this doesn't work, you can set GAMEDIR to the directory this
-# script lives in by hand.
-GAMEDIR=`which $0 | sed 's/\/[^\/]*$//'`
-
-# The config file
-CONF_FILE=mush.cnf
+# OPTIONAL things that you may want to tweak.
-# The error log file
-LOG=log/netmush.log
+# Name of file to write the game's process id to. Used by restart to
+# check for an already running game.
+PIDFILE=netmush.pid
# Uncomment the line below to attempt to allow crashes to produce
# core dumps. If you're getting crashes, this is the best way
# to debug them.
#ulimit -c unlimited
-
-# Uncomment the line below to attempt to allow crashes to produce
-# core dumps. If you're getting crashes, this is the best way
-# to debug them.
-#ulimit -c unlimited
-
-if [ ! -d "$GAMEDIR" ]; then
- echo "GAMEDIR doesn't appear to be a directory. It's: $GAMEDIR"
- exit 1
-fi
-
-cd $GAMEDIR
-echo Running from `pwd`
-
-if [ ! -f "$CONF_FILE" ]; then
- echo "CONF_FILE doesn't exist. It's: $CONF_FILE"
- echo "Create $CONF_FILE from $GAMEDIR/mushcnf.dst and run 'make update'"
- exit 1
-fi
-
# Internationalization stuff
# Set LANG here to get international character sets and, if someone's
# done it, translation of messages.
# Time zone stuff
# If you want your MUSH to run in a different timezone than the one
-# you're in, you need to identify the target time zone file in
+# you're in, you need to identify the target time zone file in
# /usr/share/zoneinfo or /usr/lib/zoneinfo. Then uncomment the next
# two lines and set TZ to the desired timezone file, as shown, with
# an initial colon:
cd $GAMEDIR
echo Running from `pwd`
-if [ ! -f $CONF_FILE ]; then
- echo "CONF_FILE doesn't exist. It's: $CONF_FILE"
- echo "Create $CONF_FILE from $GAMEDIR/mushcnf.dst"
- exit 1
-fi
-
-
-# The config file. Best to keep this as is. If you must change
-# the name, make it a link to mush.cnf.
-CONF_FILE=mush.cnf
-
-#######################################################################
-
-if [ -z $GAMEDIR ]; then
- echo "You must set GAMEDIR in the restart script."
- exit 1
-fi
-
-if [ ! -d $GAMEDIR ]; then
- echo "GAMEDIR doesn't appear to be a directory. It's: $GAMEDIR"
- exit 1
-fi
-
-cd $GAMEDIR
-echo Running from `pwd`
-
-if [ ! -f $CONF_FILE ]; then
+if [ ! -f "$CONF_FILE" ]; then
echo "CONF_FILE doesn't exist. It's: $CONF_FILE"
- echo "Create $CONF_FILE from $GAMEDIR/mushcnf.dst"
+ echo "Create $CONF_FILE from $GAMEDIR/mushcnf.dst and run 'make update'"
exit 1
fi
if [ ! -e netmush ]; then
echo "I don't see $GAMEDIR/netmush. Did you remember to make install?"
exit 1
-fi
+fi
#
# Read the cnf file and set some variables.
COMPRESSOR=`egrep "^compress_program" $CONF_FILE | sed "s/[^[:space:]]*[[:space:]]*\(.*\)/\1/" | sed 's/\r$//'`
SUFFIX=`egrep "^compress_suffix" $CONF_FILE | sed "s/[^[:space:]]*[[:space:]]*\(.*\)/\1/" | sed 's/\r$//'`
fi
-
+
#-- start up everything
# Prevent double-starting things. You may need to provide a pathname for
# some of the commands. System V flavors need "ps -f" instead of "ps uwx".
-mush=`ps uwwx | grep " $GAMEDIR/$CONF_FILE" | grep -v grep | wc -l`
+# Old style, look for a program using the config file.
+#mush=`ps uwwx | grep " $GAMEDIR/$CONF_FILE" | grep -v grep | wc -l`
+# if [ "$mush" -gt 0 ]; then
-if [ "$mush" -gt 0 ]; then
+# New style, look for a pid file.
+if [ -f $PIDFILE ]; then
+ foo=`kill -0 \`cat $PIDFILE\` 2>/dev/null`
+ mush=$?
+else
+ mush=1;
+fi
+
+if [ "$mush" -eq 0 ]; then
echo Mush already active or some other process is using $GAMEDIR/$CONF_FILE.
exit 0
fi
BASE=`basename $log`
mv -f $log save/$BASE.$TIMESTAMP
done
-
-
-# Copy the latest core or netmud.core to save/
-if [ -r "core" ]; then
- cp core save/
-fi
-if [ -r "netmud.core" ]; then
- cp netmud.core save/
-fi
if [ -r "data/$OUTDB$SUFFIX" ]; then
ln -f data/$INDB$SUFFIX save/$INDB$SUFFIX.old
DATEMSK="${GAMEDIR}/getdate.template"
export DATEMSK
+export GAMEDIR
+
LC_ALL=$LANG LANG=$LANG ./netmush $@ --pid-file=$PIDFILE $GAMEDIR/$CONF_FILE &