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
134 function remove_modules {
135 if lsmod | grep -q "brcompat_mod"; then
136 action "Removing brcompat module" rmmod brcompat_mod.ko
138 if lsmod | grep -q "openvswitch_mod"; then
139 action "Removing openvswitch module" rmmod openvswitch_mod.ko
143 function start_ovsdb_server {
144 local syslog_opt="-vANY:SYSLOG:${OVSDB_SERVER_SYSLOG_LOGLEVEL}"
145 local logfile_file_opt=""
146 local logfile_level_opt=""
147 if [ ! -d "$OVSDB_SERVER_RUN_DIR" ]; then
148 install -d -m 755 -o root -g root "$OVSDB_SERVER_RUN_DIR"
150 cd "$OVSDB_SERVER_RUN_DIR"
152 for remote in $OVSDB_SERVER_REMOTES; do
153 remotes="$remotes --remote=$remote"
156 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_LOGFILE`
157 if [ -n "$OVSDB_SERVER_FILE_LOGLEVEL" ]; then
158 logfile_level_opt="-vANY:FILE:${OVSDB_SERVER_FILE_LOGLEVEL}"
159 logfile_file_opt="--log-file=$OVSDB_SERVER_LOGFILE"
163 if [ -n "$OVSDB_SERVER_MEMLEAK_LOGFILE" ]; then
164 leak_opt="--check-leaks=$OVSDB_SERVER_MEMLEAK_LOGFILE"
165 if [ -e "$OVSDB_SERVER_MEMLEAK_LOGFILE" ]; then
166 mv "$OVSDB_SERVER_MEMLEAK_LOGFILE" "$OVSDB_SERVER_MEMLEAK_LOGFILE.prev"
171 if [ -n "$OVSDB_SERVER_STRACE_LOG" ] && [ -n "$OVSDB_SERVER_VALGRIND_LOG" ]; then
172 printf "Can not start with both VALGRIND and STRACE\n"
175 if [ -n "$OVSDB_SERVER_STRACE_LOG" ]; then
176 strace_opt="strace -o $OVSDB_SERVER_STRACE_LOG $OVSDB_SERVER_STRACE_OPT"
179 if [ -n "$OVSDB_SERVER_VALGRIND_LOG" ]; then
180 valgrind_opt="valgrind --log-file=$OVSDB_SERVER_VALGRIND_LOG $OVSDB_SERVER_VALGRIND_OPT"
183 ssl_opts="--private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert"
184 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_PIDFILE`
185 if [ "$daemonize" != "y" ]; then
186 # Start in background and force a "success" message
187 action "Starting ovsdb_server ($strace_opt$valgrind_opt)" true
188 (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) &
190 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
194 function start_vswitchd {
195 local syslog_opt="-vANY:SYSLOG:${VSWITCHD_SYSLOG_LOGLEVEL}"
196 local logfile_file_opt=""
197 local logfile_level_opt=""
198 if [ ! -d "$VSWITCHD_RUN_DIR" ]; then
199 install -d -m 755 -o root -g root "$VSWITCHD_RUN_DIR"
201 cd "$VSWITCHD_RUN_DIR"
203 install -d -m 755 -o root -g root `dirname $VSWITCHD_LOGFILE`
204 if [ -n "$VSWITCHD_FILE_LOGLEVEL" ]; then
205 logfile_level_opt="-vANY:FILE:${VSWITCHD_FILE_LOGLEVEL}"
206 logfile_file_opt="--log-file=$VSWITCHD_LOGFILE"
210 if [ -n "$VSWITCHD_MEMLEAK_LOGFILE" ]; then
211 leak_opt="--check-leaks=$VSWITCHD_MEMLEAK_LOGFILE"
212 if [ -e "$VSWITCHD_MEMLEAK_LOGFILE" ]; then
213 mv "$VSWITCHD_MEMLEAK_LOGFILE" "$VSWITCHD_MEMLEAK_LOGFILE.prev"
218 if [ -n "$VSWITCHD_STRACE_LOG" ] && [ -n "$VSWITCHD_VALGRIND_LOG" ]; then
219 printf "Can not start with both VALGRIND and STRACE\n"
222 if [ -n "$VSWITCHD_STRACE_LOG" ]; then
223 strace_opt="strace -o $VSWITCHD_STRACE_LOG $VSWITCHD_STRACE_OPT"
226 if [ -n "$VSWITCHD_VALGRIND_LOG" ]; then
227 valgrind_opt="valgrind --log-file=$VSWITCHD_VALGRIND_LOG $VSWITCHD_VALGRIND_OPT"
230 local fake_proc_net_opt=""
231 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
232 fake_proc_net_opt="--fake-proc-net"
234 if [ "$VSWITCHD_MLOCKALL" != "no" ]; then
235 mlockall_opt="--mlockall"
238 install -d -m 755 -o root -g root `dirname $VSWITCHD_PIDFILE`
239 if [ "$daemonize" != "y" ]; then
240 # Start in background and force a "success" message
241 action "Starting ovs-vswitchd ($strace_opt$valgrind_opt)" true
242 (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") &
244 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"
248 function start_brcompatd {
249 local syslog_opt="-vANY:SYSLOG:${BRCOMPATD_SYSLOG_LOGLEVEL}"
250 local logfile_file_opt=""
251 local logfile_level_opt=""
252 if [ -d "$BRCOMPATD_RUN_DIR" ]; then
253 install -d -m 755 -o root -g root "$BRCOMPATD_RUN_DIR"
255 cd "$BRCOMPATD_RUN_DIR"
257 install -d -m 755 -o root -g root `dirname $BRCOMPATD_LOGFILE`
258 if [ -n "$BRCOMPATD_FILE_LOGLEVEL" ]; then
259 logfile_level_opt="-vANY:FILE:${BRCOMPATD_FILE_LOGLEVEL}"
260 logfile_file_opt="--log-file=$BRCOMPATD_LOGFILE"
264 if [ -n "$BRCOMPATD_MEMLEAK_LOGFILE" ]; then
265 leak_opt="--check-leaks=$BRCOMPATD_MEMLEAK_LOGFILE"
266 if [ -e "$BRCOMPATD_MEMLEAK_LOGFILE" ]; then
267 mv "$BRCOMPATD_MEMLEAK_LOGFILE" "$BRCOMPATD_MEMLEAK_LOGFILE.prev"
272 if [ -n "$BRCOMPATD_STRACE_LOG" ] && [ -n "$BRCOMPATD_VALGRIND_LOG" ]; then
273 printf "Can not start with both VALGRIND and STRACE\n"
276 if [ -n "$BRCOMPATD_STRACE_LOG" ]; then
277 strace_opt="strace -o $BRCOMPATD_STRACE_LOG $BRCOMPATD_STRACE_OPT"
280 if [ -n "$VALGRIND_LOG" ]; then
281 valgrind_opt="valgrind --log-file=$BRCOMPATD_VALGRIND_LOG $BRCOMPATD_VALGRIND_OPT"
284 appctl_cmd="$appctl --target=/var/run/openvswitch/ovs-vswitchd.\`cat $VSWITCHD_PIDFILE\`.ctl %s"
286 install -d -m 755 -o root -g root `dirname $BRCOMPATD_PIDFILE`
287 if [ "$daemonize" != "y" ]; then
288 # Start in background and force a "success" message
289 action "Starting ovs-brcompatd ($strace_opt$valgrind_opt)" true
290 (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") &
292 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"
296 function stop_ovsdb_server {
297 if [ -f "$OVSDB_SERVER_PIDFILE" ]; then
298 local pid=$(cat "$OVSDB_SERVER_PIDFILE")
299 action "Killing ovsdb-server ($pid)" kill -TERM $pid
300 rm -f "$OVSDB_SERVER_PIDFILE"
304 function stop_vswitchd {
305 if [ -f "$VSWITCHD_PIDFILE" ]; then
306 local pid=$(cat "$VSWITCHD_PIDFILE")
307 action "Killing ovs-vswitchd ($pid)" kill -TERM $pid
308 rm -f "$VSWITCHD_PIDFILE"
312 function stop_brcompatd {
313 if [ -f "$BRCOMPATD_PIDFILE" ]; then
314 local pid=$(cat "$BRCOMPATD_PIDFILE")
315 action "Killing ovs-brcompatd ($pid)" kill -TERM $pid
316 rm -f "$BRCOMPATD_PIDFILE"
320 function restart_approval {
322 # Don't prompt if invoked non-interactively.
329 Restarting Open vSwitch on a live server is not guaranteed to work. It is
330 provided as a convenience for those situations in which it does work.
333 read -s -r -n 1 -p "Countinue with restart (y/N): " response
345 function set_system_uuid {
346 if test -n "$INSTALLATION_UUID"; then
347 action "Configuring Open vSwitch system UUID" true
348 $vsctl --no-wait set Open_vSwitch . external-ids:system-uuid="$INSTALLATION_UUID"
350 action "Configuring Open vSwitch system UUID" false
355 if [ "$FORCE_COREFILES" = "y" ]; then
359 insert_modules_if_required
361 # Increase the limit on the number of open file descriptors since
362 # ovs-vswitchd needs a few per bridge
366 iptables -I INPUT -p gre -j ACCEPT
368 if [ ! -e "$OVSDB_SERVER_DB" ]; then
369 warning "$OVSDB_SERVER_DB does not exist"
370 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_DB`
372 action "Creating empty database $OVSDB_SERVER_DB" true
373 $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
375 # Upgrade or downgrade schema and compact database.
376 $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
380 $vsctl --no-wait init
381 if [ ! -e /var/run/openvswitch.booted ]; then
382 touch /var/run/openvswitch.booted
383 for bridge in $($vsctl list-br); do
384 $vsctl --no-wait del-br $bridge
391 if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then
394 touch /var/lock/subsys/openvswitch
401 rm -f /var/lock/subsys/openvswitch
405 if restart_approval; then
423 strace -p $(cat "$VSWITCHD_PIDFILE") "$@"
427 strace -p $(cat "$BRCOMPATD_PIDFILE") "$@"
430 status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server &&
431 status -p "$VSWITCHD_PIDFILE" ovs-vswitchd &&
432 (test "$ENABLE_BRCOMPAT" != "y" ||
433 status -p "$BRCOMPATD_PIDFILE" ovs-brcompatd)
436 /usr/sbin/ovsdb-server -V
437 /usr/sbin/ovs-vswitchd -V
438 /usr/sbin/ovs-brcompatd -V
441 printf "openvswitch [start|stop|restart|unload|status|version]\n"
444 printf "Unknown command: $1\n"