#!/bin/sh
#
# pureftpd	PureFTPD server
#
# chkconfig:	345 85 15
# description:	PureFTPD is fast, production-quality, standard-conformant FTP server
#

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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/pure-ftpd ] && . /etc/sysconfig/pure-ftpd

# Check that networking is up.
if is_no "${NETWORKING}"; then
        # nls "ERROR: Networking is down. %s can't be run." <service>
        msg_Network_Down pure-ftpd
        exit 1
fi

if [ -f /etc/ftpd/pureftpd.conf ]; then
    PUREFTPD_OPTS=$(grep -E -v "^\W*#" /etc/ftpd/pureftpd.conf | xargs)
fi

if [ -f /etc/ftpd/pureftpd-mysql.conf ]; then
    PUREFTPD_OPTS="${PUREFTPD_OPTS} -l mysql:/etc/ftpd/pureftpd-mysql.conf"
fi

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
        if [ ! -f /var/lock/subsys/pure-ftpd ]; then
		msg_starting pure-ftpd
		rm -f /var/run/pure-ftpd/client*
		daemon pure-ftpd $PUREFTPD_OPTS --daemonize
	        RETVAL=$?
    		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pure-ftpd
	else
        	msg_Already_Running pure-ftpd
	        exit 1
	fi
	;;
  stop)
        # Stop daemons.
	if [ -f /var/lock/subsys/pure-ftpd ]; then
                msg_stopping pure-ftpd
                killproc pure-ftpd
                rm -f /var/lock/subsys/pure-ftpd > /dev/null 2>&1
        else
		msg_Not_Running pure-ftpd
	        exit 1
	fi
	;;
  status)
	status pure-ftpd
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
	    pure-ftpwho
	fi
	exit $RETVAL
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  *)
	msg_Usage "$0 {start|stop|restart|status}"
	exit 1
	;;
esac

exit $RETVAL

