PageRenderTime 73ms CodeModel.GetById 59ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/rc4.d/S50proftpd

http://github.com/brinkman83/bashrc
Shell | 225 lines | 178 code | 26 blank | 21 comment | 39 complexity | 2ea714226195edc7e933e367fd8dfe74 MD5 | raw file
  1#!/bin/sh 
  2
  3### BEGIN INIT INFO
  4# Provides:          proftpd
  5# Required-Start:    $syslog $local_fs $network
  6# Required-Stop:     $syslog $local_fs $network
  7# Should-Start:      $remote_fs $named
  8# Should-Stop:       $remote_fs $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=""
 25
 26PIDFILE=`grep -i 'pidfile' /etc/proftpd/proftpd.conf | sed -e 's/pidfile[\t ]\+//i'`
 27if [ "x$PIDFILE" = "x" ];
 28then
 29	PIDFILE=/var/run/proftpd.pid
 30fi
 31
 32# Read config (will override defaults)
 33[ -r /etc/default/proftpd ] && . /etc/default/proftpd
 34
 35trap "" 1
 36trap "" 15
 37
 38test -f $DAEMON || exit 0
 39
 40. /lib/lsb/init-functions
 41
 42#
 43# Servertype could be inetd|standalone|none.
 44# In all cases check against inetd and xinetd support.
 45#
 46if ! egrep -qi "^[[:space:]]*ServerType.*standalone" /etc/proftpd/proftpd.conf
 47then
 48    if [ $(dpkg-divert --list xinetd|wc -l) -eq 1 ] 
 49    then
 50	if egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.conf 2>/dev/null || \
 51	   egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.d/* 2>/dev/null
 52	then
 53    		RUN="no"
 54    		INETD="yes"
 55	else
 56		if ! egrep -qi "^[[:space:]]*ServerType.*inetd" /etc/proftpd/proftpd.conf
 57		then
 58    			RUN="yes"
 59			INETD="no"
 60		else
 61			RUN="no"
 62			INETD="no"
 63		fi
 64	fi
 65    else
 66    	if egrep -qi "^ftp.*/usr/sbin/proftpd" /etc/inetd.conf 2>/dev/null
 67    	then
 68    		RUN="no"
 69    		INETD="yes"
 70    	else
 71		if ! egrep -qi "^[[:space:]]*ServerType.*inetd" /etc/proftpd/proftpd.conf
 72		then
 73    			RUN="yes"
 74			INETD="no"
 75		else
 76			RUN="no"
 77			INETD="no"
 78		fi
 79    	fi
 80    fi
 81fi
 82
 83# /var/run could be on a tmpfs
 84
 85[ ! -d /var/run/proftpd ] && mkdir /var/run/proftpd
 86
 87start()
 88{
 89    log_daemon_msg "Starting ftp server" "$NAME"
 90
 91    start-stop-daemon --start --quiet --pidfile "$PIDFILE" --oknodo --exec $DAEMON -- $OPTIONS  
 92    if [ $? != 0 ]; then
 93        log_end_msg 1
 94        exit 1
 95    else
 96        log_end_msg 0
 97    fi
 98}
 99
100signal()
101{
102
103    if [ "$1" = "stop" ]; then
104	SIGNAL="TERM"
105    	log_daemon_msg "Stopping ftp server" "$NAME"
106    else
107	if [ "$1" = "reload" ]; then
108	    SIGNAL="HUP"
109    	    log_daemon_msg "Reloading ftp server" "$NAME"
110	else
111	    echo "ERR: wrong parameter given to signal()"
112	    exit 1
113	fi
114    fi
115    if [ -f "$PIDFILE" ]; then
116    	start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
117   	 if [ $? = 0 ]; then
118        	log_end_msg 0
119    	else
120		SIGNAL="KILL"
121		start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
122    		if [ $? != 0 ]; then
123        		log_end_msg 1
124        		[ $2 != 0 ] || exit 0
125    		else
126        		log_end_msg 0
127    		fi
128    	fi
129   	if [ "$SIGNAL" = "KILL" ]; then
130		rm -f "$PIDFILE"
131    	fi
132    else
133        log_end_msg 0
134    fi
135}
136
137case "$1" in
138    start)
139	if [ "x$RUN" = "xyes" ] ; then
140	    start
141	else
142	    if [ "x$INETD" = "xyes" ] ; then
143		echo "ProFTPd is started from inetd/xinetd."
144	    else 
145	    	echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
146	    fi
147	fi
148	;;
149
150    force-start)
151	if [ "x$INETD" = "xyes" ] ; then
152	    echo "Warning: ProFTPd is started from inetd/xinetd (trying to start anyway)."
153	fi
154	start
155	;;	
156    
157    stop)
158	if [ "x$RUN" = "xyes" ] ; then
159	    signal stop 0
160	else
161	    if [ "x$INETD" = "xyes" ] ; then
162		echo "ProFTPd is started from inetd/xinetd."
163	    else 
164	    	echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
165	    fi
166	fi
167	;;
168
169    force-stop)
170	if [ "x$INETD" = "xyes" ] ; then
171	    echo "Warning: ProFTPd is started from inetd/xinetd (trying to kill anyway)."
172	fi
173	signal stop 0
174	;;
175
176    reload)
177	signal reload 0
178	;;
179
180    force-reload|restart)
181	if [ "x$RUN" = "xyes" ] ; then
182	    signal stop 1
183	    sleep 2
184	    start
185	else
186	    if [ "x$INETD" = "xyes" ] ; then
187		echo "ProFTPd is started from inetd/xinetd."
188	    else 
189	    	echo "ProFTPd warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration."
190	    fi
191	fi
192	;;
193
194    status)
195	if [ "x$INETD" = "xyes" ] ; then
196	    echo "ProFTPd is started from inetd/xinetd."
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	;;
223esac
224
225exit 0