3 # Provides: fwknop-c-server
4 # Required-Start: $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
8 # Short-Description: FireWall KNock OPerator (fwknop)
11 # Author: Franck Joncourt <franck@debian.org>
13 PATH=/sbin:/usr/sbin:/bin:/usr/bin
14 DESC="FireWall KNock OPerator"
16 DAEMON=/usr/sbin/$NAME
17 PIDDIR=/var/run/fwknop
18 SCRIPTNAME=/etc/init.d/fwknop-c-server
20 # Exit if the package is not installed
21 [ -x "$DAEMON" ] || exit 0
23 # Load the VERBOSE setting and other rcS variables
26 # Define LSB log_* functions.
27 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
28 . /lib/lsb/init-functions
31 # Function that checks if all of the configuration files exist
34 # 0 : all of the configuration files exist
35 # 6 : at least one file is missing
44 file_list="/etc/fwknop/access.conf /etc/fwknop/fwknopd.conf"
46 for ConfFile in $file_list; do
47 if [ ! -f "$ConfFile" ]; then
57 # Function that starts the daemon/service
60 # 0 : daemon has been started or was already running
61 # 1 : generic or unspecified errors (could not be started)
62 # 6 : program is not configured (missing configuration files)
69 echo -n "Starting $DESC: $NAME "
74 # Check fwknopd configuration
78 # Try to start fwknopd
79 if [ "$retval" = "0" ]; then
80 start-stop-daemon --start --quiet --pidfile $PIDDIR/$NAME --exec $DAEMON
84 # Handle return status codes
90 log_failure_msg "You are missing the configuration file $ConfFile."
97 log_failure_msg "Unable to start the daemon."
105 # Function that stops the daemon/service
108 # 0 : daemon has been stopped or was already stopped
109 # 1 : daemon could not be stopped
115 local status kill_status
117 local process_list="fwknopd"
119 echo -n "Stopping $DESC:"
122 for process in $process_list; do
124 pidfile="$PIDDIR/$process.pid"
130 # Try to kill the process associated to the pid
131 if [ -r "$pidfile" ]; then
132 pid=`cat "$pidfile" 2>/dev/null`
133 kill -0 "${pid:-}" 2>/dev/null
138 if [ "$kill_status" = "0" ]; then
139 start-stop-daemon --stop --oknodo --quiet --pidfile "$pidfile"
143 # Remove its pid file
144 if [ -r "$pidfile" ] && [ "$status" = "0" ]; then
145 rm -f "$pidfile" 2>/dev/null
149 [ "$status" = "0" ] || retval="1"
154 if [ "$retval" = "0" ]; then
158 log_failure_msg "One or more process could not be stopped."
165 # Function that returns the daemon status
170 echo "Status of $DESC:"
183 restart|force-reload)
195 log_success_msg "Usage: $0 {start|stop|restart|status}" >&2