PennMUSH Community

root/1.8.3/trunk/game/restart

Revision 1032, 4.4 kB (checked in by shawnw, 1 year ago)

Merged 1.8.3p4 into trunk

  • Property svn:executable set to *
Line 
1 #!/bin/sh
2 #
3 # usage: restart
4 #
5 # REQUIRED: You must set this to the path to your game directory.
6 # E.g.: /home/mush/game
7 GAMEDIR=
8
9 # OPTIONAL things that you may want to tweak.
10
11 # Name of file to write the game's process id to. Used by restart to
12 # check for an already running game.
13 PIDFILE=netmush.pid
14
15 # Uncomment the line below to attempt to allow crashes to produce
16 # core dumps. If you're getting crashes, this is the best way
17 # to debug them.
18 #ulimit -c unlimited
19
20 # Internationalization stuff
21 # Set LANG here to get international character sets and, if someone's
22 # done it, translation of messages.
23 # Vaild locales are usually <lang_code>_<COUNTRY CODE>
24 # Example (uncomment to use):
25 #LANG=fr_FR
26
27 # Time zone stuff
28 # If you want your MUSH to run in a different timezone than the one
29 # you're in, you need to identify the target time zone file in
30 # /usr/share/zoneinfo or /usr/lib/zoneinfo. Then uncomment the next
31 # two lines and set TZ to the desired timezone file, as shown, with
32 # an initial colon:
33 #TZ=:EST5EDT
34 #export TZ
35
36
37 # The config file. Best to keep this as is. If you must change
38 # the name, make it a link to mush.cnf.
39 CONF_FILE=mush.cnf
40
41 #######################################################################
42
43 if [ -z "$GAMEDIR" ]; then
44   echo "You must set GAMEDIR in the restart script."
45   exit 1
46 fi
47
48 if [ ! -d "$GAMEDIR" ]; then
49   echo "GAMEDIR doesn't appear to be a directory. It's: $GAMEDIR"
50   exit 1
51 fi
52
53 cd $GAMEDIR
54 echo Running from `pwd`
55
56 if [ ! -f "$CONF_FILE" ]; then
57   echo "CONF_FILE doesn't exist. It's: $CONF_FILE"
58   echo "Create $CONF_FILE from $GAMEDIR/mushcnf.dst and run 'make update'"
59   exit 1
60 fi
61
62 # If netmush isn't here, they probably didn't make install
63 # In any case, we'd better not proceed.
64 if [ ! -e netmush ]; then
65   echo "I don't see $GAMEDIR/netmush. Did you remember to make install?"
66   exit 1
67 fi
68
69 #
70 # Read the cnf file and set some variables.
71 #
72 INDB=`egrep "^input_database" $CONF_FILE | sed "s/.*[   ][  ]*.*\/\(.*\)/\1/" | sed 's/\r$//'`
73 OUTDB=`egrep "^output_database" $CONF_FILE | sed "s/.*[     ][  ]*.*\/\(.*\)/\1/" | sed 's/\r$//'`
74 PANICDB=`egrep "^crash_database" $CONF_FILE | sed "s/.*[    ][  ]*.*\/\(.*\)/\1/" | sed 's/\r$//'`
75 PANICDIR=`egrep "^crash_database" $CONF_FILE | sed "s/.*[   ][  ]*\(.*\)\/.*/\1/" | sed 's/\r$//'`
76 COMPRESSOR="cat"
77 SUFFIX=""
78
79 # Find out what the compression program is, if any
80 egrep -s "^compress_program[ ]*[A-Za-z0-9]" $CONF_FILE
81 nocompress=$?
82 if [ "$nocompress" -eq 0 ]; then
83     COMPRESSOR=`egrep "^compress_program" $CONF_FILE | sed "s/[^    ]*[     ]*\(.*\)/\1/" | sed 's/\r$//'`
84     SUFFIX=`egrep "^compress_suffix" $CONF_FILE | sed "s/[^     ]*[     ]*\(.*\)/\1/" | sed 's/\r$//'`
85 fi
86
87
88 #-- start up everything
89
90 # Prevent double-starting things. You may need to provide a pathname for
91 #  some of the commands. System V flavors need "ps -f" instead of "ps uwx".
92
93 # Old style, look for a program using the config file.
94 #mush=`ps uwwx | grep " $GAMEDIR/$CONF_FILE" | grep -v grep | wc -l`
95 # if [ "$mush" -gt 0 ]; then
96
97 # New style, look for a pid file.
98 if [ -f $PIDFILE ]; then
99     foo=`kill -0 \`cat $PIDFILE\` 2>/dev/null`
100     mush=$?
101 else
102     mush=1;
103 fi
104
105 if [ "$mush" -eq 0 ]; then
106   echo Mush already active or some other process is using $GAMEDIR/$CONF_FILE.
107   exit 0
108 fi
109
110 echo Building text file indexes.
111 (cd txt; make)
112
113 echo Restarting Mush.
114
115 if [ -r "$PANICDIR/$PANICDB" ]; then
116    end="`tail -1 $PANICDIR/$PANICDB`"
117    if [ "$end" = "***END OF DUMP***" ]; then
118       echo "Recovering PANIC dump."
119       cat $PANICDIR/$PANICDB | $COMPRESSOR > data/$OUTDB$SUFFIX
120       rm $PANICDIR/$PANICDB
121       echo "PANIC dump successfully recovered."
122    else
123       mv $PANICDIR/$PANICDB save/$PANICDB.corrupt
124       echo "Warning: PANIC dump corrupt. Using older db."
125    fi
126 fi
127
128 # Copy the last set of log files to save/
129 mv -f log/*.log save/
130
131 if [ -r "data/$OUTDB$SUFFIX" ]; then
132    rm -f save/$INDB$SUFFIX.old
133    mv -f data/$INDB$SUFFIX save/$INDB$SUFFIX.old
134    mv data/$OUTDB$SUFFIX data/$INDB$SUFFIX
135 else
136    echo "No $OUTDB$SUFFIX found."
137    if [ -r "data/$INDB$SUFFIX" ]; then
138       echo "Using $INDB$SUFFIX."
139    else
140       echo "No $INDB$SUFFIX found."
141       if [ -r "save/$INDB$SUFFIX.old" ]; then
142      echo "Using save/$INDB$SUFFIX.old."
143      cp save/$INDB$SUFFIX.old data/$INDB$SUFFIX
144       else
145     echo "No database found. Mush will start with a minimal world."
146      fi
147    fi
148 fi
149
150 if [ -r reboot.db ]; then
151   rm -f reboot.db
152 fi
153
154 DATEMSK="${GAMEDIR}/getdate.template"
155 export DATEMSK
156
157 LC_ALL=$LANG LANG=$LANG ./netmush $@ $GAMEDIR/$CONF_FILE &
Note: See TracBrowser for help on using the browser.