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.mail@dthconnex.com>
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-server
20
# Exit if the package is not installed
21
[ -x "$DAEMON" ] || exit 0
23
# Load user options to pass to fwknopd daemon
24
[ -r /etc/default/fwknop-server ] && . /etc/default/fwknop-server
26
# Exit if the dameon must not be started
27
[ "$START_DAEMON" = "yes" ] || exit 0
29
# Load the VERBOSE setting and other rcS variables
32
# Define LSB log_* functions.
33
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
34
. /lib/lsb/init-functions
37
# Function that checks if all of the configuration files exist
40
# 0 : all of the configuration files exist
41
# 6 : at least one file is missing
49
file_list="/etc/fwknop/access.conf /etc/fwknop/fwknop.conf"
51
for ConfFile in $file_list; do
52
if [ ! -f "$ConfFile" ]; then
62
# Function that starts the daemon/service
64
# 0 : daemon has been started or was already running
65
# 1 : generic or unspecified errors (could not be started)
66
# 6 : program is not configured (missing configuration files)
72
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 "Unable to start the daemon."
105
# Function that stops the daemon/service
107
# The upstream author has allowed the daemon to be killed through the
108
# following command-line : fwknopd --Kill
110
# As fwknopd starts knoptm and knopwatchd on its own, we need to stop them before.
113
# 0 : daemon has been stopped or was already stopped
114
# 1 : daemon could not be stopped
119
local status kill_status
121
local process_list="knopwatchd knoptm fwknopd"
123
echo -n "Stopping $DESC:"
126
for process in $process_list; do
128
pidfile="$PIDDIR/$process.pid"
134
# Try to kill the process associated to the pid
135
if [ -r "$pidfile" ]; then
136
pid=`cat "$pidfile" 2>/dev/null`
137
kill -0 "${pid:-}" 2>/dev/null
142
if [ "$kill_status" = "0" ]; then
143
start-stop-daemon --stop --oknodo --quiet --pidfile "$pidfile"
147
# Remove its pid file
148
if [ -r "$pidfile" ] && [ "$status" = "0" ]; then
149
rm -f "$pidfile" 2>/dev/null
153
[ "$status" = "0" ] || retval="1"
158
if [ "$retval" = "0" ]; then
162
log_failure_msg "One or more process could not be stopped."
169
# Function that returns the daemon status
173
echo "Status of $DESC:"
186
restart|force-reload)
198
log_success_msg "Usage: $0 {start|stop|restart}" >&2