#! /bin/sh
#
# Author: oyaji <oyaji@acorn.zive.net>
#
# /etc/init.d/proftpd
#
### BEGIN INIT INFO
# Provides:                    proftpd
# Required-Start:              $network $named $syslog
# Required-Stop:               $network $named $syslog
# X-UnitedLinux-Should-Start:
# X-UnitedLinux-Should-Stop:
# Default-Start:               3 5
# Default-Stop:                0 1 2 6
# Description:                 Start ProFTPD 
### END INIT INFO                        

# Return values acc. to LSB for all commands but 
# status (see below):
#
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running

PROFTPD_BIN="/usr/sbin/proftpd"
PROFTPD_CFG="/etc/proftpd.conf"
PROFTPD_PID="/var/run/proftpd.pid"

[ -r $PROFTPD_CFG ] || exit 6
[ -x $PROFTPD_BIN ] || exit 5

if [ -f /etc/sysconfig/proftpd ]; then
      . /etc/sysconfig/proftpd
fi

# Source status functions
. /etc/rc.status
  
# First reset status of this service
rc_reset        

# See how we were called.
case "$1" in
        start)
                echo -n "Starting ProFTPD Server: "
                startproc $PROFTPD_BIN $OPTIONS
                 touch /var/lock/subsys/proftpd
                rc_status -v
                ;;
        stop)
                echo -n "Shutting down ProFTPD Server: "
                killproc $PROFTPD_BIN
                rm -f /var/lock/subsys/proftpd
                rc_status -v
                ;;
        status)
                # Status has a slightly different for the status command:
                # 0 - service running
                # 1 - service dead, but /var/run/  pid  file exists
                # 2 - service dead, but /var/lock/ lock file exists
                # 3 - service not running
                echo -n "Checking for ProFTPD Server: "
                checkproc -p $PROFTPD_PID $PROFTPD_BIN
                rc_status -v
                ;;
        restart)
                $0 stop
                $0 start
                rc_status
                ;;
        reread)
                echo -n "Re-reading ProFTPD Server config: "
                killproc $PROFTPD_BIN -HUP
                rc_status -v
                ;;
        suspend)
                hash ftpshut >/dev/null 2>&1
                if [ $? = 0 ]; then
                        if [ $# -gt 1 ]; then
                                shift
                                echo -n "Suspending with '$*' "
                                ftpshut $*
                        else
                                echo -n "Suspending NOW "
                                ftpshut now "Maintanance in progress"
                        fi
                else
                        echo -n "No way to suspend "
                fi
                echo
                ;;
        resume)
                if [ -f /etc/shutmsg ]; then
                        echo -n "Allowing sessions again "
                        rm -f /etc/shutmsg
                else
                        echo -n "Was not suspended "
                fi
                echo
                ;;
        *)
                echo -n "Usage: $0 {start|stop|restart|status|reread|resume"
                hash ftpshut
                if [ $? = 1 ]; then
                        echo '}'
                else
                        echo '|suspend}'
                        echo 'suspend accepts additional arguments which are passed to ftpshut(8)'
                fi
                exit 1
esac
rc_exit

if [ $# -gt 1 ]; then
        shift
        $0 $*
fi

exit 0