X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=xenserver%2Fetc_init.d_openvswitch;h=64ad52ce1157392669b56dbe6015d2da6bcbc576;hb=b2b4c70c4d337a2943b1c530557f64c4cc45d63a;hp=dc5edd06fa5a634f08074908629bb85f0b82ed78;hpb=50b2ad57cb4e2478baf7b71f0c31433eb6a37981;p=sliver-openvswitch.git diff --git a/xenserver/etc_init.d_openvswitch b/xenserver/etc_init.d_openvswitch index dc5edd06f..64ad52ce1 100755 --- a/xenserver/etc_init.d_openvswitch +++ b/xenserver/etc_init.d_openvswitch @@ -5,7 +5,7 @@ # chkconfig: 2345 09 91 # description: Manage Open vSwitch kernel modules and user-space daemons -# Copyright (C) 2009, 2010 Nicira Networks, Inc. +# Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,27 +18,68 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +### BEGIN INIT INFO +# Provides: openvswitch-switch +# Required-Start: +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Open vSwitch switch +### END INIT INFO + +# source function library +if [ -f /etc/init.d/functions ]; then + . /etc/init.d/functions +elif [ -f /etc/rc.d/init.d/functions ]; then + . /etc/rc.d/init.d/functions +elif [ -f /lib/lsb/init-functions ]; then + . /lib/lsb/init-functions +else + echo "$0: missing LSB shell function library" >&2 + exit 1 +fi -. /etc/init.d/functions +if type action >/dev/null 2>&1; then + : +else + # SUSE lacks action + action() { + STRING=$1 + shift + "$@" + rc=$? + if [ $rc -eq 0 ] ; then + log_success_msg $"$STRING " + else + log_failure_msg $"$STRING " + fi + return $rc + } +fi -. /etc/xensource-inventory +test -e /etc/xensource-inventory && . /etc/xensource-inventory test -e /etc/sysconfig/openvswitch && . /etc/sysconfig/openvswitch - -# General config variables in /etc/sysconfig/openvswitch -if test "$PRODUCT_VERSION" = "5.5.0"; then - # XenServer 5.5.0 needs ovs-brcompatd and /proc/net simulation. - : ${ENABLE_BRCOMPAT:=y} - : ${ENABLE_FAKE_PROC_NET:=y} -else - # Later versions don't need them. - : ${ENABLE_BRCOMPAT:=n} - : ${ENABLE_FAKE_PROC_NET:=n} +if test -e /etc/xensource/network.conf; then + NETWORK_MODE=$(cat /etc/xensource/network.conf) fi + +case ${NETWORK_MODE:=openvswitch} in + vswitch|openvswitch) + ;; + bridge) + exit 0 + ;; + *) + echo "Open vSwitch disabled (/etc/xensource/network.conf is invalid)" >&2 + exit 0 + ;; +esac + : ${ENABLE_MONITOR:=y} : ${FORCE_COREFILES:=y} # Config variables specific to ovsdb-server -: ${OVSDB_SERVER_REMOTES:=punix:/var/run/openvswitch/db.sock db:Open_vSwitch,managers} +: ${OVSDB_SERVER_REMOTES:=punix:/var/run/openvswitch/db.sock db:Open_vSwitch,manager_options} : ${OVSDB_SERVER_DB:=/etc/openvswitch/conf.db} : ${OVSDB_SERVER_PIDFILE:=/var/run/openvswitch/ovsdb-server.pid} : ${OVSDB_SERVER_RUN_DIR:=/var/xen/openvswitch} @@ -68,44 +109,27 @@ fi : ${VSWITCHD_VALGRIND_LOG:=} : ${VSWITCHD_VALGRIND_OPT:=} -# Config variables specific to ovs-brcompatd -: ${BRCOMPATD_PIDFILE:=/var/run/openvswitch/ovs-brcompatd.pid} -: ${BRCOMPATD_RUN_DIR:=/var/xen/openvswitch} -: ${BRCOMPATD_PRIORITY:=-10} -: ${BRCOMPATD_LOGFILE:=/var/log/openvswitch/ovs-brcompatd.log} -: ${BRCOMPATD_FILE_LOGLEVEL:=INFO} -: ${BRCOMPATD_SYSLOG_LOGLEVEL:=ERR} -: ${BRCOMPATD_MEMLEAK_LOGFILE:=} -: ${BRCOMPATD_STRACE_LOG:=} -: ${BRCOMPATD_STRACE_OPT:=} -: ${BRCOMPATD_VALGRIND_LOG:=} -: ${BRCOMPATD_VALGRIND_OPT:=} +: ${OVS_XAPI_SYNC_PIDFILE:=/var/run/openvswitch/ovs-xapi-sync.pid} # Full paths to executables & modules ovsdb_server="/usr/sbin/ovsdb-server" ovsdb_tool="/usr/bin/ovsdb-tool" vswitchd="/usr/sbin/ovs-vswitchd" -brcompatd="/usr/sbin/ovs-brcompatd" dpctl="/usr/bin/ovs-dpctl" appctl="/usr/bin/ovs-appctl" ofctl="/usr/bin/ovs-ofctl" vsctl="/usr/bin/ovs-vsctl" -if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then - if [ "$ENABLE_BRCOMPAT" != "y" ]; then - warning "FAKE_PROC_NET required BRCOMPAT which was disabled. Force enabling." - ENABLE_BRCOMPAT="y" - fi -fi - if test "$ENABLE_MONITOR" = "y"; then monitor_opt="--monitor" else monitor_opt= fi -function dp_list { - "$dpctl" show | grep '^dp[0-9]\+:' | cut -d':' -f 1 +function hup_monitor_external_ids { + if [ -e /var/run/openvswitch/ovs-xapi-sync.pid ]; then + action "Configuring Open vSwitch external IDs" kill -HUP `cat /var/run/openvswitch/ovs-xapi-sync.pid` + fi } function turn_on_corefiles { @@ -113,213 +137,131 @@ function turn_on_corefiles { } function remove_all_dp { - for dp in $(dp_list); do + for dp in $($dpctl dump-dps); do action "Removing datapath: $dp" "$dpctl" del-dp "$dp" done } function insert_modules_if_required { + if test -e /sys/module/bridge; then + bridges=`echo /sys/class/net/*/bridge | sed 's,/sys/class/net/,,g;s,/bridge,,g'` + if test "$bridges" != "*"; then + log_warning_msg "not removing bridge module because bridges exist ($bridges)" + else + action "removing bridge module" rmmod bridge + fi + fi if ! lsmod | grep -q "openvswitch_mod"; then action "Inserting llc module" modprobe llc action "Inserting openvswitch module" modprobe openvswitch_mod fi - if [ "$ENABLE_BRCOMPAT" = "y" ] && [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then - action "Inserting brcompat module" modprobe brcompat_mod - fi - if [ -f "/lib/modules/`uname -r`/kernel/extra/openvswitch/veth_mod.ko" ] && ! lsmod | grep -q "veth_mod"; then - action "Inserting veth module" modprobe veth_mod - fi - if [ -f "/lib/modules/`uname -r`/kernel/extra/openvswitch/ip_gre_mod.ko" ] && ! lsmod | grep -q "ip_gre_mod"; then - action "Inserting ip_gre module" modprobe ip_gre_mod - fi } function remove_modules { - if lsmod | grep -q "brcompat_mod"; then - action "Removing brcompat module" rmmod brcompat_mod.ko - fi if lsmod | grep -q "openvswitch_mod"; then action "Removing openvswitch module" rmmod openvswitch_mod.ko fi - if lsmod | grep -q "ip_gre_mod"; then - action "Removing ip_gre module" rmmod ip_gre_mod.ko - fi } -function start_ovsdb_server { - local syslog_opt="-vANY:SYSLOG:${OVSDB_SERVER_SYSLOG_LOGLEVEL}" - local logfile_file_opt="" - local logfile_level_opt="" - if [ ! -d "$OVSDB_SERVER_RUN_DIR" ]; then - install -d -m 755 -o root -g root "$OVSDB_SERVER_RUN_DIR" - fi - cd "$OVSDB_SERVER_RUN_DIR" - local remotes= - for remote in $OVSDB_SERVER_REMOTES; do - remotes="$remotes --remote=$remote" - done - - install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_LOGFILE` - if [ -n "$OVSDB_SERVER_FILE_LOGLEVEL" ]; then - logfile_level_opt="-vANY:FILE:${OVSDB_SERVER_FILE_LOGLEVEL}" - logfile_file_opt="--log-file=$OVSDB_SERVER_LOGFILE" - fi - - local leak_opt="" - if [ -n "$OVSDB_SERVER_MEMLEAK_LOGFILE" ]; then - leak_opt="--check-leaks=$OVSDB_SERVER_MEMLEAK_LOGFILE" - if [ -e "$OVSDB_SERVER_MEMLEAK_LOGFILE" ]; then - mv "$OVSDB_SERVER_MEMLEAK_LOGFILE" "$OVSDB_SERVER_MEMLEAK_LOGFILE.prev" +function start_daemon { + local DAEMON=$1 + shift + local BINARY=$1 + + # cd to daemon's run_dir so core files get dumped into a sensible place. + eval local run_dir=\$${DAEMON}_RUN_DIR + if [ ! -d "$run_dir" ]; then + install -d -m 755 -o root -g root "$run_dir" + fi + cd "$run_dir" + + # Configure log levels. + eval local syslog_loglevel=\$${DAEMON}_SYSLOG_LOGLEVEL + eval local file_loglevel=\$${DAEMON}_FILE_LOGLEVEL + eval local logfile=\$${DAEMON}_LOGFILE + set -- "$@" -vANY:CONSOLE:EMER -vANY:SYSLOG:"$syslog_loglevel" + if test -n "$file_loglevel" && test -n "$logfile"; then + install -d -m 755 -o root -g root `dirname "$logfile"` + set -- "$@" --log-file="$logfile" -vANY:FILE:"$file_loglevel" + fi + + # Configure leak checker. + eval local memleak_logfile=\$${DAEMON}_MEMLEAK_LOGFILE + if test -n "$memleak_logfile"; then + set -- "$@" --check-leaks="$memleak_logfile" + if test -e "$memleak_logfile"; then + mv "$memleak_logfile" "$memleak_logfile.prev" fi fi - local strace_opt="" - local daemonize="y" - if [ -n "$OVSDB_SERVER_STRACE_LOG" ] && [ -n "$OVSDB_SERVER_VALGRIND_LOG" ]; then - printf "Can not start with both VALGRIND and STRACE\n" - exit 1 - fi - if [ -n "$OVSDB_SERVER_STRACE_LOG" ]; then - strace_opt="strace -o $OVSDB_SERVER_STRACE_LOG $OVSDB_SERVER_STRACE_OPT" - daemonize="n" - fi - if [ -n "$OVSDB_SERVER_VALGRIND_LOG" ]; then - valgrind_opt="valgrind --log-file=$OVSDB_SERVER_VALGRIND_LOG $OVSDB_SERVER_VALGRIND_OPT" - daemonize="n" - fi - ssl_opts="--private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert" - install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_PIDFILE` - if [ "$daemonize" != "y" ]; then - # Start in background and force a "success" message - action "Starting ovsdb_server ($strace_opt$valgrind_opt)" true - (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) & - else - 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 - fi -} - -function start_vswitchd { - local syslog_opt="-vANY:SYSLOG:${VSWITCHD_SYSLOG_LOGLEVEL}" - local logfile_file_opt="" - local logfile_level_opt="" - if [ ! -d "$VSWITCHD_RUN_DIR" ]; then - install -d -m 755 -o root -g root "$VSWITCHD_RUN_DIR" - fi - cd "$VSWITCHD_RUN_DIR" - - install -d -m 755 -o root -g root `dirname $VSWITCHD_LOGFILE` - if [ -n "$VSWITCHD_FILE_LOGLEVEL" ]; then - logfile_level_opt="-vANY:FILE:${VSWITCHD_FILE_LOGLEVEL}" - logfile_file_opt="--log-file=$VSWITCHD_LOGFILE" - fi - local leak_opt="" - if [ -n "$VSWITCHD_MEMLEAK_LOGFILE" ]; then - leak_opt="--check-leaks=$VSWITCHD_MEMLEAK_LOGFILE" - if [ -e "$VSWITCHD_MEMLEAK_LOGFILE" ]; then - mv "$VSWITCHD_MEMLEAK_LOGFILE" "$VSWITCHD_MEMLEAK_LOGFILE.prev" - fi - fi - local strace_opt="" - local daemonize="y" - if [ -n "$VSWITCHD_STRACE_LOG" ] && [ -n "$VSWITCHD_VALGRIND_LOG" ]; then + # Configure debugging wrappers. + eval local strace_log=\$${DAEMON}_STRACE_LOG + eval local strace_opt=\$${DAEMON}_STRACE_OPT + eval local valgrind_log=\$${DAEMON}_VALGRIND_LOG + eval local valgrind_opt=\$${DAEMON}_VALGRIND_OPT + if test -n "$strace_log" && test -n "$valgrind_log"; then printf "Can not start with both VALGRIND and STRACE\n" exit 1 - fi - if [ -n "$VSWITCHD_STRACE_LOG" ]; then - strace_opt="strace -o $VSWITCHD_STRACE_LOG $VSWITCHD_STRACE_OPT" - daemonize="n" - fi - if [ -n "$VSWITCHD_VALGRIND_LOG" ]; then - valgrind_opt="valgrind --log-file=$VSWITCHD_VALGRIND_LOG $VSWITCHD_VALGRIND_OPT" - daemonize="n" - fi - local fake_proc_net_opt="" - if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then - fake_proc_net_opt="--fake-proc-net" - fi - if [ "$VSWITCHD_MLOCKALL" != "no" ]; then - mlockall_opt="--mlockall" - fi - - install -d -m 755 -o root -g root `dirname $VSWITCHD_PIDFILE` - if [ "$daemonize" != "y" ]; then - # Start in background and force a "success" message - action "Starting ovs-vswitchd ($strace_opt$valgrind_opt)" true - (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") & + elif test -n "$strace_log"; then + local mode=strace + set -- strace -o "$strace_log" $strace_opt "$@" + elif test -n "$valgrind_log"; then + local mode=valgrind + set -- valgrind --log-file="$valgrind_log" $valgrind_opt "$@" else - 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" + local mode=production + eval local pidfile=\$${DAEMON}_PIDFILE + install -d -m 755 -o root -g root `dirname $pidfile` + set -- "$@" --pidfile="$pidfile" --detach $monitor_opt --no-chdir fi -} -function start_brcompatd { - local syslog_opt="-vANY:SYSLOG:${BRCOMPATD_SYSLOG_LOGLEVEL}" - local logfile_file_opt="" - local logfile_level_opt="" - if [ -d "$BRCOMPATD_RUN_DIR" ]; then - install -d -m 755 -o root -g root "$BRCOMPATD_RUN_DIR" - fi - cd "$BRCOMPATD_RUN_DIR" - - install -d -m 755 -o root -g root `dirname $BRCOMPATD_LOGFILE` - if [ -n "$BRCOMPATD_FILE_LOGLEVEL" ]; then - logfile_level_opt="-vANY:FILE:${BRCOMPATD_FILE_LOGLEVEL}" - logfile_file_opt="--log-file=$BRCOMPATD_LOGFILE" - fi - - local leak_opt="" - if [ -n "$BRCOMPATD_MEMLEAK_LOGFILE" ]; then - leak_opt="--check-leaks=$BRCOMPATD_MEMLEAK_LOGFILE" - if [ -e "$BRCOMPATD_MEMLEAK_LOGFILE" ]; then - mv "$BRCOMPATD_MEMLEAK_LOGFILE" "$BRCOMPATD_MEMLEAK_LOGFILE.prev" - fi - fi - local strace_opt="" - local daemonize="y" - if [ -n "$BRCOMPATD_STRACE_LOG" ] && [ -n "$BRCOMPATD_VALGRIND_LOG" ]; then - printf "Can not start with both VALGRIND and STRACE\n" - exit 1 - fi - if [ -n "$BRCOMPATD_STRACE_LOG" ]; then - strace_opt="strace -o $BRCOMPATD_STRACE_LOG $BRCOMPATD_STRACE_OPT" - daemonize="n" + # Configure niceness. + eval local priority=\$${DAEMON}_PRIORITY + if test -n "$priority"; then + set -- nice -n $priority "$@" fi - if [ -n "$VALGRIND_LOG" ]; then - valgrind_opt="valgrind --log-file=$BRCOMPATD_VALGRIND_LOG $BRCOMPATD_VALGRIND_OPT" - daemonize="n" - fi - appctl_cmd="$appctl --target=/var/run/openvswitch/ovs-vswitchd.\`cat $VSWITCHD_PIDFILE\`.ctl %s" - install -d -m 755 -o root -g root `dirname $BRCOMPATD_PIDFILE` - if [ "$daemonize" != "y" ]; then - # Start in background and force a "success" message - action "Starting ovs-brcompatd ($strace_opt$valgrind_opt)" true - (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") & + if test $mode = production; then + action "Starting `basename $BINARY`" "$@" else - 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" + # Start in background and force a "success" message + action "Starting `basename $BINARY` with $mode debugging" true + ("$@") & fi } -function stop_ovsdb_server { - if [ -f "$OVSDB_SERVER_PIDFILE" ]; then - local pid=$(cat "$OVSDB_SERVER_PIDFILE") - action "Killing ovsdb-server ($pid)" kill -TERM $pid - rm -f "$OVSDB_SERVER_PIDFILE" - fi +function start_ovsdb_server { + set -- "$ovsdb_server" "$OVSDB_SERVER_DB" + for remote in $OVSDB_SERVER_REMOTES; do + set -- "$@" --remote="$remote" + done + set -- "$@" --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert + start_daemon OVSDB_SERVER "$@" } -function stop_vswitchd { - if [ -f "$VSWITCHD_PIDFILE" ]; then - local pid=$(cat "$VSWITCHD_PIDFILE") - action "Killing ovs-vswitchd ($pid)" kill -TERM $pid - rm -f "$VSWITCHD_PIDFILE" +function start_vswitchd { + local mlockall_opt= + if [ "$VSWITCHD_MLOCKALL" != "no" ]; then + mlockall_opt="--mlockall" fi -} -function stop_brcompatd { - if [ -f "$BRCOMPATD_PIDFILE" ]; then - local pid=$(cat "$BRCOMPATD_PIDFILE") - action "Killing ovs-brcompatd ($pid)" kill -TERM $pid - rm -f "$BRCOMPATD_PIDFILE" + start_daemon VSWITCHD "$vswitchd" $mlockall_opt "$VSWITCHD_OVSDB_SERVER" + } + +function stop_daemon { + local DAEMON=$1 + local BINARY=$2 + eval local pidfile=\$${DAEMON}_PIDFILE + if test -f "$pidfile"; then + local pid=$(cat "$pidfile") + action "Killing `basename $BINARY` ($pid)" kill $pid + for delay in .1 .25 .65 1 1 1 1; do + if kill -0 $pid >/dev/null 2>&1; then + sleep $delay + else + break + fi + done fi } @@ -336,7 +278,7 @@ Restarting Open vSwitch on a live server is not guaranteed to work. It is provided as a convenience for those situations in which it does work. EOF - read -s -r -n 1 -p "Countinue with restart (y/N): " response + read -s -r -n 1 -p "Continue with restart (y/N): " response printf "\n" case "$response" in y|Y) @@ -348,12 +290,28 @@ EOF esac } -function set_system_uuid { - if test -n "$INSTALLATION_UUID"; then - action "Configuring Open vSwitch system UUID" true - $vsctl --no-wait set Open_vSwitch . external-ids:system-uuid="$INSTALLATION_UUID" +function set_system_ids { + if [ -f /etc/xensource-inventory ]; then + OVS_VERSION=`ovs-vswitchd --version | sed 's/.*) //;1q'` + action "Configuring Open vSwitch system IDs" true + $vsctl --no-wait --timeout=5 set Open_vSwitch . \ + ovs-version="$OVS_VERSION" \ + system-type="$PRODUCT_BRAND" \ + system-version="$PRODUCT_VERSION-$BUILD_NUMBER" \ + external-ids:system-id="$INSTALLATION_UUID" \ + external-ids:xs-system-uuid="$INSTALLATION_UUID" else - action "Configuring Open vSwitch system UUID" false + if test -f /etc/openvswitch/install_uuid.conf; then + . /etc/openvswitch/install_uuid.conf + elif INSTALLATION_UUID=`uuidgen`; then + echo "INSTALLATION_UUID=$INSTALLATION_UUID" > /etc/openvswitch/install_uuid.conf + else + log_failure_msg "missing uuidgen, could not generate system UUID" + return + fi + $vsctl --no-wait --timeout=5 set Open_vSwitch . \ + external-ids:system-id="$INSTALLATION_UUID" + action "Configuring Open vSwitch system IDs" true fi } @@ -371,39 +329,61 @@ function start { # Allow GRE traffic. iptables -I INPUT -p gre -j ACCEPT + schemaver=`$ovsdb_tool schema-version "$VSWITCHD_OVSDB_SCHEMA"` if [ ! -e "$OVSDB_SERVER_DB" ]; then warning "$OVSDB_SERVER_DB does not exist" install -d -m 755 -o root -g root `dirname $OVSDB_SERVER_DB` action "Creating empty database $OVSDB_SERVER_DB" true $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA" - else - # Upgrade or downgrade schema and compact database. + elif test "X`$ovsdb_tool needs-conversion "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"`" != Xno; then + # Back up the old version. + version=`$ovsdb_tool db-version "$OVSDB_SERVER_DB"` + cksum=`$ovsdb_tool db-cksum "$OVSDB_SERVER_DB" | awk '{print $1}'` + cp "$OVSDB_SERVER_DB" "$OVSDB_SERVER_DB.backup$version-$cksum" + + # Compact database. This is important if the old schema did not enable + # garbage collection (i.e. if it did not have any tables with "isRoot": + # true) but the new schema does. In that situation the old database + # may contain a transaction that creates a record followed by a + # transaction that creates the first use of the record. Replaying that + # series of transactions against the new database schema (as "convert" + # does) would cause the record to be dropped by the first transaction, + # then the second transaction would cause a referential integrity + # failure (for a strong reference). + $ovsdb_tool -vANY:console:emer compact "$OVSDB_SERVER_DB" + + # Upgrade or downgrade schema. $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA" fi start_ovsdb_server - $vsctl --no-wait init + $vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schemaver" if [ ! -e /var/run/openvswitch.booted ]; then touch /var/run/openvswitch.booted for bridge in $($vsctl list-br); do - $vsctl --no-wait del-br $bridge + $vsctl --no-wait --timeout=5 del-br $bridge done fi - set_system_uuid + set_system_ids start_vswitchd - if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then - start_brcompatd + + if [ -f /etc/xensource-inventory ]; then + # Start daemon to monitor external ids + PYTHONPATH=/usr/share/openvswitch/python \ + /usr/share/openvswitch/scripts/ovs-xapi-sync \ + --pidfile --detach $monitor_opt "$VSWITCHD_OVSDB_SERVER" fi + touch /var/lock/subsys/openvswitch } function stop { - stop_brcompatd - stop_vswitchd - stop_ovsdb_server + stop_daemon VSWITCHD "$vswitchd" + stop_daemon OVSDB_SERVER "$ovsdb_server" + stop_daemon OVS_XAPI_SYNC ovs-xapi-sync rm -f /var/lock/subsys/openvswitch } @@ -414,6 +394,59 @@ function restart { fi } +function internal_interfaces { + # Outputs a list of internal interfaces: + # + # - There is an internal interface for every bridge, whether it has + # an Interface record or not and whether the Interface record's + # 'type' is properly set. + # + # - There is an internal interface for each Interface record whose + # 'type' is 'internal'. + # + # But ignore interfaces that don't really exist. + for d in `(ovs-vsctl --bare \ + -- --columns=name find Interface type=internal \ + -- list-br) | sort -u` + do + if test -e "/sys/class/net/$d"; then + printf "%s " "$d" + fi + done +} + +function force_reload_kmod { + ifaces=$(internal_interfaces) + action "Configured internal interfaces: $ifaces" true + + stop + + script=$(mktemp) + action "Save interface configuration to $script" true + if ! /usr/share/openvswitch/scripts/ovs-save $ifaces > $script; then + warning "Failed to save configuration, not replacing kernel module" + start + exit 1 + fi + chmod +x $script + + action "Destroy datapaths" remove_all_dp + + remove_modules + + start + + action "Restore interface configuration from $script" $script + + # Restart the high-availability daemon if it is running. Otherwise + # it loses its heartbeat and reboots the system after a few minutes. + if pidof xhad >/dev/null && test -e /etc/xensource/xhad.conf; then + PATH=$PATH:/opt/xensource/xha + action "Stopping HA daemon" ha_stop_daemon + action "Starting HA daemon" ha_start_daemon + fi +} + case "$1" in start) start @@ -424,27 +457,29 @@ case "$1" in restart) restart ;; + reload|force-reload) + # Nothing to do to ovs-vswitchd and ovsdb-server as they keep their + # configuration up-to-date all the time. HUP ovs-xapi-sync so it + # re-runs. + hup_monitor_external_ids + ;; strace-vswitchd) shift strace -p $(cat "$VSWITCHD_PIDFILE") "$@" ;; - strace-brcompatd) - shift - strace -p $(cat "$BRCOMPATD_PIDFILE") "$@" - ;; status) status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server && - status -p "$VSWITCHD_PIDFILE" ovs-vswitchd && - (test "$ENABLE_BRCOMPAT" != "y" || - status -p "$BRCOMPATD_PIDFILE" ovs-brcompatd) + status -p "$VSWITCHD_PIDFILE" ovs-vswitchd ;; version) /usr/sbin/ovsdb-server -V /usr/sbin/ovs-vswitchd -V - /usr/sbin/ovs-brcompatd -V + ;; + force-reload-kmod) + force_reload_kmod ;; help) - printf "openvswitch [start|stop|restart|unload|status|version]\n" + printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n" ;; *) printf "Unknown command: $1\n"