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 NETWORK_MODE=$(cat /etc/xensource/network.conf)
28 if test "$NETWORK_MODE" = bridge; then
29 echo "Open vSwitch disabled (/etc/xensource/network.conf is 'bridge')" >&2
33 # General config variables in /etc/sysconfig/openvswitch
34 if test "$PRODUCT_VERSION" = "5.5.0"; then
35 # XenServer 5.5.0 needs ovs-brcompatd and /proc/net simulation.
36 : ${ENABLE_BRCOMPAT:=y}
37 : ${ENABLE_FAKE_PROC_NET:=y}
39 # Later versions don't need them.
40 : ${ENABLE_BRCOMPAT:=n}
41 : ${ENABLE_FAKE_PROC_NET:=n}
43 : ${ENABLE_MONITOR:=y}
44 : ${FORCE_COREFILES:=y}
46 # Config variables specific to ovsdb-server
47 : ${OVSDB_SERVER_REMOTES:=punix:/var/run/openvswitch/db.sock db:Open_vSwitch,managers}
48 : ${OVSDB_SERVER_DB:=/etc/openvswitch/conf.db}
49 : ${OVSDB_SERVER_PIDFILE:=/var/run/openvswitch/ovsdb-server.pid}
50 : ${OVSDB_SERVER_RUN_DIR:=/var/xen/openvswitch}
51 : ${OVSDB_SERVER_PRIORITY:=-10}
52 : ${OVSDB_SERVER_LOGFILE:=/var/log/openvswitch/ovsdb-server.log}
53 : ${OVSDB_SERVER_FILE_LOGLEVEL:=INFO}
54 : ${OVSDB_SERVER_SYSLOG_LOGLEVEL:=ERR}
55 : ${OVSDB_SERVER_MEMLEAK_LOGFILE:=}
56 : ${OVSDB_SERVER_STRACE_LOG:=}
57 : ${OVSDB_SERVER_STRACE_OPT:=}
58 : ${OVSDB_SERVER_VALGRIND_LOG:=}
59 : ${OVSDB_SERVER_VALGRIND_OPT:=}
61 # Config variables specific to ovs-vswitchd
62 : ${VSWITCHD_OVSDB_SERVER:=unix:/var/run/openvswitch/db.sock}
63 : ${VSWITCHD_OVSDB_SCHEMA:=/usr/share/openvswitch/vswitch.ovsschema}
64 : ${VSWITCHD_PIDFILE:=/var/run/openvswitch/ovs-vswitchd.pid}
65 : ${VSWITCHD_RUN_DIR:=/var/xen/openvswitch}
66 : ${VSWITCHD_PRIORITY:=-10}
67 : ${VSWITCHD_MLOCKALL:=yes}
68 : ${VSWITCHD_LOGFILE:=/var/log/openvswitch/ovs-vswitchd.log}
69 : ${VSWITCHD_FILE_LOGLEVEL:=INFO}
70 : ${VSWITCHD_SYSLOG_LOGLEVEL:=ERR}
71 : ${VSWITCHD_MEMLEAK_LOGFILE:=}
72 : ${VSWITCHD_STRACE_LOG:=}
73 : ${VSWITCHD_STRACE_OPT:=}
74 : ${VSWITCHD_VALGRIND_LOG:=}
75 : ${VSWITCHD_VALGRIND_OPT:=}
77 # Config variables specific to ovs-brcompatd
78 : ${BRCOMPATD_PIDFILE:=/var/run/openvswitch/ovs-brcompatd.pid}
79 : ${BRCOMPATD_RUN_DIR:=/var/xen/openvswitch}
80 : ${BRCOMPATD_PRIORITY:=-10}
81 : ${BRCOMPATD_LOGFILE:=/var/log/openvswitch/ovs-brcompatd.log}
82 : ${BRCOMPATD_FILE_LOGLEVEL:=INFO}
83 : ${BRCOMPATD_SYSLOG_LOGLEVEL:=ERR}
84 : ${BRCOMPATD_MEMLEAK_LOGFILE:=}
85 : ${BRCOMPATD_STRACE_LOG:=}
86 : ${BRCOMPATD_STRACE_OPT:=}
87 : ${BRCOMPATD_VALGRIND_LOG:=}
88 : ${BRCOMPATD_VALGRIND_OPT:=}
90 # Config variables specific to ovs-xenserverd
91 : ${XENSERVERD_PIDFILE:=/var/run/openvswitch/ovs-xenserverd.pid}
92 : ${XENSERVERD_RUN_DIR:=/var/xen/openvswitch}
93 : ${XENSERVERD_PRIORITY:=}
94 : ${XENSERVERD_LOGFILE:=}
95 : ${XENSERVERD_FILE_LOGLEVEL:=}
96 : ${XENSERVERD_SYSLOG_LOGLEVEL:=}
97 : ${XENSERVERD_MEMLEAK_LOGFILE:=}
98 : ${XENSERVERD_STRACE_LOG:=}
99 : ${XENSERVERD_STRACE_OPT:=}
100 : ${XENSERVERD_VALGRIND_LOG:=}
101 : ${XENSERVERD_VALGRIND_OPT:=}
103 # Full paths to executables & modules
104 ovsdb_server="/usr/sbin/ovsdb-server"
105 ovsdb_tool="/usr/bin/ovsdb-tool"
106 vswitchd="/usr/sbin/ovs-vswitchd"
107 brcompatd="/usr/sbin/ovs-brcompatd"
108 xenserverd="/usr/sbin/ovs-xenserverd"
109 dpctl="/usr/bin/ovs-dpctl"
110 appctl="/usr/bin/ovs-appctl"
111 ofctl="/usr/bin/ovs-ofctl"
112 vsctl="/usr/bin/ovs-vsctl"
114 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
115 if [ "$ENABLE_BRCOMPAT" != "y" ]; then
116 warning "FAKE_PROC_NET required BRCOMPAT which was disabled. Force enabling."
121 if test "$ENABLE_MONITOR" = "y"; then
122 monitor_opt="--monitor"
128 "$dpctl" show | grep '^dp[0-9]\+:' | cut -d':' -f 1
131 function turn_on_corefiles {
135 function remove_all_dp {
136 for dp in $(dp_list); do
137 action "Removing datapath: $dp" "$dpctl" del-dp "$dp"
141 function insert_modules_if_required {
142 if ! lsmod | grep -q "openvswitch_mod"; then
143 action "Inserting llc module" modprobe llc
144 action "Inserting openvswitch module" modprobe openvswitch_mod
146 if [ "$ENABLE_BRCOMPAT" = "y" ] && [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
147 action "Inserting brcompat module" modprobe brcompat_mod
149 if [ -f "/lib/modules/`uname -r`/kernel/extra/openvswitch/veth_mod.ko" ] && ! lsmod | grep -q "veth_mod"; then
150 action "Inserting veth module" modprobe veth_mod
154 function remove_modules {
155 if lsmod | grep -q "brcompat_mod"; then
156 action "Removing brcompat module" rmmod brcompat_mod.ko
158 if lsmod | grep -q "openvswitch_mod"; then
159 action "Removing openvswitch module" rmmod openvswitch_mod.ko
163 function start_daemon {
168 # cd to daemon's run_dir so core files get dumped into a sensible place.
169 eval local run_dir=\$${DAEMON}_RUN_DIR
170 if [ ! -d "$run_dir" ]; then
171 install -d -m 755 -o root -g root "$run_dir"
175 # Configure log levels.
176 eval local syslog_loglevel=\$${DAEMON}_SYSLOG_LOGLEVEL
177 eval local file_loglevel=\$${DAEMON}_FILE_LOGLEVEL
178 eval local logfile=\$${DAEMON}_LOGFILE
179 set -- "$@" -vANY:CONSOLE:EMER -vANY:SYSLOG:"$syslog_loglevel"
180 if test -n "$file_loglevel" && test -n "$logfile"; then
181 install -d -m 755 -o root -g root `dirname "$logfile"`
182 set -- "$@" --log-file="$logfile" -vANY:FILE:"$file_loglevel"
185 # Configure leak checker.
186 eval local memleak_logfile=\$${DAEMON}_MEMLEAK_LOGFILE
187 if test -n "$memleak_logfile"; then
188 set -- "$@" --check-leaks="$memleak_logfile"
189 if test -e "$memleak_logfile"; then
190 mv "$memleak_logfile" "$memleak_logfile.prev"
194 # Configure debugging wrappers.
195 eval local strace_log=\$${DAEMON}_STRACE_LOG
196 eval local strace_opt=\$${DAEMON}_STRACE_OPT
197 eval local valgrind_log=\$${DAEMON}_VALGRIND_LOG
198 eval local valgrind_opt=\$${DAEMON}_VALGRIND_OPT
199 if test -n "$strace_log" && test -n "$valgrind_log"; then
200 printf "Can not start with both VALGRIND and STRACE\n"
202 elif test -n "$strace_log"; then
204 set -- strace -o "$strace_log" $strace_opt "$@"
205 elif test -n "$valgrind_log"; then
207 set -- valgrind --log-file="$valgrind_log" $valgrind_opt "$@"
209 local mode=production
210 eval local pidfile=\$${DAEMON}_PIDFILE
211 install -d -m 755 -o root -g root `dirname $pidfile`
212 set -- "$@" --pidfile="$pidfile" --detach $monitor_opt --no-chdir
215 # Configure niceness.
216 eval local priority=\$${DAEMON}_PRIORITY
217 if test -n "$priority"; then
218 set -- nice -n $priority "$@"
221 if test $mode = production; then
222 action "Starting `basename $BINARY`" "$@"
224 # Start in background and force a "success" message
225 action "Starting `basename $BINARY` with $mode debugging" true
230 function start_ovsdb_server {
231 set -- "$ovsdb_server" "$OVSDB_SERVER_DB"
232 for remote in $OVSDB_SERVER_REMOTES; do
233 set -- "$@" --remote="$remote"
235 set -- "$@" --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert
236 start_daemon OVSDB_SERVER "$@"
239 function start_vswitchd {
240 local fake_proc_net_opt=
241 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
242 fake_proc_net_opt="--fake-proc-net"
246 if [ "$VSWITCHD_MLOCKALL" != "no" ]; then
247 mlockall_opt="--mlockall"
250 start_daemon VSWITCHD "$vswitchd" $fake_proc_net_opt $mlockall_opt \
251 "$VSWITCHD_OVSDB_SERVER"
254 function start_brcompatd {
255 start_daemon BRCOMPATD "$brcompatd" \
256 --appctl-command="$appctl --target=/var/run/openvswitch/ovs-vswitchd.\`cat $VSWITCHD_PIDFILE\`.ctl %s" \
257 "$VSWITCHD_OVSDB_SERVER"
260 function start_xenserverd {
261 start_daemon XENSERVERD "$xenserverd"
264 function stop_daemon {
267 eval local pidfile=\$${DAEMON}_PIDFILE
268 if test -f "$pidfile"; then
269 local pid=$(cat "$pidfile")
270 action "Killing `basename $BINARY` ($pid)" kill $pid
275 function restart_approval {
277 # Don't prompt if invoked non-interactively.
284 Restarting Open vSwitch on a live server is not guaranteed to work. It is
285 provided as a convenience for those situations in which it does work.
288 read -s -r -n 1 -p "Continue with restart (y/N): " response
300 function set_system_uuid {
301 if test -n "$INSTALLATION_UUID"; then
302 action "Configuring Open vSwitch system UUID" true
303 $vsctl --no-wait set Open_vSwitch . external-ids:system-uuid="$INSTALLATION_UUID"
305 action "Configuring Open vSwitch system UUID" false
310 if [ "$FORCE_COREFILES" = "y" ]; then
314 insert_modules_if_required
316 # Increase the limit on the number of open file descriptors since
317 # ovs-vswitchd needs a few per bridge
321 iptables -I INPUT -p gre -j ACCEPT
323 if [ ! -e "$OVSDB_SERVER_DB" ]; then
324 warning "$OVSDB_SERVER_DB does not exist"
325 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_DB`
327 action "Creating empty database $OVSDB_SERVER_DB" true
328 $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
330 # Upgrade or downgrade schema and compact database.
331 $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
335 $vsctl --no-wait init
336 if [ ! -e /var/run/openvswitch.booted ]; then
337 touch /var/run/openvswitch.booted
338 for bridge in $($vsctl list-br); do
339 $vsctl --no-wait del-br $bridge
346 if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then
350 touch /var/lock/subsys/openvswitch
354 stop_daemon XENSERVERD "$xenserverd"
355 stop_daemon BRCOMPATD "$brcompatd"
356 stop_daemon VSWITCHD "$vswitchd"
357 stop_daemon OVSDB_SERVER "$ovsdb_server"
358 rm -f /var/lock/subsys/openvswitch
362 if restart_approval; then
380 strace -p $(cat "$VSWITCHD_PIDFILE") "$@"
384 strace -p $(cat "$BRCOMPATD_PIDFILE") "$@"
387 status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server &&
388 status -p "$VSWITCHD_PIDFILE" ovs-vswitchd &&
389 (test "$ENABLE_BRCOMPAT" != "y" ||
390 status -p "$BRCOMPATD_PIDFILE" ovs-brcompatd) &&
391 status -p "$XENSERVERD_PIDFILE" ovs-xenserverd
394 /usr/sbin/ovsdb-server -V
395 /usr/sbin/ovs-vswitchd -V
396 /usr/sbin/ovs-brcompatd -V
397 /usr/sbin/ovs-xenserverd -V
400 printf "openvswitch [start|stop|restart|unload|status|version]\n"
403 printf "Unknown command: $1\n"