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