#!/bin/sh
#
# fb-server      Frozen-Bubble server
#
# chkconfig: 2345 99 10
# description: this is the Frozen-Bubble server; it allows people to play \
#              Frozen-Bubble over the Internet.
# processname: fb-server
# pidfile: /var/run/fb-server.pid
# config: /etc/fb-server*.conf

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

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

conffiles=/etc/fb-server*.conf
servicename=fb-server

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

start() {
	gprintf "Starting Frozen-Bubble server(s): "
        ATLEASTONE=-1
        for file in $conffiles; do
            su -l fbuser -s /bin/sh -c "fb-server -c $file >/dev/null" && success || failure  
            RETVAL=$?
            if [ "$ATLEASTONE" -ne 0 ]; then
                ATLEASTONE=$RETVAL
            fi
            echo
        done
	if [ $ATLEASTONE -eq 0 ]; then
            touch /var/lock/subsys/$servicename
        fi
	return $ATLEASTONE
}

stop() {
	gprintf "Stopping Frozen-Bubble server(s): "
        killproc fb-server -TERM
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ]; then
            rm -f /var/lock/subsys/$servicename
        fi
	return $RETVAL
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  status)
        status fb-server
        RETVAL=$?
        ;;
  condrestart)
	[ -f /var/lock/subsys/$servicename ] && restart || :
	;;
  *)
	gprintf "Usage: $servicename {start|stop|restart|status|condrestart}\n"
	exit 1
esac

exit $?
