File: proftpd.init

package info (click to toggle)
proftpd-dfsg 1.3.0-19etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 9,604 kB
  • ctags: 5,598
  • sloc: ansic: 59,475; sh: 18,832; perl: 1,474; makefile: 1,191
file content (203 lines) | stat: -rw-r--r-- 4,232 bytes parent folder | download | duplicates (2)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/sh 

# Start the proftpd FTP daemon.

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/proftpd
NAME=proftpd

# Defaults
RUN="no"
OPTIONS=""

PIDFILE=`grep -i 'pidfile' /etc/proftpd/proftpd.conf | sed -e 's/pidfile[\t ]\+//i'`
if [ "x$PIDFILE" = "x" ];
then
	PIDFILE=/var/run/proftpd.pid
fi

# Read config (will override defaults)
[ -r /etc/default/proftpd ] && . /etc/default/proftpd

trap "" 1
trap "" 15

test -f $DAEMON || exit 0

#
# These compatibility funcs are here just for sarge backports.
# They will be removed post-etch.
#
log_daemon_msg() {
    echo -n "$1: $2"
}

log_end_msg() {
    if [ $1 -ne 0 ]; then
       echo " failed!"
    else
       echo "."
    fi
}

[ -f /lib/lsb/init-functions ] && . /lib/lsb/init-functions

#
# Servertype could be inetd|standalone|none.
# In all cases check against inetd and xinetd support.
#
if ! egrep -qi "^[[:space:]]*ServerType.*standalone" /etc/proftpd/proftpd.conf
then
    if [ $(dpkg-divert --list xinetd|wc -l) -eq 1 ] 
    then
	if egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.conf 2>/dev/null || \
	   egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.d/* 2>/dev/null
	then
    		RUN="no"
    		INETD="yes"
	else
		if ! egrep -qi "^[[:space:]]*ServerType.*inetd" /etc/proftpd/proftpd.conf
		then
    			RUN="yes"
			INETD="no"
		else
			RUN="no"
			INETD="no"
		fi
	fi
    else
    	if egrep -qi "^ftp.*/usr/sbin/proftpd" /etc/inetd.conf 2>/dev/null
    	then
    		RUN="no"
    		INETD="yes"
    	else
		if ! egrep -qi "^[[:space:]]*ServerType.*inetd" /etc/proftpd/proftpd.conf
		then
    			RUN="yes"
			INETD="no"
		else
			RUN="no"
			INETD="no"
		fi
    	fi
    fi
fi

# /var/run could be on a tmpfs

[ ! -d /var/run/proftpd ] && mkdir /var/run/proftpd

start()
{
    log_daemon_msg "Starting ftp server" "$NAME"

    start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec $DAEMON -- $OPTIONS  
    if [ $? != 0 ]; then
        log_end_msg 1
        exit 1
    else
        log_end_msg 0
    fi
}

signal()
{

    if [ "$1" = "stop" ]; then
	SIGNAL="TERM"
    	log_daemon_msg "Stopping ftp server" "$NAME"
    else
	if [ "$1" = "reload" ]; then
	    SIGNAL="HUP"
    	    log_daemon_msg "Reloading ftp server" "$NAME"
	else
	    echo "ERR: wrong parameter given to signal()"
	    exit 1
	fi
    fi
    if [ -f "$PIDFILE" ]; then
    	start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
   	 if [ $? = 0 ]; then
        	log_end_msg 0
    	else
		SIGNAL="KILL"
		start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
    		if [ $? != 0 ]; then
        		log_end_msg 1
        		[ $2 != 0 ] || exit 0
    		else
        		log_end_msg 0
    		fi
    	fi
   	if [ "$SIGNAL" = "KILL" ]; then
		rm -f "$PIDFILE"
    	fi
    else
        log_end_msg 0
    fi
}

case "$1" in
    start)
	if [ "x$RUN" = "xyes" ] ; then
	    start
	else
	    if [ "x$INETD" = "xyes" ] ; then
		echo "ProFTPd is started from inetd/xinetd."
	    else 
	    	echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
	    fi
	fi
	;;

    force-start)
	if [ "x$INETD" = "xyes" ] ; then
	    echo "Warning: ProFTPd is started from inetd/xinetd (trying to start anyway)."
	fi
	start
	;;	
    
    stop)
	if [ "x$RUN" = "xyes" ] ; then
	    signal stop 0
	else
	    if [ "x$INETD" = "xyes" ] ; then
		echo "ProFTPd is started from inetd/xinetd."
	    else 
	    	echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
	    fi
	fi
	;;

    force-stop)
	if [ "x$INETD" = "xyes" ] ; then
	    echo "Warning: ProFTPd is started from inetd/xinetd (trying to kill anyway)."
	fi
	signal stop 0
	;;

    reload)
	signal reload 0
	;;

    force-reload|restart)
	if [ "x$RUN" = "xyes" ] ; then
	    signal stop 1
	    sleep 2
	    start
	else
	    if [ "x$INETD" = "xyes" ] ; then
		echo "ProFTPd is started from inetd."
	    else 
	    	echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
	    fi
	fi
	;;

    *)
	echo "Usage: /etc/init.d/$NAME {start|force-start|stop|force-stop|reload|restart|force-reload}"
	exit 1
	;;
esac

exit 0