#!/usr/bin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2
# $Header: /var/cvsroot/gentoo-x86/net-ftp/vsftpd/files/vsftpd.init,v 1.8 2013/04/20 16:51:02 hwoarang Exp $

VSFTPD_NAME=${SVCNAME##*.}
if [ -n "${VSFTPD_NAME}" -a "${SVCNAME}" != "vsftpd" ]; then
    VSFTPD_PID="/run/vsftpd.${VSFTPD_NAME}.pid"
    VSFTPD_CONF_DEFAULT="/etc/${VSFTPD_NAME}.conf"
else
    VSFTPD_PID="/run/vsftpd.pid"
    VSFTPD_CONF_DEFAULT="/etc/vsftpd.conf"
fi
VSFTPD_CONF=${VSFTPD_CONF:-${VSFTPD_CONF_DEFAULT}}
VSFTPD_EXEC=${VSFTPD_EXEC:-/usr/bin/vsftpd}

depend() {
	need net
	use dns logger
}

checkconfig() {
	VSFTPD_CONF="${VSFTPD_CONF}" \
		/usr/lib/vsftpd-checkconfig.sh || return 1
}

start() {
	checkconfig || return 1
	ebegin "Starting ${SVCNAME}"
	start-stop-daemon --start --exec ${VSFTPD_EXEC} \
		--background --make-pidfile --pidfile "${VSFTPD_PID}" \
		-- "${VSFTPD_CONF}"
	eend $?
}

stop() {
	ebegin "Stopping ${SVCNAME}"
	if [ -f ${VSFTPD_PID} ]; then
		start-stop-daemon --stop --pidfile ${VSFTPD_PID}
	else
		ewarn "Couldn't found ${VSFTPD_PID} trying to stop over the process name ${SVCNAME}"
		start-stop-daemon --stop --name ${SVCNAME}
	fi
	eend $?
}

# vim: ts=4
