mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-23 21:19:32 +00:00
Fix parameter handling and quoting
Add timestamps to some log messages and custom settings for newer server versions.
This commit is contained in:
parent
845f5e5ef3
commit
5b3e121798
@ -1,12 +1,12 @@
|
||||
#!/bin/sh
|
||||
die() { echo >&2 "$@"; exit 1; }
|
||||
die() { printf '%s\n' "$*" >&2; exit 1; }
|
||||
dietail() {
|
||||
echo >&2 "$@"
|
||||
echo >&2 "tail $LOG:"
|
||||
printf '%s\n' "$*" >&2
|
||||
printf 'tail %s:\n' "$LOG" >&2
|
||||
tail "$SERVERBASE/logs/$LOG"
|
||||
exit 1
|
||||
}
|
||||
[ $# -ge 1 ] || die "Syntax: $(basename $0) <server version> [--test] [<additional parameters for wesnothd>]"
|
||||
[ $# -ge 1 ] || die "Syntax: $(basename "$0") <server version> [--test] [<additional parameters for wesnothd>]"
|
||||
set -o nounset
|
||||
set -o noclobber
|
||||
|
||||
@ -19,15 +19,13 @@ SERVERBASE="$HOME/servers/$SERVER"
|
||||
shift
|
||||
if [ $# -ge 1 ] && [ "$1" = "--test" ]; then
|
||||
shift
|
||||
PARAMETERS="$@"
|
||||
cd "$SERVERBASE"/build || exit 1
|
||||
bin/wesnothd-$SERVER -c "$SERVERBASE"/wesnothd.cfg --port 15001 $PARAMETERS
|
||||
bin/wesnothd-$SERVER -c "$SERVERBASE"/wesnothd.cfg --port 15001 "$@"
|
||||
# remove the socket so it looks like we never ran the server
|
||||
rm var/run/socket
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PARAMETERS="$@"
|
||||
THREADS=4
|
||||
PORT=15000
|
||||
case $SERVER in
|
||||
@ -41,11 +39,17 @@ case $SERVER in
|
||||
1.7*) PORT=14997
|
||||
THREADS=16 ;;
|
||||
1.9*|1.10*)
|
||||
PORT=14997
|
||||
THREADS=30 ;;
|
||||
PORT=14996
|
||||
THREADS=8 ;;
|
||||
1.12*)
|
||||
# TODO: increase after 1.12.0 is announced
|
||||
THREADS=16 ;;
|
||||
THREADS=30 ;;
|
||||
1.14*)
|
||||
set -- --keepalive ;;
|
||||
1.16*)
|
||||
set -- --keepalive ;;
|
||||
1.13*|trunk)
|
||||
# TODO: loonycyborg wants to test this with asio builds
|
||||
set -- --keepalive ;;
|
||||
esac
|
||||
|
||||
ulimit -Ss 2048
|
||||
@ -53,22 +57,22 @@ 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; echo -n 'terminated: '; date; exit 0" INT
|
||||
trap "echo -n 'terminated: '; date; exit 0" INT
|
||||
trap 'printf "terminated: "; date; exit' INT
|
||||
|
||||
while [ true ]
|
||||
while true
|
||||
do
|
||||
cd "$SERVERBASE"/build || exit 1
|
||||
[ -x bin/wesnothd-$SERVER ] || die "Executable 'bin/wesnothd-$SERVER' not found."
|
||||
|
||||
DATE=$(date +"%Y%m%d-%H%M%S")
|
||||
[ -r "$SERVERBASE"/redirect.cfg ] && PORT=$(sed -nre '/port=/s/[ \t]*port="?([0-9]+)"?/\1/p' "$SERVERBASE"/redirect.cfg)
|
||||
[ -r "$SERVERBASE"/redirect.cfg ] && PORT=$(sed -nE '/port=/s/[[:blank:]]*port="?([0-9]+)"?/\1/p' "$SERVERBASE"/redirect.cfg)
|
||||
BUILDDIR=$(readlink "$SERVERBASE"/build)
|
||||
#REV=r$(echo $BUILDDIR | sed -nre "s,.*wesnothd-svn-([0-9:SM]+)_$SERVER$,\1,p")
|
||||
REV=$(echo $BUILDDIR | sed -nre "s,.*wesnothd-$SERVER-git-(.*)$,\1,p")
|
||||
REV=${BUILDDIR#*wesnothd-*-git-}
|
||||
LOG="wesnothd.$DATE.$REV.log"
|
||||
bin/wesnothd-$SERVER -c "$SERVERBASE"/wesnothd.cfg --port $PORT --threads $THREADS $PARAMETERS > "$SERVERBASE/logs/$LOG" 2>&1 &
|
||||
bin/wesnothd-$SERVER -c "$SERVERBASE"/wesnothd.cfg --port "$PORT" --threads "$THREADS" "$@" > "$SERVERBASE/logs/$LOG" 2>&1 &
|
||||
PID=$!
|
||||
echo "started $SERVER server with command: 'wesnothd-$SERVER -c \"$SERVERBASE\"/wesnothd.cfg --port $PORT --threads $THREADS $PARAMETERS' (commit: $REV, pid: $PID) logging to: $LOG"
|
||||
echo "started $SERVER server with command: 'wesnothd-$SERVER -c \"$SERVERBASE\"/wesnothd.cfg --port $PORT --threads $THREADS $*' (commit: $REV, pid: $PID) logging to: $LOG"
|
||||
# wait a bit in case the process dies immediately
|
||||
sleep 5
|
||||
if ps -p $PID > /dev/null 2>&1
|
||||
@ -84,7 +88,7 @@ do
|
||||
# wait for the server to terminate
|
||||
wait $PID
|
||||
EXIT_CODE=$?
|
||||
echo "wesnothd exited with code: $EXIT_CODE"
|
||||
printf '%s wesnothd exited with code: %s\n' "$(date +'%Y%m%d %T')" "$EXIT_CODE"
|
||||
# need to use the recorded path since the build/ symlink might have changed
|
||||
mv "$SERVERBASE/$BUILDDIR/gmon.out" "$SERVERBASE/$BUILDDIR/gmon.$DATE.$REV.out" > /dev/null 2>&1
|
||||
# check for return code if not zero or 98 (port in use) the server should be restarted
|
||||
@ -93,6 +97,7 @@ do
|
||||
98|127|128) dietail ;; #Could not bind to port #Command not found #Invalid argument to exit
|
||||
esac
|
||||
|
||||
printf '%s tail %s:\n' "$(date +'%Y%m%d %T')" "$LOG"
|
||||
tail "$SERVERBASE/logs/$LOG"
|
||||
echo
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user