4 # This is a hacked version of "isempireup" by Dave Nye
5 # Modified for use with the Empire2 server by Ken Stevens 1995
8 # keepitup -kill <game>
9 # keepitup -start <game> <dir>
10 # keepitup -check <game> <dir> <port> <coun> <rep>
13 # You may need to put a '-' in front of the ps flags below
16 tbase=/tmp/empcheck.$$
18 trap 'rm -f $FNAMES ; exit' 0 1 2 3 15
21 if [ "$_verbose" = "true" ]; then
27 ERR1="connect: Connection refused"
28 ERR2="Expecting 2, got unix socket connect: No such file or directory"
29 MDOWN="The game is down"
34 FNAMES="$FNAMES ${FK}.L ${FK}.P"
38 egrep "emp_server $FLAGS $1" ${FK}.L | egrep "$USER" >${FK}.P
40 SZ="`wc -l ${FK}.P | awk '{print $1}' -`"
41 if [ $SZ -gt 0 ]; then
42 PIDS=`awk '{rec = rec " " $2} END {print rec}' ${FK}.P`
43 putmsg "Found pids $PIDS to kill for emp_server $FLAGS"
53 FNAMES="$FNAMES ${FK}.L ${FK}.P"
57 egrep "$PROC" ${FK}.L | egrep "$USER" >${FK}.P
59 SZ="`wc -l ${FK}.P | awk '{print $1}' -`"
60 if [ $SZ -gt 0 ]; then
61 PIDS=`awk '{rec = rec " " $2} END {print rec}' ${FK}.P`
62 putmsg "Found pids " $PIDS " to kill for" $PROC
75 ./emp_server $FLAGS $UNIQ &
76 echo "restarted $UNIQ"
86 EMPIREHOST=`/bin/hostname`
90 export EMPIREHOST EMPIREPORT COUNTRY PLAYER
93 rm -f ${FN}.I ${FN}.1 ${FN}.2
94 FNAMES="$FNAMES ${FN}.I ${FN}.1 ${FN}.2"
99 $DIR/bin/emp_client >${FN}.1 2>${FN}.2 <${FN}.I
102 NORM=`head -1 ${FN}.1`
104 if [ "$STAT" = "0" ]; then
107 elif [ "$ER" = "$ERR0" ]; then
109 # putmsg "All Ok, but bad return status"
110 elif [ "$ER" = "$ERR1" ]; then
112 putmsg "emp_server is down"
113 elif [ "$ER" = "$ERR2" ]; then
115 putmsg "emp_server is down"
118 putmsg "Something is wrong"
120 rm -f ${FN}.I ${FN}.1 ${FN}.2
123 while [ $# -gt 0 ]; do
127 if [ $# -lt 1 ]; then
128 echo "Expecting -kill <game>"
135 if [ $# -lt 2 ]; then
136 echo "Expecting -start <game> <dir>"
141 # -check game dir port country user
143 if [ $# -lt 5 ]; then
144 echo "Expecting -check <game> <dir> <port> <tcoun> <tuser>"
147 checkgame $2 $3 $4 $5
148 if [ "$ALLOK" != "true" ]; then
151 shift ; shift ; shift ; shift ; shift ;;
152 *) echo "Unknown parameter found in: $*."