#! /bin/bash
# fireflier startup script
# (=modified version of debian apache startup script)

NAME=fireflier
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin
DAEMON=/usr/local/sbin/fireflierd
PIDFILE=/var/run/$NAME.pid
CONF=/etc/fireflier/fireflier.conf

trap "" 1
export LANG=C
export PATH

test -f $DAEMON || exit 0

if egrep -q -i "^[[:space:]]*start_server[[:space:]]*=[[:space:]]*no" $CONF
then
    exit 0
fi

case "$1" in
  start)
    echo -n "Starting fireflier server: $NAME"
    # issueing this modprobe command is not very nice here,
    # but the server depends on ip_queue.
    # -q will at least suppress errors.
    modprobe -q ip_queue
    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- -d
    ;;

  stop)
    echo -n "Stopping fireflier server: $NAME"
    start-stop-daemon --stop --pidfile $PIDFILE
    ;;

  restart)
    $0 stop
    $0 start
    ;;

  force-reload)
    $0 stop
    $0 start
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

if [ $? == 0 ]; then
	echo .
	exit 0
else
	echo failed
	exit 1
fi
