5 # chkconfig: 2345 09 91
6 # description: Manage Open vSwitch kernel modules and user-space daemons
8 # Copyright (C) 2009, 2010 Nicira Networks, Inc.
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at:
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
22 . /etc/init.d/functions
24 . /etc/xensource-inventory
25 test -e /etc/sysconfig/openvswitch && . /etc/sysconfig/openvswitch
27 # General config variables in /etc/sysconfig/openvswitch
28 if test "$PRODUCT_VERSION" = "5.5.0"; then
29 # XenServer 5.5.0 needs ovs-brcompatd and /proc/net simulation.
30 : ${ENABLE_BRCOMPAT:=y}
31 : ${ENABLE_FAKE_PROC_NET:=y}
33 # Later versions don't need them.
34 : ${ENABLE_BRCOMPAT:=n}
35 : ${ENABLE_FAKE_PROC_NET:=n}
37 : ${ENABLE_MONITOR:=y}
38 : ${FORCE_COREFILES:=y}
40 # Config variables specific to ovsdb-server
41 : ${OVSDB_SERVER_REMOTES:=punix:/var/run/openvswitch/db.sock db:Open_vSwitch,managers}
42 : ${OVSDB_SERVER_DB:=/etc/openvswitch/conf.db}
43 : ${OVSDB_SERVER_PIDFILE:=/var/run/openvswitch/ovsdb-server.pid}
44 : ${OVSDB_SERVER_RUN_DIR:=/var/xen/openvswitch}
45 : ${OVSDB_SERVER_PRIORITY:=-10}
46 : ${OVSDB_SERVER_LOGFILE:=/var/log/openvswitch/ovsdb-server.log}
47 : ${OVSDB_SERVER_FILE_LOGLEVEL:=INFO}
48 : ${OVSDB_SERVER_SYSLOG_LOGLEVEL:=ERR}
49 : ${OVSDB_SERVER_MEMLEAK_LOGFILE:=}
50 : ${OVSDB_SERVER_STRACE_LOG:=}
51 : ${OVSDB_SERVER_STRACE_OPT:=}
52 : ${OVSDB_SERVER_VALGRIND_LOG:=}
53 : ${OVSDB_SERVER_VALGRIND_OPT:=}
55 # Config variables specific to ovs-vswitchd
56 : ${VSWITCHD_OVSDB_SERVER:=unix:/var/run/openvswitch/db.sock}
57 : ${VSWITCHD_OVSDB_SCHEMA:=/usr/share/openvswitch/vswitch.ovsschema}
58 : ${VSWITCHD_PIDFILE:=/var/run/openvswitch/ovs-vswitchd.pid}
59 : ${VSWITCHD_RUN_DIR:=/var/xen/openvswitch}
60 : ${VSWITCHD_PRIORITY:=-10}
61 : ${VSWITCHD_MLOCKALL:=yes}
62 : ${VSWITCHD_LOGFILE:=/var/log/openvswitch/ovs-vswitchd.log}
63 : ${VSWITCHD_FILE_LOGLEVEL:=INFO}
64 : ${VSWITCHD_SYSLOG_LOGLEVEL:=ERR}
65 : ${VSWITCHD_MEMLEAK_LOGFILE:=}
66 : ${VSWITCHD_STRACE_LOG:=}
67 : ${VSWITCHD_STRACE_OPT:=}
68 : ${VSWITCHD_VALGRIND_LOG:=}
69 : ${VSWITCHD_VALGRIND_OPT:=}
71 # Config variables specific to ovs-brcompatd
72 : ${BRCOMPATD_PIDFILE:=/var/run/openvswitch/ovs-brcompatd.pid}
73 : ${BRCOMPATD_RUN_DIR:=/var/xen/openvswitch}
74 : ${BRCOMPATD_PRIORITY:=-10}
75 : ${BRCOMPATD_LOGFILE:=/var/log/openvswitch/ovs-brcompatd.log}
76 : ${BRCOMPATD_FILE_LOGLEVEL:=INFO}
77 : ${BRCOMPATD_SYSLOG_LOGLEVEL:=ERR}
78 : ${BRCOMPATD_MEMLEAK_LOGFILE:=}
79 : ${BRCOMPATD_STRACE_LOG:=}
80 : ${BRCOMPATD_STRACE_OPT:=}
81 : ${BRCOMPATD_VALGRIND_LOG:=}
82 : ${BRCOMPATD_VALGRIND_OPT:=}
84 # Full paths to executables & modules
85 ovsdb_server="/usr/sbin/ovsdb-server"
86 ovsdb_tool="/usr/bin/ovsdb-tool"
87 vswitchd="/usr/sbin/ovs-vswitchd"
88 brcompatd="/usr/sbin/ovs-brcompatd"
89 dpctl="/usr/bin/ovs-dpctl"
90 appctl="/usr/bin/ovs-appctl"
91 ofctl="/usr/bin/ovs-ofctl"
92 vsctl="/usr/bin/ovs-vsctl"
94 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
95 if [ "$ENABLE_BRCOMPAT" != "y" ]; then
96 warning "FAKE_PROC_NET required BRCOMPAT which was disabled. Force enabling."
101 if test "$ENABLE_MONITOR" = "y"; then
102 monitor_opt="--monitor"
108 "$dpctl" show | grep '^dp[0-9]\+:' | cut -d':' -f 1
111 function turn_on_corefiles {
115 function remove_all_dp {
116 for dp in $(dp_list); do
117 action "Removing datapath: $dp" "$dpctl" del-dp "$dp"
121 function insert_modules_if_required {
122 if ! lsmod | grep -q "openvswitch_mod"; then
123 action "Inserting llc module" modprobe llc
124 action "Inserting openvswitch module" modprobe openvswitch_mod
126 if [ "$ENABLE_BRCOMPAT" = "y" ] && [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
127 action "Inserting brcompat module" modprobe brcompat_mod
129 if [ -f "/lib/modules/`uname -r`/kernel/extra/openvswitch/veth_mod.ko" ] && ! lsmod | grep -q "veth_mod"; then
130 action "Inserting veth module" modprobe veth_mod
132 if [ -f "/lib/modules/`uname -r`/kernel/extra/openvswitch/ip_gre_mod.ko" ] && ! lsmod | grep -q "ip_gre_mod"; then
133 action "Inserting ip_gre module" modprobe ip_gre_mod
137 function remove_modules {
138 if lsmod | grep -q "brcompat_mod"; then
139 action "Removing brcompat module" rmmod brcompat_mod.ko
141 if lsmod | grep -q "openvswitch_mod"; then
142 action "Removing openvswitch module" rmmod openvswitch_mod.ko
144 if lsmod | grep -q "ip_gre_mod"; then
145 action "Removing ip_gre module" rmmod ip_gre_mod.ko
149 function start_ovsdb_server {
150 local syslog_opt="-vANY:SYSLOG:${OVSDB_SERVER_SYSLOG_LOGLEVEL}"
151 local logfile_file_opt=""
152 local logfile_level_opt=""
153 if [ ! -d "$OVSDB_SERVER_RUN_DIR" ]; then
154 install -d -m 755 -o root -g root "$OVSDB_SERVER_RUN_DIR"
156 cd "$OVSDB_SERVER_RUN_DIR"
158 for remote in $OVSDB_SERVER_REMOTES; do
159 remotes="$remotes --remote=$remote"
162 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_LOGFILE`
163 if [ -n "$OVSDB_SERVER_FILE_LOGLEVEL" ]; then
164 logfile_level_opt="-vANY:FILE:${OVSDB_SERVER_FILE_LOGLEVEL}"
165 logfile_file_opt="--log-file=$OVSDB_SERVER_LOGFILE"
169 if [ -n "$OVSDB_SERVER_MEMLEAK_LOGFILE" ]; then
170 leak_opt="--check-leaks=$OVSDB_SERVER_MEMLEAK_LOGFILE"
171 if [ -e "$OVSDB_SERVER_MEMLEAK_LOGFILE" ]; then
172 mv "$OVSDB_SERVER_MEMLEAK_LOGFILE" "$OVSDB_SERVER_MEMLEAK_LOGFILE.prev"
177 if [ -n "$OVSDB_SERVER_STRACE_LOG" ] && [ -n "$OVSDB_SERVER_VALGRIND_LOG" ]; then
178 printf "Can not start with both VALGRIND and STRACE\n"
181 if [ -n "$OVSDB_SERVER_STRACE_LOG" ]; then
182 strace_opt="strace -o $OVSDB_SERVER_STRACE_LOG $OVSDB_SERVER_STRACE_OPT"
185 if [ -n "$OVSDB_SERVER_VALGRIND_LOG" ]; then
186 valgrind_opt="valgrind --log-file=$OVSDB_SERVER_VALGRIND_LOG $OVSDB_SERVER_VALGRIND_OPT"
189 ssl_opts="--private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert"
190 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_PIDFILE`
191 if [ "$daemonize" != "y" ]; then
192 # Start in background and force a "success" message
193 action "Starting ovsdb_server ($strace_opt$valgrind_opt)" true
194 (nice -n "$OVSDB_SERVER_PRIORITY" $strace_opt $valgrind_opt "$ovsdb_server" "$OVSDB_SERVER_DB" --pidfile="$OVSDB_SERVER_PIDFILE" --detach $monitor_opt --no-chdir -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt $remotes $ssl_opts) &
196 action "Starting ovsdb-server" nice -n "$OVSDB_SERVER_PRIORITY" "$ovsdb_server" "$OVSDB_SERVER_DB" --pidfile="$OVSDB_SERVER_PIDFILE" --detach $monitor_opt --no-chdir -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt $remotes $ssl_opts
200 function start_vswitchd {
201 local syslog_opt="-vANY:SYSLOG:${VSWITCHD_SYSLOG_LOGLEVEL}"
202 local logfile_file_opt=""
203 local logfile_level_opt=""
204 if [ ! -d "$VSWITCHD_RUN_DIR" ]; then
205 install -d -m 755 -o root -g root "$VSWITCHD_RUN_DIR"
207 cd "$VSWITCHD_RUN_DIR"
209 install -d -m 755 -o root -g root `dirname $VSWITCHD_LOGFILE`
210 if [ -n "$VSWITCHD_FILE_LOGLEVEL" ]; then
211 logfile_level_opt="-vANY:FILE:${VSWITCHD_FILE_LOGLEVEL}"
212 logfile_file_opt="--log-file=$VSWITCHD_LOGFILE"
216 if [ -n "$VSWITCHD_MEMLEAK_LOGFILE" ]; then
217 leak_opt="--check-leaks=$VSWITCHD_MEMLEAK_LOGFILE"
218 if [ -e "$VSWITCHD_MEMLEAK_LOGFILE" ]; then
219 mv "$VSWITCHD_MEMLEAK_LOGFILE" "$VSWITCHD_MEMLEAK_LOGFILE.prev"
224 if [ -n "$VSWITCHD_STRACE_LOG" ] && [ -n "$VSWITCHD_VALGRIND_LOG" ]; then
225 printf "Can not start with both VALGRIND and STRACE\n"
228 if [ -n "$VSWITCHD_STRACE_LOG" ]; then
229 strace_opt="strace -o $VSWITCHD_STRACE_LOG $VSWITCHD_STRACE_OPT"
232 if [ -n "$VSWITCHD_VALGRIND_LOG" ]; then
233 valgrind_opt="valgrind --log-file=$VSWITCHD_VALGRIND_LOG $VSWITCHD_VALGRIND_OPT"
236 local fake_proc_net_opt=""
237 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
238 fake_proc_net_opt="--fake-proc-net"
240 if [ "$VSWITCHD_MLOCKALL" != "no" ]; then
241 mlockall_opt="--mlockall"
244 install -d -m 755 -o root -g root `dirname $VSWITCHD_PIDFILE`
245 if [ "$daemonize" != "y" ]; then
246 # Start in background and force a "success" message
247 action "Starting ovs-vswitchd ($strace_opt$valgrind_opt)" true
248 (nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt "$vswitchd" --pidfile="$VSWITCHD_PIDFILE" --detach $monitor_opt --no-chdir $fake_proc_net_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt $mlockall_opt "$VSWITCHD_OVSDB_SERVER") &
250 action "Starting ovs-vswitchd" nice -n "$VSWITCHD_PRIORITY" "$vswitchd" --pidfile="$VSWITCHD_PIDFILE" --detach $monitor_opt --no-chdir $fake_proc_net_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt $mlockall_opt "$VSWITCHD_OVSDB_SERVER"
254 function start_brcompatd {
255 local syslog_opt="-vANY:SYSLOG:${BRCOMPATD_SYSLOG_LOGLEVEL}"
256 local logfile_file_opt=""
257 local logfile_level_opt=""
258 if [ -d "$BRCOMPATD_RUN_DIR" ]; then
259 install -d -m 755 -o root -g root "$BRCOMPATD_RUN_DIR"
261 cd "$BRCOMPATD_RUN_DIR"
263 install -d -m 755 -o root -g root `dirname $BRCOMPATD_LOGFILE`
264 if [ -n "$BRCOMPATD_FILE_LOGLEVEL" ]; then
265 logfile_level_opt="-vANY:FILE:${BRCOMPATD_FILE_LOGLEVEL}"
266 logfile_file_opt="--log-file=$BRCOMPATD_LOGFILE"
270 if [ -n "$BRCOMPATD_MEMLEAK_LOGFILE" ]; then
271 leak_opt="--check-leaks=$BRCOMPATD_MEMLEAK_LOGFILE"
272 if [ -e "$BRCOMPATD_MEMLEAK_LOGFILE" ]; then
273 mv "$BRCOMPATD_MEMLEAK_LOGFILE" "$BRCOMPATD_MEMLEAK_LOGFILE.prev"
278 if [ -n "$BRCOMPATD_STRACE_LOG" ] && [ -n "$BRCOMPATD_VALGRIND_LOG" ]; then
279 printf "Can not start with both VALGRIND and STRACE\n"
282 if [ -n "$BRCOMPATD_STRACE_LOG" ]; then
283 strace_opt="strace -o $BRCOMPATD_STRACE_LOG $BRCOMPATD_STRACE_OPT"
286 if [ -n "$VALGRIND_LOG" ]; then
287 valgrind_opt="valgrind --log-file=$BRCOMPATD_VALGRIND_LOG $BRCOMPATD_VALGRIND_OPT"
290 appctl_cmd="$appctl --target=/var/run/openvswitch/ovs-vswitchd.\`cat $VSWITCHD_PIDFILE\`.ctl %s"
292 install -d -m 755 -o root -g root `dirname $BRCOMPATD_PIDFILE`
293 if [ "$daemonize" != "y" ]; then
294 # Start in background and force a "success" message
295 action "Starting ovs-brcompatd ($strace_opt$valgrind_opt)" true
296 (nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt "$brcompatd"--no-chdir --appctl-command="$appctl_cmd" --pidfile=$BRCOMPATD_PIDFILE -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_OVSDB_SERVER") &
298 action "Starting ovs-brcompatd" nice -n "$BRCOMPATD_PRIORITY" $strace_opt $valgrind_opt "$brcompatd" --no-chdir --appctl-command="$appctl_cmd" --pidfile=$BRCOMPATD_PIDFILE --detach $monitor_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_OVSDB_SERVER"
302 function stop_ovsdb_server {
303 if [ -f "$OVSDB_SERVER_PIDFILE" ]; then
304 local pid=$(cat "$OVSDB_SERVER_PIDFILE")
305 action "Killing ovsdb-server ($pid)" kill -TERM $pid
306 rm -f "$OVSDB_SERVER_PIDFILE"
310 function stop_vswitchd {
311 if [ -f "$VSWITCHD_PIDFILE" ]; then
312 local pid=$(cat "$VSWITCHD_PIDFILE")
313 action "Killing ovs-vswitchd ($pid)" kill -TERM $pid
314 rm -f "$VSWITCHD_PIDFILE"
318 function stop_brcompatd {
319 if [ -f "$BRCOMPATD_PIDFILE" ]; then
320 local pid=$(cat "$BRCOMPATD_PIDFILE")
321 action "Killing ovs-brcompatd ($pid)" kill -TERM $pid
322 rm -f "$BRCOMPATD_PIDFILE"
326 function restart_approval {
328 # Don't prompt if invoked non-interactively.
335 Restarting Open vSwitch on a live server is not guaranteed to work. It is
336 provided as a convenience for those situations in which it does work.
339 read -s -r -n 1 -p "Countinue with restart (y/N): " response
351 function set_system_uuid {
352 if test -n "$INSTALLATION_UUID"; then
353 action "Configuring Open vSwitch system UUID" true
354 $vsctl --no-wait set Open_vSwitch . external-ids:system-uuid="$INSTALLATION_UUID"
356 action "Configuring Open vSwitch system UUID" false
361 if [ "$FORCE_COREFILES" = "y" ]; then
365 insert_modules_if_required
367 # Increase the limit on the number of open file descriptors since
368 # ovs-vswitchd needs a few per bridge
372 iptables -I INPUT -p gre -j ACCEPT
374 if [ ! -e "$OVSDB_SERVER_DB" ]; then
375 warning "$OVSDB_SERVER_DB does not exist"
376 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_DB`
378 action "Creating empty database $OVSDB_SERVER_DB" true
379 $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
381 # Upgrade or downgrade schema and compact database.
382 $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
386 $vsctl --no-wait init
387 if [ ! -e /var/run/openvswitch.booted ]; then
388 touch /var/run/openvswitch.booted
389 for bridge in $($vsctl list-br); do
390 $vsctl --no-wait del-br $bridge
397 if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then
400 touch /var/lock/subsys/openvswitch
407 rm -f /var/lock/subsys/openvswitch
411 if restart_approval; then
429 strace -p $(cat "$VSWITCHD_PIDFILE") "$@"
433 strace -p $(cat "$BRCOMPATD_PIDFILE") "$@"
436 status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server &&
437 status -p "$VSWITCHD_PIDFILE" ovs-vswitchd &&
438 (test "$ENABLE_BRCOMPAT" != "y" ||
439 status -p "$BRCOMPATD_PIDFILE" ovs-brcompatd)
442 /usr/sbin/ovsdb-server -V
443 /usr/sbin/ovs-vswitchd -V
444 /usr/sbin/ovs-brcompatd -V
447 printf "openvswitch [start|stop|restart|unload|status|version]\n"
450 printf "Unknown command: $1\n"