File fb-server of Package frozen-bubble

#! /bin/sh
#
# Author: Dirk Stoecker <frozenbubble@dstoecker.de>
#
# /etc/init.d/fb-server
#
#   and its symbolic link
#
# /sbin/rcfb-server
#
# System startup script for the Frozen Bubble server
#
### BEGIN INIT INFO
# Provides: fb-server
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Description: Frozen Bubble multiple server autohandler
# Short-Description: Frozen Bubble server
### END INIT INFO

FB_SERVER_BIN=/usr/lib/frozen-bubble/fb-server
FB_USER=nobody
test -x $FB_SERVER_BIN || exit 5

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - misc error
# 2 - invalid or excess args
# 3 - unimplemented feature (e.g. reload)
# 4 - insufficient privilege
# 5 - program not installed
# 6 - program not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

CONFFILES=/etc/fb-server*.conf

case "$1" in
    start)
        for file in $CONFFILES; do
            CMD=`ps -A -o %a --no-headers |grep -e "nice -10 $FB_SERVER_BIN -c $file" | grep -v grep`
            if [ -z "$CMD" ]; then
              echo -n "Starting Frozen bubble server ($file)"
              su -l $FB_USER -s /bin/sh -c "$FB_SERVER_BIN -c $file >/dev/null"
              rc_status -v
            fi
        done
        ;;
    stop)
        for file in $CONFFILES; do
            CMD=`ps -A -o %p%a --no-headers |grep -e "$FB_SERVER_BIN -c $file" | grep -v grep`
            PID=`echo $CMD | perl -pe 's/^ *(\d+) .*$/$1/'`
            if [ "$PID" ]; then
              echo -n "Shutting down Frozen bubble server ($file)"
              kill -TERM $PID
              rc_status -v
            fi
        done
        ;;
    reload) # no reloading possible, do a restart
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        sleep 2
        $0 start
        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        sleep 2
        $0 start
        # Remember status and be quiet
        rc_status
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
        ;;
esac
rc_exit

openSUSE Build Service is sponsored by