blob: 01c998c92403ddb487567ff743d211b6b1fa8f5a [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: proftpd
5# Required-Start: $remote_fs $syslog $local_fs $network
6# Required-Stop: $remote_fs $syslog $local_fs $network
7# Should-Start: $named
8# Should-Stop: $named
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: Starts ProFTPD daemon
12# Description: This script runs the FTP service offered
13# by the ProFTPD daemon
14### END INIT INFO
15
16# Start the proftpd FTP daemon.
17
18PATH=/bin:/usr/bin:/sbin:/usr/sbin
19DAEMON=/usr/sbin/proftpd
20NAME=proftpd
21
22# Defaults
23RUN="no"
24OPTIONS=""
25CONFIG_FILE=/etc/proftpd.conf
26
27PIDFILE=`grep -i '^pidfile' $CONFIG_FILE|awk '{ print $2 }'`
28if [ "x$PIDFILE" = "x" ];
29then
30 PIDFILE=/var/run/proftpd.pid
31fi
32
33# Read config (will override defaults)
34[ -r /etc/default/proftpd ] && . /etc/default/proftpd
35
36trap "" 1
37trap "" 15
38
39test -f $DAEMON || exit 0
40
41. /etc/init.d/functions
42
43#
44# Servertype could be inetd|standalone|none.
45# In all cases check against inetd and xinetd support.
46#
47if ! egrep -qi "^[[:space:]]*ServerType.*standalone" $CONFIG_FILE
48then
49 if egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.conf 2>/dev/null || \
50 egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.d/* 2>/dev/null || \
51 egrep -qi "^ftp.*/usr/sbin/proftpd" /etc/inetd.conf 2>/dev/null
52 then
53 RUN="no"
54 INETD="yes"
55 else
56 if ! egrep -qi "^[[:space:]]*ServerType.*inetd" $CONFIG_FILE
57 then
58 RUN="yes"
59 INETD="no"
60 else
61 RUN="no"
62 INETD="no"
63 fi
64 fi
65fi
66
67# /var/run could be on a tmpfs
68
69[ ! -d /var/run/proftpd ] && mkdir /var/run/proftpd
70
71inetd_check()
72{
73 if [ ! -x /usr/sbin/inetd -a ! -x /usr/sbin/xinetd ]; then
74 echo "Neither inetd nor xinetd appears installed: check your configuration."
75 fi
76}
77
78start()
79{
80 set -e
81 echo -n "Starting ftp server $NAME... "
82 start-stop-daemon --start --quiet --pidfile "$PIDFILE" --oknodo --exec $DAEMON -- -c $CONFIG_FILE $OPTIONS
83 echo "done."
84}
85
86signal()
87{
88
89 if [ "$1" = "stop" ]; then
90 SIGNAL="TERM"
91 echo -n "Stopping ftp server $NAME... "
92 else
93 if [ "$1" = "reload" ]; then
94 SIGNAL="HUP"
95 echo -n "Reloading ftp server $NAME... "
96 else
97 echo "ERR: wrong parameter given to signal()"
98 exit 1
99 fi
100 fi
101 if [ -f "$PIDFILE" ]; then
102 start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
103 if [ $? = 0 ]; then
104 echo "done."
105 return
106 else
107 SIGNAL="KILL"
108 start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
109 if [ $? != 0 ]; then
110 echo
111 [ $2 != 0 ] || exit 0
112 else
113 echo "done."
114 return
115 fi
116 fi
117 if [ "$SIGNAL" = "KILL" ]; then
118 rm -f "$PIDFILE"
119 fi
120 else
121 echo "done."
122 return
123 fi
124}
125
126case "$1" in
127 start)
128 if [ "x$RUN" = "xyes" ] ; then
129 start
130 else
131 if [ "x$INETD" = "xyes" ] ; then
132 echo "ProFTPD is started from inetd/xinetd."
133 inetd_check
134 else
135 echo "ProFTPD warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
136 fi
137 fi
138 ;;
139
140 force-start)
141 if [ "x$INETD" = "xyes" ] ; then
142 echo "Warning: ProFTPD is started from inetd/xinetd (trying to start anyway)."
143 inetd_check
144 fi
145 start
146 ;;
147
148 stop)
149 if [ "x$RUN" = "xyes" ] ; then
150 signal stop 0
151 else
152 if [ "x$INETD" = "xyes" ] ; then
153 echo "ProFTPD is started from inetd/xinetd."
154 inetd_check
155 else
156 echo "ProFTPD warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
157 fi
158 fi
159 ;;
160
161 force-stop)
162 if [ "x$INETD" = "xyes" ] ; then
163 echo "Warning: ProFTPD is started from inetd/xinetd (trying to kill anyway)."
164 inetd_check
165 fi
166 signal stop 0
167 ;;
168
169 reload)
170 signal reload 0
171 ;;
172
173 force-reload|restart)
174 if [ "x$RUN" = "xyes" ] ; then
175 signal stop 1
176 sleep 2
177 start
178 else
179 if [ "x$INETD" = "xyes" ] ; then
180 echo "ProFTPD is started from inetd/xinetd."
181 inetd_check
182 else
183 echo "ProFTPD warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
184 fi
185 fi
186 ;;
187
188 status)
189 if [ "x$INETD" = "xyes" ] ; then
190 echo "ProFTPD is started from inetd/xinetd."
191 inetd_check
192 exit 0
193 else
194 if [ -f "$PIDFILE" ]; then
195 pid=$(cat $PIDFILE)
196 else
197 pid="x"
198 fi
199 if [ `pidof proftpd|grep "$pid"|wc -l` -ne 0 ] ; then
200 echo "ProFTPD is started in standalone mode, currently running."
201 exit 0
202 else
203 echo "ProFTPD is started in standalone mode, currently not running."
204 exit 3
205 fi
206 fi
207 ;;
208
209 check-config)
210 $DAEMON -t >/dev/null && echo "ProFTPD configuration OK" && exit 0
211 exit 1
212 ;;
213
214 *)
215 echo "Usage: /etc/init.d/$NAME {start|status|force-start|stop|force-stop|reload|restart|force-reload|check-config}"
216 exit 1
217 ;;
218esac
219
220exit 0