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"
120 function hup_monitor_external_ids {
121 if [ -e /var/run/openvswitch/ovs-external-ids.pid ]; then
122 action "Configuring Open vSwitch external IDs" kill -HUP `cat /var/run/openvswitch/ovs-external-ids.pid`
127 "$dpctl" show | grep '^dp[0-9]\+:' | cut -d':' -f 1
130 function turn_on_corefiles {
134 function remove_all_dp {
135 for dp in $(dp_list); do
136 action "Removing datapath: $dp" "$dpctl" del-dp "$dp"
140 function insert_modules_if_required {
141 if ! lsmod | grep -q "openvswitch_mod"; then
142 action "Inserting llc module" modprobe llc
143 action "Inserting openvswitch module" modprobe openvswitch_mod
145 if [ "$ENABLE_BRCOMPAT" = "y" ] && [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
146 action "Inserting brcompat module" modprobe brcompat_mod
150 function remove_modules {
151 if lsmod | grep -q "brcompat_mod"; then
152 action "Removing brcompat module" rmmod brcompat_mod.ko
154 if lsmod | grep -q "openvswitch_mod"; then
155 action "Removing openvswitch module" rmmod openvswitch_mod.ko
159 function start_daemon {
164 # cd to daemon's run_dir so core files get dumped into a sensible place.
165 eval local run_dir=\$${DAEMON}_RUN_DIR
166 if [ ! -d "$run_dir" ]; then
167 install -d -m 755 -o root -g root "$run_dir"
171 # Configure log levels.
172 eval local syslog_loglevel=\$${DAEMON}_SYSLOG_LOGLEVEL
173 eval local file_loglevel=\$${DAEMON}_FILE_LOGLEVEL
174 eval local logfile=\$${DAEMON}_LOGFILE
175 set -- "$@" -vANY:CONSOLE:EMER -vANY:SYSLOG:"$syslog_loglevel"
176 if test -n "$file_loglevel" && test -n "$logfile"; then
177 install -d -m 755 -o root -g root `dirname "$logfile"`
178 set -- "$@" --log-file="$logfile" -vANY:FILE:"$file_loglevel"
181 # Configure leak checker.
182 eval local memleak_logfile=\$${DAEMON}_MEMLEAK_LOGFILE
183 if test -n "$memleak_logfile"; then
184 set -- "$@" --check-leaks="$memleak_logfile"
185 if test -e "$memleak_logfile"; then
186 mv "$memleak_logfile" "$memleak_logfile.prev"
190 # Configure debugging wrappers.
191 eval local strace_log=\$${DAEMON}_STRACE_LOG
192 eval local strace_opt=\$${DAEMON}_STRACE_OPT
193 eval local valgrind_log=\$${DAEMON}_VALGRIND_LOG
194 eval local valgrind_opt=\$${DAEMON}_VALGRIND_OPT
195 if test -n "$strace_log" && test -n "$valgrind_log"; then
196 printf "Can not start with both VALGRIND and STRACE\n"
198 elif test -n "$strace_log"; then
200 set -- strace -o "$strace_log" $strace_opt "$@"
201 elif test -n "$valgrind_log"; then
203 set -- valgrind --log-file="$valgrind_log" $valgrind_opt "$@"
205 local mode=production
206 eval local pidfile=\$${DAEMON}_PIDFILE
207 install -d -m 755 -o root -g root `dirname $pidfile`
208 set -- "$@" --pidfile="$pidfile" --detach $monitor_opt --no-chdir
211 # Configure niceness.
212 eval local priority=\$${DAEMON}_PRIORITY
213 if test -n "$priority"; then
214 set -- nice -n $priority "$@"
217 if test $mode = production; then
218 action "Starting `basename $BINARY`" "$@"
220 # Start in background and force a "success" message
221 action "Starting `basename $BINARY` with $mode debugging" true
226 function start_ovsdb_server {
227 set -- "$ovsdb_server" "$OVSDB_SERVER_DB"
228 for remote in $OVSDB_SERVER_REMOTES; do
229 set -- "$@" --remote="$remote"
231 set -- "$@" --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert
232 start_daemon OVSDB_SERVER "$@"
235 function start_vswitchd {
236 local fake_proc_net_opt=
237 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
238 fake_proc_net_opt="--fake-proc-net"
242 if [ "$VSWITCHD_MLOCKALL" != "no" ]; then
243 mlockall_opt="--mlockall"
246 start_daemon VSWITCHD "$vswitchd" $fake_proc_net_opt $mlockall_opt \
247 "$VSWITCHD_OVSDB_SERVER"
250 function start_brcompatd {
251 start_daemon BRCOMPATD "$brcompatd" \
252 --appctl-command="$appctl --target=/var/run/openvswitch/ovs-vswitchd.\`cat $VSWITCHD_PIDFILE\`.ctl %s" \
253 "$VSWITCHD_OVSDB_SERVER"
256 function stop_daemon {
259 eval local pidfile=\$${DAEMON}_PIDFILE
260 if test -f "$pidfile"; then
261 local pid=$(cat "$pidfile")
262 action "Killing `basename $BINARY` ($pid)" kill $pid
263 for delay in .1 .25 .65 1 1 1 1; do
264 if kill -0 $pid >/dev/null 2>&1; then
274 function restart_approval {
276 # Don't prompt if invoked non-interactively.
283 Restarting Open vSwitch on a live server is not guaranteed to work. It is
284 provided as a convenience for those situations in which it does work.
287 read -s -r -n 1 -p "Continue with restart (y/N): " response
299 function set_system_ids {
300 if [ -f /etc/xensource-inventory ]; then
301 action "Configuring Open vSwitch system IDs" true
302 $vsctl --no-wait --timeout=5 set Open_vSwitch . \
303 external-ids:system-type="$PRODUCT_BRAND" \
304 external-ids:system-version="$PRODUCT_VERSION-$BUILD_NUMBER" \
305 external-ids:system-id="$INSTALLATION_UUID" \
306 external-ids:xs-system-uuid="$INSTALLATION_UUID"
308 action "Configuring Open vSwitch system IDs" false
313 if [ "$FORCE_COREFILES" = "y" ]; then
317 insert_modules_if_required
319 # Increase the limit on the number of open file descriptors since
320 # ovs-vswitchd needs a few per bridge
324 iptables -I INPUT -p gre -j ACCEPT
326 if [ ! -e "$OVSDB_SERVER_DB" ]; then
327 warning "$OVSDB_SERVER_DB does not exist"
328 install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_DB`
330 action "Creating empty database $OVSDB_SERVER_DB" true
331 $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
333 # Upgrade or downgrade schema and compact database.
334 $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
338 $vsctl --no-wait --timeout=5 init
339 if [ ! -e /var/run/openvswitch.booted ]; then
340 touch /var/run/openvswitch.booted
341 for bridge in $($vsctl list-br); do
342 $vsctl --no-wait --timeout=5 del-br $bridge
349 if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then
353 # Start daemon to monitor external ids
354 PYTHONPATH=/usr/share/openvswitch/python \
355 /usr/share/openvswitch/scripts/ovs-external-ids \
356 --pidfile --detach $monitor_opt "$VSWITCHD_OVSDB_SERVER"
358 touch /var/lock/subsys/openvswitch
362 stop_daemon BRCOMPATD "$brcompatd"
363 stop_daemon VSWITCHD "$vswitchd"
364 stop_daemon OVSDB_SERVER "$ovsdb_server"
365 if [ -e /var/run/openvswitch/ovs-external-ids.pid ]; then
366 kill `cat /var/run/openvswitch/ovs-external-ids.pid`
368 rm -f /var/lock/subsys/openvswitch
372 if restart_approval; then
389 # Nothing to do to ovs-vswitchd and ovsdb-server as they keep their
390 # configuration up-to-date all the time. HUP ovs-external-ids so it
392 hup_monitor_external_ids
396 strace -p $(cat "$VSWITCHD_PIDFILE") "$@"
400 strace -p $(cat "$BRCOMPATD_PIDFILE") "$@"
403 status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server &&
404 status -p "$VSWITCHD_PIDFILE" ovs-vswitchd &&
405 (test "$ENABLE_BRCOMPAT" != "y" ||
406 status -p "$BRCOMPATD_PIDFILE" ovs-brcompatd)
409 /usr/sbin/ovsdb-server -V
410 /usr/sbin/ovs-vswitchd -V
411 /usr/sbin/ovs-brcompatd -V
414 printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n"
417 printf "Unknown command: $1\n"