summaryrefslogtreecommitdiff
blob: e486e1fc08637e6cc4d4f54b2423faea3a41d159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/sbin/runscript
# Copyright 2003-2004 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.7 2008/12/26 16:50:15 armin76 Exp $

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

depend() {
	need net
	use dns logger
}

checkconfig() {
	if [ ! -e ${VSFTPD_CONF} ] ; then
		eerror "Please setup ${VSFTPD_CONF} before starting vsftpd"
		eerror "There are sample configurations in /usr/share/doc/vsftpd"
		return 1
	fi

	if egrep -iq "^ *background *= *yes" "${VSFTPD_CONF}" ; then
		eerror "${VSFTPD_CONF} must not set background=YES"
		return 1
	fi

	local has_ip=false has_ipv6=false ip_error=true
	egrep -iq "^ *listen *= *yes" "${VSFTPD_CONF}" && has_ip=true
	egrep -iq "^ *listen_ipv6 *= *yes" "${VSFTPD_CONF}" && has_ipv6=true
	if ${has_ip} && ! ${has_ipv6} ; then
		ip_error=false
	elif ! ${has_ip} && ${has_ipv6} ; then
		ip_error=false
	fi
	if ${ip_error} ; then
		eerror "${VSFTPD_CONF} must contain listen=YES or listen_ipv6=YES"
		eerror "but not both"
		return 1
	fi
}

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