#!/bin/sh
#
# /etc/init.d/wu-ftpd  --  start/stop the wu-ftpd FTP daemon.

PATH=/bin:/usr/bin:/sbin:/usr/sbin

trap "" 1 15
test -x /usr/sbin/wu-ftpd || exit 0

# don't remove -S or -s, they're essential for the daemon mode
wu_options="-S -l"

run_wu="1"
# check that the FTP service isn't already enabled in inetd
if egrep -q "^ftp[:space:]*" /etc/inetd.conf ; then
    run_wu=0
fi

case "$1" in
  start)
    if [ "$run_wu" = "1" ]; then
	echo -n "Starting FTP server: wu-ftpd"
	start-stop-daemon --start --quiet --pidfile /var/run/wu-ftpd.pid \
	    --exec /usr/sbin/wu-ftpd -- $wu_options && echo "."
    fi
    ;;
  stop)
    if [ "$run_wu" = "1" ]; then
	echo -n "Stopping FTP server: wu-ftpd"
	kill -3 `cat /var/run/wu-ftpd.pid` >/dev/null 2>&1 && echo "."
    fi
    ;;
  restart|force-reload)
    if [ "$run_wu" = "1" ]; then
	echo -n "Restarting FTP server: wu-ftpd"
	$0 stop >/dev/null && echo -n "."
	sleep 2 && echo -n "."
	$0 start >/dev/null && echo ".done."
    fi
    ;;
  *)
    echo "Usage: /etc/init.d/wu-ftpd {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
