3 # This is free software; you may redistribute it and/or modify
4 # it under the terms of the GNU General Public License as
5 # published by the Free Software Foundation; either version 2,
6 # or (at your option) any later version.
8 # This is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License with
14 # the Debian operating system, in /usr/share/common-licenses/GPL; if
15 # not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
20 # Required-Start: $network $local_fs $remote_fs
21 # Required-Stop: $remote_fs
24 # Default-Start: 2 3 4 5
26 # Short-Description: NFQueue DHCP/RA server
29 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
31 DAEMON=/usr/sbin/nfdhcpd
33 DESC="NFQUEUE-based DHCP/RA server"
34 LOGDIR=/var/log/nfdhcpd
36 PIDFILE=/var/run/$NAME/$NAME.pid
38 test -x $DAEMON || exit 0
40 . /lib/lsb/init-functions
42 # Default options, these can be overriden by the information
43 # at /etc/default/$NAME
44 DAEMON_OPTS="" # Additional options given to the server
46 DIETIME=2 # Time to wait for the server to die, in seconds
47 # If this value is set too low you might not
48 # let some servers to die gracefully and
49 # 'restart' will not work
51 STARTTIME=1 # Time to wait for the server to start, in seconds
52 # If this value is set each time the server is
53 # started (on start or restart) the script will
54 # stall to try to determine if it is running
55 # If it is not set and the server takes time
56 # to setup a pid file the log message might
57 # be a false positive (says it did not start
58 # when it actually did)
60 LOGFILE=$LOGDIR/$NAME.log # Server logfile
61 #DAEMON_USER=nfdhcp # Users to run the daemons as. If this value
62 # is set start-stop-daemon will chuid the server
64 # Include defaults if available
65 if [ -f /etc/default/$NAME ] ; then
69 # Use this if you want the user to explicitly set 'RUN' in
71 if [ "x$RUN" != "xyes" ] ; then
72 log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
73 log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it."
77 # Check that the user exists (if we set a user)
78 # Does the user exist?
82 # Check if a given process pid's cmdline matches a given name
85 [ -z "$pid" ] && return 1
86 [ ! -d /proc/$pid ] && return 1
87 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
88 # Is this the expected server
89 [ "$cmd" != "$name" ] && return 1
94 # Check if the process is running looking at /proc
95 # (works for all users)
96 # No pidfile, probably no daemon present
97 [ ! -f "$PIDFILE" ] && return 1
99 running_pid $pid $DAEMON || return 1
104 # /var/run may be volatile, so we need to ensure that
105 # /var/run/$NAME exists here as well as in postinst
106 if [ ! -d /var/run/$NAME ]; then
107 mkdir /var/run/$NAME || return 1
108 chown nobody:nogroup /var/run/$NAME || return 1
110 start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE \
111 --exec $DAEMON -- $DAEMON_OPTS
117 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
123 [ ! -f "$PIDFILE" ] && return 1
124 pid=pidofproc $PIDFILE # This is the daemon's pid
131 # Force the process to die killing it manually
132 [ ! -e "$PIDFILE" ] && return
141 echo "Cannot kill $NAME (pid=$pid)!"
151 log_daemon_msg "Starting $DESC " "$NAME"
152 # Check if it's running first
154 log_progress_msg "apparently already running"
158 if start_server ; then
159 # NOTE: Some servers might die some time after they start,
160 # this code will detect this issue if STARTTIME is set
161 # to a reasonable value
162 [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
164 # It's ok, the server started and is running
167 # It is not running after we did start
171 # Either we could not start it
176 log_daemon_msg "Stopping $DESC" "$NAME"
178 # Only stop the server if we see it running
180 stop_server || errcode=$?
183 # If it's not running don't do anything
184 log_progress_msg "apparently not running"
190 # First try to stop gracefully the program
193 # If it's still running try to kill it more forcefully
194 log_daemon_msg "Stopping (force) $DESC" "$NAME"
196 force_stop || errcode=$?
200 restart|force-reload)
201 log_daemon_msg "Restarting $DESC" "$NAME"
203 stop_server || errcode=$?
204 # Wait some sensible amount, some server need this
205 [ -n "$DIETIME" ] && sleep $DIETIME
206 start_server || errcode=$?
207 [ -n "$STARTTIME" ] && sleep $STARTTIME
208 running || errcode=$?
213 log_daemon_msg "Checking status of $DESC" "$NAME"
215 log_progress_msg "running"
218 log_progress_msg "apparently not running"
224 log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
225 log_warning_msg "cannot re-read the config file (use restart)."
229 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2