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)
35 echo "Open vSwitch disabled (/etc/xensource/network.conf is invalid)" >&2
40 # General config variables in /etc/sysconfig/openvswitch
41 if test "$PRODUCT_VERSION" = "5.5.0"; then
42 # XenServer 5.5.0 needs ovs-brcompatd and /proc/net simulation.
43 : ${ENABLE_BRCOMPAT:=y}
44 : ${ENABLE_FAKE_PROC_NET:=y}
46 # Later versions don't need them.
47 : ${ENABLE_BRCOMPAT:=n}
48 : ${ENABLE_FAKE_PROC_NET:=n}
50 : ${ENABLE_MONITOR:=y}
51 : ${FORCE_COREFILES:=y}
53 # Config variables specific to ovsdb-server
54 : ${OVSDB_SERVER_REMOTES:=punix:/var/run/openvswitch/db.sock db:Open_vSwitch,managers}
55 : ${OVSDB_SERVER_DB:=/etc/openvswitch/conf.db}
56 : ${OVSDB_SERVER_PIDFILE:=/var/run/openvswitch/ovsdb-server.pid}
57 : ${OVSDB_SERVER_RUN_DIR:=/var/xen/openvswitch}
58 : ${OVSDB_SERVER_PRIORITY:=-10}
59 : ${OVSDB_SERVER_LOGFILE:=/var/log/openvswitch/ovsdb-server.log}
60 : ${OVSDB_SERVER_FILE_LOGLEVEL:=INFO}
61 : ${OVSDB_SERVER_SYSLOG_LOGLEVEL:=ERR}
62 : ${OVSDB_SERVER_MEMLEAK_LOGFILE:=}
63 : ${OVSDB_SERVER_STRACE_LOG:=}
64 : ${OVSDB_SERVER_STRACE_OPT:=}
65 : ${OVSDB_SERVER_VALGRIND_LOG:=}
66 : ${OVSDB_SERVER_VALGRIND_OPT:=}
68 # Config variables specific to ovs-vswitchd
69 : ${VSWITCHD_OVSDB_SERVER:=unix:/var/run/openvswitch/db.sock}
70 : ${VSWITCHD_OVSDB_SCHEMA:=/usr/share/openvswitch/vswitch.ovsschema}
71 : ${VSWITCHD_PIDFILE:=/var/run/openvswitch/ovs-vswitchd.pid}
72 : ${VSWITCHD_RUN_DIR:=/var/xen/openvswitch}
73 : ${VSWITCHD_PRIORITY:=-10}
74 : ${VSWITCHD_MLOCKALL:=yes}
75 : ${VSWITCHD_LOGFILE:=/var/log/openvswitch/ovs-vswitchd.log}
76 : ${VSWITCHD_FILE_LOGLEVEL:=INFO}
77 : ${VSWITCHD_SYSLOG_LOGLEVEL:=ERR}
78 : ${VSWITCHD_MEMLEAK_LOGFILE:=}
79 : ${VSWITCHD_STRACE_LOG:=}
80 : ${VSWITCHD_STRACE_OPT:=}
81 : ${VSWITCHD_VALGRIND_LOG:=}
82 : ${VSWITCHD_VALGRIND_OPT:=}
84 # Config variables specific to ovs-brcompatd
85 : ${BRCOMPATD_PIDFILE:=/var/run/openvswitch/ovs-brcompatd.pid}
86 : ${BRCOMPATD_RUN_DIR:=/var/xen/openvswitch}
87 : ${BRCOMPATD_PRIORITY:=-10}
88 : ${BRCOMPATD_LOGFILE:=/var/log/openvswitch/ovs-brcompatd.log}
89 : ${BRCOMPATD_FILE_LOGLEVEL:=INFO}
90 : ${BRCOMPATD_SYSLOG_LOGLEVEL:=ERR}
91 : ${BRCOMPATD_MEMLEAK_LOGFILE:=}
92 : ${BRCOMPATD_STRACE_LOG:=}
93 : ${BRCOMPATD_STRACE_OPT:=}
94 : ${BRCOMPATD_VALGRIND_LOG:=}
95 : ${BRCOMPATD_VALGRIND_OPT:=}
97 # Full paths to executables & modules
98 ovsdb_server="/usr/sbin/ovsdb-server"
99 ovsdb_tool="/usr/bin/ovsdb-tool"
100 vswitchd="/usr/sbin/ovs-vswitchd"
101 brcompatd="/usr/sbin/ovs-brcompatd"
102 dpctl="/usr/bin/ovs-dpctl"
103 appctl="/usr/bin/ovs-appctl"
104 ofctl="/usr/bin/ovs-ofctl"
105 vsctl="/usr/bin/ovs-vsctl"
107 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
108 if [ "$ENABLE_BRCOMPAT" != "y" ]; then
109 warning "FAKE_PROC_NET required BRCOMPAT which was disabled. Force enabling."
114 if test "$ENABLE_MONITOR" = "y"; then
115 monitor_opt="--monitor"
121 "$dpctl" show | grep '^dp[0-9]\+:' | cut -d':' -f 1
124 function turn_on_corefiles {
128 function remove_all_dp {
129 for dp in $(dp_list); do
130 action "Removing datapath: $dp" "$dpctl" del-dp "$dp"
134 function insert_modules_if_required {
135 if ! lsmod | grep -q "openvswitch_mod"; then
136 action "Inserting llc module" modprobe llc
137 action "Inserting openvswitch module" modprobe openvswitch_mod
139 if [ "$ENABLE_BRCOMPAT" = "y" ] && [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
140 action "Inserting brcompat module" modprobe brcompat_mod
144 function remove_modules {
145 if lsmod | grep -q "brcompat_mod"; then
146 action "Removing brcompat module" rmmod brcompat_mod.ko
148 if lsmod | grep -q "openvswitch_mod"; then
149 action "Removing openvswitch module" rmmod openvswitch_mod.ko
153 function start_daemon {
158 # cd to daemon's run_dir so core files get dumped into a sensible place.
159 eval local run_dir=\$${DAEMON}_RUN_DIR
160 if [ ! -d "$run_dir" ]; then
161 install -d -m 755 -o root -g root "$run_dir"
165 # Configure log levels.
166 eval local syslog_loglevel=\$${DAEMON}_SYSLOG_LOGLEVEL
167 eval local file_loglevel=\$${DAEMON}_FILE_LOGLEVEL
168 eval local logfile=\$${DAEMON}_LOGFILE
169 set -- "$@" -vANY:CONSOLE:EMER -vANY:SYSLOG:"$syslog_loglevel"
170 if test -n "$file_loglevel" && test -n "$logfile"; then
171 install -d -m 755 -o root -g root `dirname "$logfile"`
172 set -- "$@" --log-file="$logfile" -vANY:FILE:"$file_loglevel"
175 # Configure leak checker.
176 eval local memleak_logfile=\$${DAEMON}_MEMLEAK_LOGFILE
177 if test -n "$memleak_logfile"; then
178 set -- "$@" --check-leaks="$memleak_logfile"
179 if test -e "$memleak_logfile"; then
180 mv "$memleak_logfile" "$memleak_logfile.prev"
184 # Configure debugging wrappers.
185 eval local strace_log=\$${DAEMON}_STRACE_LOG
186 eval local strace_opt=\$${DAEMON}_STRACE_OPT
187 eval local valgrind_log=\$${DAEMON}_VALGRIND_LOG
188 eval local valgrind_opt=\$${DAEMON}_VALGRIND_OPT
189 if test -n "$strace_log" && test -n "$valgrind_log"; then
190 printf "Can not start with both VALGRIND and STRACE\n"
192 elif test -n "$strace_log"; then
194 set -- strace -o "$strace_log" $strace_opt "$@"
195 elif test -n "$valgrind_log"; then
197 set -- valgrind --log-file="$valgrind_log" $valgrind_opt "$@"
199 local mode=production
200 eval local pidfile=\$${DAEMON}_PIDFILE
201 install -d -m 755 -o root -g root `dirname $pidfile`
202 set -- "$@" --pidfile="$pidfile" --detach $monitor_opt --no-chdir
205 # Configure niceness.
206 eval local priority=\$${DAEMON}_PRIORITY
207 if test -n "$priority"; then
208 set -- nice -n $priority "$@"
211 if test $mode = production; then
212 action "Starting `basename $BINARY`" "$@"
214 # Start in background and force a "success" message
215 action "Starting `basename $BINARY` with $mode debugging" true
220 function start_ovsdb_server {
221 set -- "$ovsdb_server" "$OVSDB_SERVER_DB"
222 for remote in $OVSDB_SERVER_REMOTES; do
223 set -- "$@" --remote="$remote"
225 set -- "$@" --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert
226 start_daemon OVSDB_SERVER "$@"
229 function start_vswitchd {
230 local fake_proc_net_opt=
231 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
232 fake_proc_net_opt="--fake-proc-net"
236 if [ "$VSWITCHD_MLOCKALL" != "no" ]; then
237 mlockall_opt="--mlockall"
240 start_daemon VSWITCHD "$vswitchd" $fake_proc_net_opt $mlockall_opt \
241 "$VSWITCHD_OVSDB_SERVER"
244 function start_brcompatd {
245 start_daemon BRCOMPATD "$brcompatd" \
246 --appctl-command="$appctl --target=/var/run/openvswitch/ovs-vswitchd.\`cat $VSWITCHD_PIDFILE\`.ctl %s" \
247 "$VSWITCHD_OVSDB_SERVER"
250 function stop_daemon {
253 eval local pidfile=\$${DAEMON}_PIDFILE
254 if test -f "$pidfile"; then
255 local pid=$(cat "$pidfile")
256 action "Killing `basename $BINARY` ($pid)" kill $pid
257 for delay in .1 .25 .65 1 1 1 1; do
258 if kill -0 $pid >/dev/null 2>&1; then
268 function restart_approval {
270 # Don't prompt if invoked non-interactively.
277 Restarting Open vSwitch on a live server is not guaranteed to work. It is
278 provided as a convenience for those situations in which it does work.
281 read -s -r -n 1 -p "Continue with restart (y/N): " response
293 function set_system_ids {
294 if [ -f /etc/xensource-inventory ]; then
295 action "Configuring Open vSwitch system IDs" true
296 $vsctl --no-wait set Open_vSwitch . \
297 external-ids:system-type="$PRODUCT_BRAND" \
298 external-ids:system-version="$PRODUCT_VERSION-$BUILD_NUMBER" \
299 external-ids:system-id="$INSTALLATION_UUID" \
300 external-ids:xs-system-uuid="$INSTALLATION_UUID"
302 action "Configuring Open vSwitch system IDs" false
307 if [ "$FORCE_COREFILES" = "y" ]; then
311 insert_modules_if_required
313 # Increase the limit on the number of open file descriptors since
314 # ovs-vswitchd needs a few per bridge
318 iptables -I INPUT -p gre -j ACCEPT
320 if [ ! -e "$OVSDB_SERVER_DB" ]; then
321 warning "$OVSDB_SERVER_DB does not exist"
322 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_DB`
324 action "Creating empty database $OVSDB_SERVER_DB" true
325 $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
327 # Upgrade or downgrade schema and compact database.
328 $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
332 $vsctl --no-wait init
333 if [ ! -e /var/run/openvswitch.booted ]; then
334 touch /var/run/openvswitch.booted
335 for bridge in $($vsctl list-br); do
336 $vsctl --no-wait del-br $bridge
343 if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then
347 # Start daemon to monitor external ids
348 PYTHONPATH=/usr/share/openvswitch/python \
349 /usr/share/openvswitch/scripts/monitor-external-ids \
350 --pidfile --detach "$VSWITCHD_OVSDB_SERVER"
352 touch /var/lock/subsys/openvswitch
356 stop_daemon BRCOMPATD "$brcompatd"
357 stop_daemon VSWITCHD "$vswitchd"
358 stop_daemon OVSDB_SERVER "$ovsdb_server"
359 if [ -e /var/run/openvswitch/monitor-external-ids.pid ]; then
360 kill `cat /var/run/openvswitch/monitor-external-ids.pid`
361 rm /var/run/openvswitch/monitor-external-ids.pid
363 rm -f /var/lock/subsys/openvswitch
367 if restart_approval; then
384 # Nothing to do--ovs-vswitchd and ovsdb-server keep their configuration
385 # up-to-date all the time.
389 strace -p $(cat "$VSWITCHD_PIDFILE") "$@"
393 strace -p $(cat "$BRCOMPATD_PIDFILE") "$@"
396 status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server &&
397 status -p "$VSWITCHD_PIDFILE" ovs-vswitchd &&
398 (test "$ENABLE_BRCOMPAT" != "y" ||
399 status -p "$BRCOMPATD_PIDFILE" ovs-brcompatd)
402 /usr/sbin/ovsdb-server -V
403 /usr/sbin/ovs-vswitchd -V
404 /usr/sbin/ovs-brcompatd -V
407 printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n"
410 printf "Unknown command: $1\n"