~kampka/ubuntu/quantal/fwknop/upstart-support

« back to all changes in this revision

Viewing changes to debian/fwknop-server.init

  • Committer: Bazaar Package Importer
  • Author(s): Franck Joncourt
  • Date: 2008-10-02 19:32:55 UTC
  • Revision ID: james.westby@ubuntu.com-20081002193255-02knm8mw3oxt0ojl
Tags: 1.9.8-1
* Initial release (Closes: #406627) 
* Includes fr debconf translation (Closes: #500655)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          fwknop
 
4
# Required-Start:    $remote_fs
 
5
# Required-Stop:     $remote_fs
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: FireWall KNock OPerator (fwknop)
 
9
### END INIT INFO
 
10
 
 
11
# Author: Franck Joncourt <franck.mail@dthconnex.com>
 
12
 
 
13
PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
14
DESC="FireWall KNock OPerator"
 
15
NAME=fwknopd
 
16
DAEMON=/usr/sbin/$NAME
 
17
PIDDIR=/var/run/fwknop
 
18
SCRIPTNAME=/etc/init.d/fwknop-server
 
19
 
 
20
# Exit if the package is not installed
 
21
[ -x "$DAEMON" ] || exit 0
 
22
 
 
23
# Load user options to pass to fwknopd daemon
 
24
[ -r /etc/default/fwknop-server ] && . /etc/default/fwknop-server
 
25
 
 
26
# Exit if the dameon must not be started
 
27
[ "$START_DAEMON" = "yes" ] || exit 0
 
28
 
 
29
# Load the VERBOSE setting and other rcS variables
 
30
. /lib/init/vars.sh
 
31
 
 
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
 
35
 
 
36
#
 
37
# Function that checks if all of the configuration files exist
 
38
#
 
39
# Return
 
40
#   0 : all of the configuration files exist
 
41
#   6 : at least one file is missing
 
42
 
 
43
check_config()
 
44
{
 
45
        local retval
 
46
        local file_list
 
47
 
 
48
        retval=0
 
49
        file_list="/etc/fwknop/access.conf /etc/fwknop/fwknop.conf"
 
50
 
 
51
        for ConfFile in $file_list; do
 
52
                if [ ! -f "$ConfFile" ]; then
 
53
                        retval=6        
 
54
                        break   
 
55
                fi
 
56
        done
 
57
 
 
58
        return $retval
 
59
}
 
60
 
 
61
#
 
62
# Function that starts the daemon/service
 
63
#
 
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)
 
67
 
 
68
do_start()
 
69
{
 
70
        local retval
 
71
 
 
72
        echo -n "Starting $DESC: $NAME "
 
73
 
 
74
        # Check fwknopd configuration
 
75
        check_config
 
76
        retval=$?
 
77
 
 
78
        # Try to start fwknopd
 
79
        if [ "$retval"  = "0" ]; then
 
80
                start-stop-daemon --start --quiet --pidfile $PIDDIR/$NAME --exec $DAEMON
 
81
                retval="$?"
 
82
        fi
 
83
 
 
84
        # Handle return status codes
 
85
        case "$retval" in
 
86
                0)       
 
87
                        log_success_msg
 
88
                        ;;
 
89
                6)      
 
90
                        log_failure_msg "You are missing the configuration file $ConfFile."
 
91
                        ;;
 
92
                9)      
 
93
                        retval=0
 
94
                        ;;
 
95
                *)
 
96
                        retval=1
 
97
                        log_failure "Unable to start the daemon."
 
98
                        ;;
 
99
        esac
 
100
 
 
101
        return $retval
 
102
}
 
103
 
 
104
#
 
105
# Function that stops the daemon/service
 
106
#
 
107
# The upstream author has allowed the daemon to be killed through the 
 
108
# following command-line : fwknopd --Kill
 
109
#
 
110
# As fwknopd starts knoptm and knopwatchd on its own, we need to stop them before.
 
111
#
 
112
# Return
 
113
#   0 : daemon has been stopped or was already stopped
 
114
#   1 : daemon could not be stopped
 
115
 
 
116
do_stop()
 
117
{
 
118
        local retval="0"
 
119
        local status kill_status
 
120
        local pid pidfile
 
121
        local process_list="knopwatchd knoptm fwknopd"
 
122
 
 
123
        echo -n "Stopping $DESC:"
 
124
 
 
125
        # For each process
 
126
        for process in $process_list; do
 
127
 
 
128
                pidfile="$PIDDIR/$process.pid"
 
129
                status="0"
 
130
                kill_status="1"
 
131
 
 
132
                echo -n " $process"
 
133
 
 
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
 
138
                        kill_status="$?"
 
139
                fi
 
140
 
 
141
                # Stop the process
 
142
                if [ "$kill_status" = "0" ]; then
 
143
                        start-stop-daemon --stop --oknodo --quiet --pidfile "$pidfile"
 
144
                        status="$?"
 
145
                fi
 
146
 
 
147
                # Remove its pid file
 
148
                if [ -r "$pidfile" ] && [ "$status" = "0" ]; then
 
149
                         rm -f "$pidfile" 2>/dev/null
 
150
                         status="$?"
 
151
                fi
 
152
 
 
153
                [ "$status" = "0" ] || retval="1"
 
154
 
 
155
        done
 
156
 
 
157
 
 
158
        if [ "$retval" = "0" ]; then
 
159
                log_success_msg
 
160
        else
 
161
                echo -n " "
 
162
                log_failure_msg "One or more process could not be stopped."
 
163
        fi
 
164
 
 
165
        return $retval
 
166
}
 
167
 
 
168
#
 
169
# Function that returns the daemon status
 
170
#
 
171
do_status()
 
172
{
 
173
        echo "Status of $DESC:"
 
174
        $DAEMON --Status
 
175
}
 
176
 
 
177
case "$1" in
 
178
        start)
 
179
                do_start
 
180
                ;;
 
181
 
 
182
        stop)
 
183
                do_stop
 
184
                ;;
 
185
 
 
186
        restart|force-reload)
 
187
                do_stop
 
188
                sleep 1
 
189
                do_start
 
190
                ;;
 
191
 
 
192
        status)
 
193
                do_status
 
194
                exit $?
 
195
                ;;
 
196
 
 
197
        *)
 
198
                log_success_msg "Usage: $0 {start|stop|restart}" >&2
 
199
                exit 1 
 
200
                ;;
 
201
esac
 
202
 
 
203
exit