wesnoth/utils/mp-server/run_server
2007-12-10 19:03:59 +00:00

55 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
if [ $# -ne 1 ]; then
echo "Syntax: $0 <server version>"
exit 1
fi
SERVER=$1
SERVERBASE=$HOME/servers/$SERVER
SOURCE=$HOME/source/trunk
case $SERVER in
1.2 ) SOURCE=$HOME/source/1.2
;;
* )
esac
[ -d "$SERVERBASE/logs" ] || mkdir $SERVERBASE/logs
[ -d "$SERVERBASE" ] || exit 1
ulimit -Ss 2048
ulimit -c unlimited
# send the standard server message to the appropriate server when killing it with ctrl+c
trap "$HOME/bin/send_server_message $SERVER; sleep 2; killall wesnothd-$SERVER; echo -n 'terminated: '; date; exit 0" SIGINT
while [ true ]
do
if ps -C wesnothd-$SERVER >/dev/null; then
sleep 10
else
DATE=$(date +"%Y%m%d-%H%M%S")
PORT=$(cat $SERVERBASE/port)
REV=$(ls -l $SERVERBASE/build | sed -e 's,.*wesnothd-\(svn-.*\)_.*/,\1,')
cd $SERVERBASE/build || exit 1
[ -x bin/wesnothd-$SERVER ] || exit 1
nice -n 3 bin/wesnothd-$SERVER -c $SERVERBASE/wesnothd.cfg --port $PORT --threads 30 > $SERVERBASE/logs/wesnothd.$DATE.$REV.log 2>&1 &
PID=$!
echo -n "started $SERVER server (revision: $REV, pid: $PID) at: "; date
cd $SERVERBASE
rm -f old.log oldlobby.log
mv current.log old.log > /dev/null 2>&1
mv currentlobby.log oldlobby.log > /dev/null 2>&1
ln -s logs/wesnothd.$DATE.$REV.log current.log
ln -s logs/lobby.$DATE.$REV.log currentlobby.log
# wait a bit so the server is likely up and listening
sleep 1
if [ "$SERVER" != "trunk" ]; then
cd $SOURCE/utils/
./mp-lobby-logger.pl -j -p $PORT -l $SERVERBASE/currentlobby.log >> $SERVERBASE/logs/lobby-chat.log 2>&1 &
fi
# wait for the server to terminate
wait $PID
cd
fi
done