#!/bin/bash
#
# starling    This shell script takes care of starting and stopping
#                    the starling server
# chkconfig: 345 98 98
# description: The starling queue server

. /etc/rc.d/init.d/functions

PROG="/usr/bin/starling"
PIDFILE="/var/run/starling.pid"
OPTIONS="-u nobody -g nobody -L /var/log/starling.log -q /var/spool/starling -d"

start() {
  if [ -f $PIDFILE ]; then
    echo "starling already running"
  else
    echo -n "Starting starling:"
        touch $PIDFILE
        chown nobody:nobody $PIDFILE
    cd $PROGDIR
    daemon $PROG $OPTIONS
        RETVAL=$?
        echo
        return $RETVAL
  fi
}

stop() {
  if [ -f $PIDFILE ]; then
    echo -n "Stopping starling:"
        killproc $PROG
        RETVAL=$?
        echo
        return $RETVAL
  else
    echo "starling not running"
  fi
}

case "$1" in
start)
  start
;;
stop)
  stop
;;
restart)
  stop
  sleep 3
  start
;;
esac

exit $RETVAL

