4 # Provides: fwknop-server
5 # Required-Start: $local_fs $remote_fs $syslog $network
6 # Required-Stop: $local_fs $remote_fs $syslog $network
7 # Default-Start: 2 3 4 5
9 # Short-Description: start and stop fwknopd
10 # Description: Fwknop implements an authorization scheme known as \
11 # Single Packet Authorization (SPA) for Linux systems \
15 # Author: Franck Joncourt <franck@debian.org>
17 PATH=/sbin:/usr/sbin:/bin:/usr/bin
18 DESC="FireWall KNock OPerator"
20 DAEMON=/usr/sbin/$NAME
21 PIDDIR=/var/run/fwknop
22 SCRIPTNAME=/etc/init.d/fwknop-server
24 # Exit if the package is not installed
25 [ -x "$DAEMON" ] || exit 0
27 # Load user options to pass to fwknopd daemon
30 [ -r /etc/default/fwknop-server ] && . /etc/default/fwknop-server
32 # Exit if the dameon must not be started
33 [ "$START_DAEMON" = "yes" ] || exit 0
35 # Load the VERBOSE setting and other rcS variables
38 # Define LSB log_* functions.
39 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
40 . /lib/lsb/init-functions
43 # Function that checks if all of the configuration files exist
46 # 0 : all of the configuration files exist
47 # 6 : at least one file is missing
56 file_list="/etc/fwknop/access.conf /etc/fwknop/fwknopd.conf"
58 for ConfFile in $file_list; do
59 if [ ! -f "$ConfFile" ]; then
69 # Function that starts the daemon/service
72 # 0 : daemon has been started or was already running
73 # 1 : generic or unspecified errors (could not be started)
74 # 6 : program is not configured (missing configuration files)
84 # Check fwknopd configuration
88 # Try to start fwknopd
89 if [ "$retval" = "0" ]; then
90 start-stop-daemon --start --quiet --pidfile $PIDDIR/$NAME --exec $DAEMON -- $DAEMON_ARGS
94 # Handle return status codes
99 log_action_msg "You are missing the configuration file $ConfFile." || true
106 log_action_msg "Unable to start the daemon." || true
110 log_daemon_msg "Starting $DESC" "$NAME" || true
111 log_end_msg $retval || true
117 # Function that stops the daemon/service
120 # 0 : daemon has been stopped or was already stopped
121 # 1 : daemon could not be stopped
127 local status kill_status
129 local process_list="fwknopd"
132 for process in $process_list; do
134 pidfile="$PIDDIR/$process.pid"
138 # Try to kill the process associated to the pid
139 if [ -r "$pidfile" ]; then
140 pid=`cat "$pidfile" 2>/dev/null`
141 kill -0 "${pid:-}" 2>/dev/null
146 if [ "$kill_status" = "0" ]; then
147 start-stop-daemon --stop --oknodo --quiet --pidfile "$pidfile"
151 # Remove its pid file
152 if [ -r "$pidfile" ] && [ "$status" = "0" ]; then
153 rm -f "$pidfile" 2>/dev/null
157 [ "$status" = "0" ] || retval="1"
162 if [ "$retval" != "0" ]; then
163 log_action_msg "The process could not be stopped" || true
166 log_daemon_msg "Stopping $DESC" "$NAME" || true
167 log_end_msg $retval || true
173 # Function that returns the daemon status
178 echo "Status of $DESC:"
191 restart|force-reload)
203 log_success_msg "Usage: $0 {start|stop|restart|status}" >&2