3 # Copyright (c) 2007, 2009 Javier Fernandez-Sanguino <jfs@debian.org>
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.
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.
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
21 # Provides: openvswitch-controller
22 # Required-Start: $network $local_fs $remote_fs
23 # Required-Stop: $remote_fs
24 # Should-Start: $named
26 # Default-Start: 2 3 4 5
28 # Short-Description: Open vSwitch controller
31 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
33 DAEMON=/usr/sbin/ovs-controller # Introduce the server's location here
34 NAME=ovs-controller # Introduce the short server's name here
35 DESC=ovs-controller # Introduce a short description here
36 LOGDIR=/var/log/openvswitch # Log directory to use
38 PIDFILE=/var/run/openvswitch/$NAME.pid
40 test -x $DAEMON || exit 0
42 . /lib/lsb/init-functions
44 # Default options, these can be overriden by the information
45 # at /etc/default/$NAME
46 DAEMON_OPTS="" # Additional options given to the server
48 DODTIME=10 # Time to wait for the server to die, in seconds
49 # If this value is set too low you might not
50 # let some servers to die gracefully and
51 # 'restart' will not work
53 LOGFILE=$LOGDIR/$NAME.log # Server logfile
54 #DAEMONUSER= # User to run the daemons as. If this value
55 # is set start-stop-daemon will chuid the server
57 # Include defaults if available
58 default=/etc/default/openvswitch-controller
59 if [ -f $default ] ; then
63 # Check that the user exists (if we set a user)
64 # Does the user exist?
65 if [ -n "$DAEMONUSER" ] ; then
66 if getent passwd | grep -q "^$DAEMONUSER:"; then
67 # Obtain the uid and gid
68 DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
69 DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
71 log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
80 # Check if a given process pid's cmdline matches a given name
83 [ -z "$pid" ] && return 1
84 [ ! -d /proc/$pid ] && return 1
85 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
86 # Is this the expected server
87 [ "$cmd" != "$name" ] && return 1
92 # Check if the process is running looking at /proc
93 # (works for all users)
95 # No pidfile, probably no daemon present
96 [ ! -f "$PIDFILE" ] && return 1
98 running_pid $pid $DAEMON || return 1
103 if [ -z "$LISTEN" ]; then
104 echo "$default: No connection methods configured, controller disabled" >&2
111 : ${PRIVKEY:=/etc/openvswitch-controller/privkey.pem}
112 : ${CERT:=/etc/openvswitch-controller/cert.pem}
113 : ${CACERT:=/etc/openvswitch-controller/cacert.pem}
114 if test ! -e "$PRIVKEY" || test ! -e "$CERT" ||
115 test ! -e "$CACERT"; then
116 if test ! -e "$PRIVKEY"; then
117 echo "$PRIVKEY: private key missing" >&2
119 if test ! -e "$CERT"; then
120 echo "$CERT: certificate for private key missing" >&2
122 if test ! -e "$CACERT"; then
123 echo "$CACERT: CA certificate missing" >&2
127 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
131 # Start the process using the wrapper
132 if [ -z "$DAEMONUSER" ] ; then
133 start-stop-daemon --start --pidfile $PIDFILE \
134 --exec $DAEMON -- --detach --pidfile=$PIDFILE \
135 $LISTEN $DAEMON_OPTS $SSL_OPTS
138 # if we are using a daemonuser then change the user id
139 start-stop-daemon --start --quiet --pidfile $PIDFILE \
140 --chuid $DAEMONUSER --exec $DAEMON -- \
141 --detach --pidfile=$PIDFILE $LISTEN $DAEMON_OPTS \
149 # Stop the process using the wrapper
150 if [ -z "$DAEMONUSER" ] ; then
151 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
155 # if we are using a daemonuser then look for process that match
156 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
157 --user $DAEMONUSER --exec $DAEMON
165 [ ! -f "$PIDFILE" ] && return 1
166 pid=`cat $PIDFILE` # This is the daemon's pid
173 # Force the process to die killing it manually
174 [ ! -e "$PIDFILE" ] && return
183 echo "Cannot kill $NAME (pid=$pid)!"
194 log_daemon_msg "Starting $DESC " "$NAME"
195 # Check if it's running first
197 log_progress_msg "apparently already running"
201 if start_server && running ; then
202 # It's ok, the server started and is running
205 # Either we could not start it or it is not running
207 # NOTE: Some servers might die some time after they start,
208 # this code does not try to detect this and might give
209 # a false positive (use 'status' for that)
214 log_daemon_msg "Stopping $DESC" "$NAME"
216 # Only stop the server if we see it running
220 # If it's not running don't do anything
221 log_progress_msg "apparently not running"
227 # First try to stop gracefully the program
230 # If it's still running try to kill it more forcefully
231 log_daemon_msg "Stopping (force) $DESC" "$NAME"
236 restart|force-reload)
237 log_daemon_msg "Restarting $DESC" "$NAME"
239 # Wait some sensible amount, some server need this
240 [ -n "$DIETIME" ] && sleep $DIETIME
247 log_daemon_msg "Checking status of $DESC" "$NAME"
249 log_progress_msg "running"
252 log_progress_msg "apparently not running"
257 # Use this if the daemon cannot reload
259 log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
260 log_warning_msg "cannot re-read the config file (use restart)."
264 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2