Blob Blame History Raw
#!/bin/sh
#
# wesnothd     This shell script takes care of starting and stopping
#              the Wesnoth game server.
#
# chkconfig:   - 15 85
# description: The Wesnoth server supports playing networked \
#              multi-player games.
# processname: wesnothd
# config:      /etc/sysconfig/wesnothd
# pidfile:     /var/run/wesnothd.pid

### BEGIN INIT INFO
# Provides: lsb-wesnothd
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: start and stop Wesnoth server
# Description: wesnothd enables hosting online Wesnoth games
### END INIT INFO


# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

exec="/usr/sbin/wesnothd"
prog=$(basename $exec)
pidfile=/var/run/$prog.pid
socketfile=/var/run/wesnothd/socket

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    echo -n $"Starting Wesnoth game server: "
    if [ -n "`/sbin/pidof $prog`" ]; then
        echo -n $"$prog already running"
        failure
        echo
        return 1
    fi
    [ -p $socketfile ] && rm -f $socketfile
    daemon --user wesnothd $exec --daemon $WESNOTHD_OPTIONS >/dev/null 2>&1
    retval=$?
    if [ $retval -eq 0 ]; then
        success
        touch $lockfile
        pidofproc $prog > $pidfile
    else
        failure
    fi
    echo
    return $retval
}

stop() {
    echo -n $"Stopping Wesnoth game server: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

fdr_status() {
    status $prog
}

case "$1" in
    start|stop|restart|reload)
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        fdr_status
        ;;
    condrestart|try-restart)
        [ ! -f $lockfile ] || restart
    ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
        exit 2
esac