rendered paste body#! /bin/sh
### BEGIN INIT INFO
# Provides: battlefield
# Required-Start: networking
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Battlefield Server Daemon
# Description: Starts/Stops/Restarts the Battlefield2 Server Daemon
### END INIT INFO
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/bf2server/mono-1.1.12.1/
DESC="Battlefield Server"
NAME=bf2server
USER=bf2server
DIR=/home/bf2server/bf2
DAEMON=mono
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
ARGUMENTS="$DIR/bf2ccd.exe"
# Gracefully exit if the package has been removed.
# moot
#test -x "$DAEMON" # || exit 0
d_start() {
start-stop-daemon --start --quiet \
--chuid $USER \
--chdir $DIR \
--exec "$DAEMON $ARGUMENTS" \
> /dev/null \
|| echo -n " already running"
echo $! > $PIDFILE.my
}
d_stop() {
start-stop-daemon --stop --quiet \
--chuid $USER \
--chdir $DIR \
--exec "kill -SIGTERM $(cat $PIDFILE.my)" \
|| echo -n " not running"
kill -SIGTERM $(cat $PIDFILE.my)
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 15
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0