3 # Copyright (c) 2011, 2014 Nicira, 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-testcontroller
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: Simple OpenFlow controller for testing
30 # Description: This controller enables OpenFlow switches that connect to
31 # it to act as MAC-learning Ethernet switches.
34 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
36 DAEMON
=/usr
/bin
/ovs-testcontroller
# Introduce the server's location here
37 NAME
=ovs-testcontroller
# Introduce the short server's name here
38 DESC
=ovs-testcontroller
# Introduce a short description here
39 LOGDIR
=/var
/log
/openvswitch
# Log directory to use
41 PIDFILE
=/var
/run
/openvswitch
/$NAME.pid
43 test -x $DAEMON ||
exit 0
45 .
/lib
/lsb
/init-functions
47 # Default options, these can be overriden by the information
48 # at /etc/default/openvswitch-testcontroller
49 DAEMON_OPTS
="" # Additional options given to the server
51 DODTIME
=10 # Time to wait for the server to die, in seconds
52 # If this value is set too low you might not
53 # let some servers to die gracefully and
54 # 'restart' will not work
56 LOGFILE
=$LOGDIR/$NAME.log
# Server logfile
57 #DAEMONUSER= # User to run the daemons as. If this value
58 # is set start-stop-daemon will chuid the server
60 # Include defaults if available
61 default
=/etc
/default
/openvswitch-testcontroller
62 if [ -f $default ] ; then
66 # Check that the user exists (if we set a user)
67 # Does the user exist?
68 if [ -n "$DAEMONUSER" ] ; then
69 if getent passwd |
grep -q "^$DAEMONUSER:"; then
70 # Obtain the uid and gid
71 DAEMONUID
=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
72 DAEMONGID
=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
74 log_failure_msg
"The user $DAEMONUSER, required to run $NAME does not exist."
83 # Check if a given process pid's cmdline matches a given name
86 [ -z "$pid" ] && return 1
87 [ ! -d /proc
/$pid ] && return 1
88 cmd
=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
89 # Is this the expected server
90 [ "$cmd" != "$name" ] && return 1
95 # Check if the process is running looking at /proc
96 # (works for all users)
98 # No pidfile, probably no daemon present
99 [ ! -f "$PIDFILE" ] && return 1
101 running_pid
$pid $DAEMON ||
return 1
106 if [ -z "$LISTEN" ]; then
107 echo "$default: No connection methods configured, controller disabled" >&2
111 if [ ! -d /var
/run
/openvswitch
]; then
112 install -d -m 755 -o root
-g root
/var
/run
/openvswitch
118 : ${PRIVKEY:=/etc/openvswitch-testcontroller/privkey.pem}
119 : ${CERT:=/etc/openvswitch-testcontroller/cert.pem}
120 : ${CACERT:=/etc/openvswitch-testcontroller/cacert.pem}
121 if test ! -e "$PRIVKEY" ||
test ! -e "$CERT" ||
122 test ! -e "$CACERT"; then
123 if test ! -e "$PRIVKEY"; then
124 echo "$PRIVKEY: private key missing" >&2
126 if test ! -e "$CERT"; then
127 echo "$CERT: certificate for private key missing" >&2
129 if test ! -e "$CACERT"; then
130 echo "$CACERT: CA certificate missing" >&2
134 SSL_OPTS
="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
138 # Start the process using the wrapper
139 if [ -z "$DAEMONUSER" ] ; then
140 start-stop-daemon
--start --pidfile $PIDFILE \
141 --exec $DAEMON -- --detach --pidfile=$PIDFILE \
142 $LISTEN $DAEMON_OPTS $SSL_OPTS
145 # if we are using a daemonuser then change the user id
146 start-stop-daemon
--start --quiet --pidfile $PIDFILE \
147 --chuid $DAEMONUSER --exec $DAEMON -- \
148 --detach --pidfile=$PIDFILE $LISTEN $DAEMON_OPTS \
156 # Stop the process using the wrapper
157 if [ -z "$DAEMONUSER" ] ; then
158 start-stop-daemon
--stop --quiet --pidfile $PIDFILE \
162 # if we are using a daemonuser then look for process that match
163 start-stop-daemon
--stop --quiet --pidfile $PIDFILE \
164 --user $DAEMONUSER --exec $DAEMON
172 [ ! -f "$PIDFILE" ] && return 1
173 pid
=`cat $PIDFILE` # This is the daemon's pid
180 # Force the process to die killing it manually
181 [ ! -e "$PIDFILE" ] && return
190 echo "Cannot kill $NAME (pid=$pid)!"
201 log_daemon_msg
"Starting $DESC " "$NAME"
202 # Check if it's running first
204 log_progress_msg
"apparently already running"
208 if start_server
&& running
; then
209 # It's ok, the server started and is running
212 # Either we could not start it or it is not running
214 # NOTE: Some servers might die some time after they start,
215 # this code does not try to detect this and might give
216 # a false positive (use 'status' for that)
221 log_daemon_msg
"Stopping $DESC" "$NAME"
223 # Only stop the server if we see it running
227 # If it's not running don't do anything
228 log_progress_msg
"apparently not running"
234 # First try to stop gracefully the program
237 # If it's still running try to kill it more forcefully
238 log_daemon_msg
"Stopping (force) $DESC" "$NAME"
243 restart|force-reload
)
244 log_daemon_msg
"Restarting $DESC" "$NAME"
247 # Wait some sensible amount, some server need this.
248 [ -n "$DODTIME" ] && sleep $DODTIME
256 log_daemon_msg
"Checking status of $DESC" "$NAME"
258 log_progress_msg
"running"
261 log_progress_msg
"apparently not running"
266 # Use this if the daemon cannot reload
268 log_warning_msg
"Reloading $NAME daemon: not implemented, as the daemon"
269 log_warning_msg
"cannot re-read the config file (use restart)."
272 N
=/etc
/init.d
/openvswitch-testcontroller
273 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2