#!/bin/sh die() { echo >&2 "$@"; exit 1; } dietail() { echo >&2 "$@" echo >&2 "tail $LOG:" tail $LOG exit 1 } [ $# -ge 1 ] || die "Usage: $0 []" VERSION=$1 shift PARAMETERS="$@" case $VERSION in 1.9|1.12) THREADS=4 ;; *) THREADS=2 ;; esac SERVERBASE=$HOME/campaignd/$VERSION [ -d "$SERVERBASE" ] || die "Server '$VERSION' not found." [ -r "$SERVERBASE"/COPYING.txt ] || die "GPL file (COPYING.txt) is missing." [ -r "$SERVERBASE"/server.cfg ] || die "server.cfg is missing, is the server correctly configured? Aborting..." [ -d "$SERVERBASE/data" ] || mkdir "$SERVERBASE/data" [ -d "$SERVERBASE/logs" ] || mkdir "$SERVERBASE/logs" ulimit -c unlimited cd $SERVERBASE || exit 1 while [ true ] do DATE=$(date +"%Y%m%d-%H%M%S") COMMAND="$HOME/bin/campaignd-$VERSION $THREADS $PARAMETERS" LOG="$SERVERBASE/logs/campaignd.$DATE.log" mv "$SERVERBASE/current.log" "$SERVERBASE/old.log" > /dev/null 2>&1 ln -s "$LOG" "$SERVERBASE/current.log" echo "started $VERSION campaignd with command: '$COMMAND' logging to: $LOG" $COMMAND > $LOG 2>&1 EXIT_CODE="$?" echo "exit code: $EXIT_CODE" mv gmon.out gmon.$DATE.out > /dev/null 2>&1 case $EXIT_CODE in 0) exit ;; 1|2|127) dietail ;; #"File I/O error." #"Could not parse config file." #cannot open shared object file esac done