]> git.proxmox.com Git - ovs.git/blob - debian/openvswitch-ipsec.init
[ Felix Moessbauer ]
[ovs.git] / debian / openvswitch-ipsec.init
1 #!/bin/sh
2 #
3 # Copyright (c) 2007, 2009 Javier Fernandez-Sanguino <jfs@debian.org>
4 #
5 # This is free software; you may redistribute it and/or modify
6 # it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2,
8 # or (at your option) any later version.
9 #
10 # This is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License with
16 # the Debian operating system, in /usr/share/common-licenses/GPL; if
17 # not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
19 #
20 ### BEGIN INIT INFO
21 # Provides: openvswitch-ipsec
22 # Required-Start: $network $local_fs $remote_fs openvswitch-switch
23 # Required-Stop: $remote_fs
24 # Default-Start: 2 3 4 5
25 # Default-Stop: 0 1 6
26 # Short-Description: Open vSwitch GRE-over-IPsec daemon
27 # Description: The ovs-monitor-ipsec script provides support for
28 # encrypting GRE tunnels with IPsec.
29 ### END INIT INFO
30
31 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
32
33 DAEMON=/usr/share/openvswitch/scripts/ovs-monitor-ipsec # Daemon's location
34 NAME=ovs-monitor-ipsec # Introduce the short server's name here
35 LOGDIR=/var/log/openvswitch # Log directory to use
36 DATADIR=/usr/share/openvswitch
37
38 PIDFILE=/var/run/openvswitch/$NAME.pid
39
40 test -x $DAEMON || exit 0
41
42 . /lib/lsb/init-functions
43
44 DODTIME=10 # Time to wait for the server to die, in seconds
45 # If this value is set too low you might not
46 # let some servers to die gracefully and
47 # 'restart' will not work
48
49 set -e
50
51 running_pid() {
52 # Check if a given process pid's cmdline matches a given name
53 pid=$1
54 name=$2
55 [ -z "$pid" ] && return 1
56 [ ! -d /proc/$pid ] && return 1
57 cmd=`cat /proc/$pid/cmdline | tr "\000" " "|cut -d " " -f 2`
58 # Is this the expected server
59 [ "$cmd" != "$name" ] && return 1
60 return 0
61 }
62
63 running() {
64 # Check if the process is running looking at /proc
65 # (works for all users)
66
67 # No pidfile, probably no daemon present
68 [ ! -f "$PIDFILE" ] && return 1
69 pid=`cat $PIDFILE`
70 running_pid $pid $DAEMON || return 1
71 return 0
72 }
73
74 start_server() {
75 ${DATADIR}/scripts/ovs-ctl --ike-daemon=strongswan start-ovs-ipsec
76 return 0
77 }
78
79 stop_server() {
80 ${DATADIR}/scripts/ovs-ctl stop-ovs-ipsec
81 return 0
82 }
83
84 force_stop() {
85 # Force the process to die killing it manually
86 [ ! -e "$PIDFILE" ] && return
87 if running ; then
88 kill -15 $pid
89 # Is it really dead?
90 sleep "$DODTIME"
91 if running ; then
92 kill -9 $pid
93 sleep "$DODTIME"
94 if running ; then
95 echo "Cannot kill $NAME (pid=$pid)!"
96 exit 1
97 fi
98 fi
99 fi
100 rm -f $PIDFILE
101 }
102
103
104 case "$1" in
105 start)
106 log_daemon_msg "Starting $NAME"
107 # Check if it's running first
108 if running ; then
109 log_progress_msg "apparently already running"
110 log_end_msg 0
111 exit 0
112 fi
113 if start_server && running ; then
114 # It's ok, the server started and is running
115 log_end_msg 0
116 else
117 # Either we could not start it or it is not running
118 # after we did
119 # NOTE: Some servers might die some time after they start,
120 # this code does not try to detect this and might give
121 # a false positive (use 'status' for that)
122 log_end_msg 1
123 fi
124 ;;
125 stop)
126 log_daemon_msg "Stopping $NAME"
127 if running ; then
128 # Only stop the server if we see it running
129 stop_server
130 log_end_msg $?
131 else
132 # If it's not running don't do anything
133 log_progress_msg "apparently not running"
134 log_end_msg 0
135 exit 0
136 fi
137 ;;
138 force-stop)
139 # First try to stop gracefully the program
140 $0 stop
141 if running; then
142 # If it's still running try to kill it more forcefully
143 log_daemon_msg "Stopping (force) $NAME"
144 force_stop
145 log_end_msg $?
146 fi
147 ;;
148 restart|force-reload)
149 log_daemon_msg "Restarting $NAME"
150 stop_server
151 # Wait some sensible amount, some server need this
152 [ -n "$DODTIME" ] && sleep $DODTIME
153 start_server
154 running
155 log_end_msg $?
156 ;;
157 status)
158 log_daemon_msg "Checking status of $NAME"
159 if running ; then
160 log_progress_msg "running"
161 log_end_msg 0
162 else
163 log_progress_msg "apparently not running"
164 log_end_msg 1
165 exit 1
166 fi
167 ;;
168 # Use this if the daemon cannot reload
169 reload)
170 log_warning_msg "Reloading $NAME daemon: not implemented, as the"
171 log_warning_msg "deamon cannot re-read the config file (use restart)."
172 ;;
173 *)
174 N=/etc/init.d/openvswitch-ipsec
175 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" \
176 >&2
177 exit 1
178 ;;
179 esac
180
181 exit 0