3 # Copyright (c) 2011 Nicira Networks Inc.
4 # Copyright (c) 2007, 2009 Javier Fernandez-Sanguino <jfs@debian.org>
6 # This is free software; you may redistribute it and/or modify
7 # it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2,
9 # or (at your option) any later version.
11 # This is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License with
17 # the Debian operating system, in /usr/share/common-licenses/GPL; if
18 # not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
22 # Provides: openvswitch-controller
23 # Required-Start: $network $local_fs $remote_fs
24 # Required-Stop: $remote_fs
25 # Should-Start: $named
27 # Default-Start: 2 3 4 5
29 # Short-Description: Open vSwitch controller
32 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
34 DAEMON=/usr/bin/ovs-controller # Introduce the server's location here
35 NAME=ovs-controller # Introduce the short server's name here
36 DESC=ovs-controller # Introduce a short description here
37 LOGDIR=/var/log/openvswitch # Log directory to use
39 PIDFILE=/var/run/openvswitch/$NAME.pid
41 test -x $DAEMON || exit 0
43 . /lib/lsb/init-functions
45 # Default options, these can be overriden by the information
46 # at /etc/default/openvswitch-controller
47 DAEMON_OPTS="" # Additional options given to the server
49 DODTIME=10 # Time to wait for the server to die, in seconds
50 # If this value is set too low you might not
51 # let some servers to die gracefully and
52 # 'restart' will not work
54 LOGFILE=$LOGDIR/$NAME.log # Server logfile
55 #DAEMONUSER= # User to run the daemons as. If this value
56 # is set start-stop-daemon will chuid the server
58 # Include defaults if available
59 default=/etc/default/openvswitch-controller
60 if [ -f $default ] ; then
64 # Check that the user exists (if we set a user)
65 # Does the user exist?
66 if [ -n "$DAEMONUSER" ] ; then
67 if getent passwd | grep -q "^$DAEMONUSER:"; then
68 # Obtain the uid and gid
69 DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
70 DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
72 log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
81 # Check if a given process pid's cmdline matches a given name
84 [ -z "$pid" ] && return 1
85 [ ! -d /proc/$pid ] && return 1
86 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
87 # Is this the expected server
88 [ "$cmd" != "$name" ] && return 1
93 # Check if the process is running looking at /proc
94 # (works for all users)
96 # No pidfile, probably no daemon present
97 [ ! -f "$PIDFILE" ] && return 1
99 running_pid $pid $DAEMON || return 1
104 if [ -z "$LISTEN" ]; then
105 echo "$default: No connection methods configured, controller disabled" >&2
109 if [ ! -d /var/run/openvswitch ]; then
110 install -d -m 755 -o root -g root /var/run/openvswitch
116 : ${PRIVKEY:=/etc/openvswitch-controller/privkey.pem}
117 : ${CERT:=/etc/openvswitch-controller/cert.pem}
118 : ${CACERT:=/etc/openvswitch-controller/cacert.pem}
119 if test ! -e "$PRIVKEY" || test ! -e "$CERT" ||
120 test ! -e "$CACERT"; then
121 if test ! -e "$PRIVKEY"; then
122 echo "$PRIVKEY: private key missing" >&2
124 if test ! -e "$CERT"; then
125 echo "$CERT: certificate for private key missing" >&2
127 if test ! -e "$CACERT"; then
128 echo "$CACERT: CA certificate missing" >&2
132 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
136 # Start the process using the wrapper
137 if [ -z "$DAEMONUSER" ] ; then
138 start-stop-daemon --start --pidfile $PIDFILE \
139 --exec $DAEMON -- --detach --pidfile=$PIDFILE \
140 $LISTEN $DAEMON_OPTS $SSL_OPTS
143 # if we are using a daemonuser then change the user id
144 start-stop-daemon --start --quiet --pidfile $PIDFILE \
145 --chuid $DAEMONUSER --exec $DAEMON -- \
146 --detach --pidfile=$PIDFILE $LISTEN $DAEMON_OPTS \
154 # Stop the process using the wrapper
155 if [ -z "$DAEMONUSER" ] ; then
156 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
160 # if we are using a daemonuser then look for process that match
161 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
162 --user $DAEMONUSER --exec $DAEMON
170 [ ! -f "$PIDFILE" ] && return 1
171 pid=`cat $PIDFILE` # This is the daemon's pid
178 # Force the process to die killing it manually
179 [ ! -e "$PIDFILE" ] && return
188 echo "Cannot kill $NAME (pid=$pid)!"
199 log_daemon_msg "Starting $DESC " "$NAME"
200 # Check if it's running first
202 log_progress_msg "apparently already running"
206 if start_server && running ; then
207 # It's ok, the server started and is running
210 # Either we could not start it or it is not running
212 # NOTE: Some servers might die some time after they start,
213 # this code does not try to detect this and might give
214 # a false positive (use 'status' for that)
219 log_daemon_msg "Stopping $DESC" "$NAME"
221 # Only stop the server if we see it running
225 # If it's not running don't do anything
226 log_progress_msg "apparently not running"
232 # First try to stop gracefully the program
235 # If it's still running try to kill it more forcefully
236 log_daemon_msg "Stopping (force) $DESC" "$NAME"
241 restart|force-reload)
242 log_daemon_msg "Restarting $DESC" "$NAME"
244 # Wait some sensible amount, some server need this
245 [ -n "$DODTIME" ] && sleep $DODTIME
252 log_daemon_msg "Checking status of $DESC" "$NAME"
254 log_progress_msg "running"
257 log_progress_msg "apparently not running"
262 # Use this if the daemon cannot reload
264 log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
265 log_warning_msg "cannot re-read the config file (use restart)."
268 N=/etc/init.d/openvswitch-controller
269 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2