#!/bin/sh

PATH=/bin:/usr/bin:/sbin:/usr/sbin
PIDFILE=/var/run/ftn/binkd.pid
DAEMON=/usr/sbin/binkd
OPTS="/etc/binkd/binkd.cfg -q"

test -f $DAEMON || exit 0

# don't start binkd if it is started by inetd
grep -q ^binkd /etc/inetd.conf && exit 0

case "$1" in
  start)
    echo -n "Starting FTN mailer: binkd"
    su ftn -c "start-stop-daemon --start --quiet --pidfile $PIDFILE \
	--exec $DAEMON -- $OPTS &"
    echo "."
    ;;
  stop)
    echo -n "Stopping FTN mailer: binkd"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON &
    echo "."
    ;;
  reload)
    echo -n "Reloading FTN mailer: binkd"
    su ftn -c start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE \
	--exec $DAEMON &
    echo "."
    ;;
  restart|force-reload)
    sh $0 stop
    sh $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/binkd {start|stop|restart|reload|force-reload}"
    exit 1
    ;;
esac

exit 0
