#!/bin/sh
#
# Start the proftpd FTP daemon.

# For more exhaustive logging, try "-d 3" as proftpd_options.

run_proftpd=1
proftpd_options=""

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/proftpd
NAME=proftpd
FLAGS="defaults 50"

trap "" 1
trap "" 15

test -f $DAEMON || exit 0

if ! egrep -q "^[:space:]*ServerType.*standalone" /etc/proftpd.conf
then
    run_proftpd=0
fi

case "$1" in

  start)
    if [ $run_proftpd = 1 ]
    then
        update-inetd --disable ftp
	echo -n "Starting professional ftp daemon: "
	if start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
	    --exec $DAEMON -- $proftpd_options
	then
	    echo "$NAME."
	else
	    echo
	fi
    fi
    ;;

  stop)
    if [ $run_proftpd = 1 ]
    then
	echo -n "Stopping professional ftp daemon: "
	if killall $NAME > /dev/null 2>&1
	then
	    echo "$NAME."
	else
	    echo
	fi
    fi
    ;;

  reload)
    echo -n "Reloading $NAME configuration..."
    if killall -1 $NAME > /dev/null 2>&1
    then
	echo done.
    else
	echo failed.
    fi
    ;;

  restart)
    $0 force-reload
    ;;

  force-reload)
    echo -n "Restarting $NAME daemon."
    /etc/init.d/$NAME stop > /dev/null 2>&1
    echo -n "."
    sleep 2
    echo -n "."
    if start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
	--exec $DAEMON -- $proftpd_options
    then
	echo "done."
    fi
    ;;

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

esac

exit 0
