#!/bin/sh
#
# /etc/init.d/proftpd
#
# Startup script for ProFTPd
#
# chkconfig: - 85 15
# description: ProFTPD is an enhanced FTP server with \
#               a focus toward simplicity, security, and ease of configuration. \
#              It features a very Apache-like configuration syntax, \
#               and a highly customizable server infrastructure, \
#               including support for multiple 'virtual' FTP servers, \
#               anonymous FTP, and permission-based directory visibility.
# processname: proftpd
# config: /etc/proftp.conf
#
# By: Osman Elliyasa <osman@Cable.EU.org>
# $Id: proftpd.init.d,v 1.1 1999/10/23 04:07:58 macgyver Exp $

# Source function library.
. /etc/rc.d/init.d/functions

FTPSHUT=/usr/sbin/ftpshut

RETVAL=0
LOCKFILE=/var/lock/subsys/proftpd

start()
{
	#$0 resume
	echo -n "Starting proftpd: "
	daemon proftpd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	echo
}	

stop()
{
	#$0 suspend
	echo -n "Shutting down proftpd: "
	killproc proftpd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
	echo
}

restart()
{
	stop
	start
}

reload()
{
	echo -n "Reloading proftpd: "
	killproc proftpd -HUP
	RETVAL=$?
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status proftpd
	;;
  restart)
	restart
	;;
  reload)
	reload
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
    	    stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
	    restart
	fi
	;;
  suspend)
  	if [ -f $FTPSHUT ]; then
	    if [ $# -gt 1 ]; then
		shift
		action "Suspending with '$*' " $FTPSHUT $*
	    else
		action "Suspending NOW " $FTPSHUT now \"Maintanance in progress\"
	    fi
	fi
  	;;
  resume)
	if [ -f /etc/shutmsg ]; then
	    action "Allowing sessions again " rm -f /etc/shutmsg
	fi
  	;;
  *)
	echo -n "Usage: ${0##*/} {start|stop|restart|status|reload|resume|condstop|condrestart"
  	if [ "$FTPSHUT" = "" ]; then
		echo "}"
	else
		echo "|suspend}"
		echo "suspend accepts additional arguments which are passed to ftpshut(8)"
	fi
	RETVAL=1
esac

exit $RETVAL
