3 # /etc/init.d/openvswitch-switch
5 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
6 # Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
7 # Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
8 # Modified for openvswitch-switch.
10 # Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
13 # Provides: openvswitch-switch
14 # Required-Start: $network $named $remote_fs $syslog
16 # Default-Start: 2 3 4 5
18 # Short-Description: Open vSwitch switch
21 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
22 ovs_vswitchd=/usr/sbin/ovs-vswitchd
23 ovsdb_server=/usr/bin/ovsdb-server
25 (test -x $ovsdb_server && test -x $ovs_vswitchd) || exit 0
27 DODTIME=1 # Time to wait for the server to die, in seconds
28 # If this value is set too low you might not
29 # let some servers to die gracefully and
30 # 'restart' will not work
32 # Include ovs-openflowd defaults if available
33 unset OVSDB_SERVER_OPTS
34 unset OVS_VSWITCHD_OPTS
37 default=/etc/default/openvswitch-switch
38 if [ -f $default ] ; then
42 : ${ENABLE_MONITOR:=y}
46 # running_pid pid name
48 # Check if 'pid' is a process named 'name'
52 [ -z "$pid" ] && return 1
53 [ ! -d /proc/$pid ] && return 1
54 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
55 # Is this the expected child?
68 # Checks for a running process named 'name' by looking for a pidfile
69 # named /var/run/${name}.pid
73 local pidfile=/var/run/${name}.pid
75 # No pidfile, probably no daemon present
76 [ ! -f "$pidfile" ] && return 1
78 # Obtain the pid and check it against the binary name
80 running_pid $pid $name || return 1
86 # Checks for a running process named 'name', by looking for a pidfile
87 # named /var/run/${name}.pid, and then kills it and waits for it to
91 local pidfile=/var/run/${name}.pid
93 [ ! -f "$pidfile" ] && return
94 if running $name; then
96 [ -n "$DODTIME" ] && sleep "$DODTIME"s
97 if running $name; then
99 [ -n "$DODTIME" ] && sleep "$DODTIME"s
100 if running $name; then
101 echo "Cannot kill $name (pid=$pid)!"
131 # is_module_loaded module
133 # Returns 0 if 'module' is loaded, 1 otherwise.
137 grep -q "^$module " /proc/modules
142 # Loads 'module' into the running kernel, if it is not already loaded.
145 echo -n "Loading $module: "
146 if is_module_loaded $module; then
147 echo "already loaded, nothing to do."
148 elif modprobe $module; then
152 echo "$module has probably not been built for this kernel."
153 if ! test -d /usr/share/doc/openvswitch-datapath-source; then
154 echo "Install the openvswitch-datapath-source package, then read"
155 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
157 echo "For instructions, read"
158 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
164 # unload_module module
166 # Unloads 'module' from the running kernel, if it is loaded.
169 echo -n "Unloading $module: "
170 if is_module_loaded $module; then
171 if rmmod $module; then
178 echo "not loaded, nothing to do."
183 if is_module_loaded openvswitch_mod; then
184 for dp in $(ovs-dpctl dump-dps); do
185 echo -n "Deleting datapath $dp: "
186 if ovs-dpctl del-dp $dp; then
193 unload_module openvswitch_mod
194 unload_module ip_gre_mod
199 load_module openvswitch_mod
201 load_module ip_gre_mod
203 if test -n "$CORE_LIMIT"; then
204 check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
207 # Create an empty configuration database if it doesn't exist.
208 if test ! -e /etc/openvswitch/conf.db; then
209 # Create configuration database.
210 ovsdb-tool -vANY:console:emer \
211 create /etc/openvswitch-switch/conf \
212 /usr/share/openvswitch/vswitch.ovsschema
214 # Upgrade or downgrade schema and compact database.
215 ovsdb-tool -vANY:console:emer \
216 convert /etc/openvswitch-switch/conf \
217 /usr/share/openvswitch/vswitch.ovsschema
220 if test "$ENABLE_MONITOR" = y; then
221 monitor_opt=--monitor
226 # Start ovsdb-server.
228 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
229 set -- "$@" --log-file
230 set -- "$@" --detach --pidfile $monitor_opt
231 set -- "$@" --remote punix:/var/run/ovsdb-server
232 set -- "$@" /etc/openvswitch-switch/conf
233 set -- "$@" --private-key=db:SSL,private_key
234 set -- "$@" --certificate=db:SSL,certificate
235 set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert
236 set -- "$@" $OVSDB_SERVER_OPTS
237 echo -n "Starting ovsdb-server: "
238 start-stop-daemon --start --quiet --pidfile /var/run/ovsdb-server.pid \
239 --exec $ovsdb_server -- "$@"
240 if running ovsdb-server; then
246 ovs-vsctl --no-wait init
248 # Start ovs-vswitchd.
250 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
251 set -- "$@" --log-file
252 set -- "$@" --detach --pidfile $monitor_opt
253 set -- "$@" unix:/var/run/ovsdb-server
254 set -- "$@" $OVS_VSWITCHD_OPTS
255 echo -n "Starting ovs-vswitchd: "
256 start-stop-daemon --start --quiet --pidfile /var/run/ovs-vswitchd.pid \
257 --exec $ovs_vswitchd -- "$@"
258 if running ovs-vswitchd; then
265 echo -n "Stopping ovs-vswitchd: "
266 start-stop-daemon --stop --quiet --oknodo \
267 --pidfile /var/run/ovs-vswitchd.pid \
271 echo -n "Stopping ovsdb-server: "
272 start-stop-daemon --stop --quiet --oknodo \
273 --pidfile /var/run/ovsdb-server.pid \
278 echo -n "Forcefully stopping ovs-vswitchd: "
279 force_stop ovs-vswitchd
280 if ! running ovs-vswitchd; then
286 echo -n "Forcefully stopping ovsdb-server: "
287 force_stop ovsdb-server
288 if ! running ovsdb-server; then
300 # Nothing to do, since ovs-vswitchd automatically reloads
301 # whenever its configuration changes, and ovsdb-server doesn't
302 # have anything to reload.
309 for daemon in ovs-vswitchd ovsdb-server; do
310 echo -n "$daemon is "
311 if running $daemon; then
321 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2