-NETWORK_MODE=$(cat /etc/xensource/network.conf)
-if test "$NETWORK_MODE" = bridge; then
- echo "Open vSwitch disabled (/etc/xensource/network.conf is 'bridge')" >&2
- exit 0
-fi
-
-# 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}
-fi
-: ${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_DB:=/etc/openvswitch/conf.db}
-: ${OVSDB_SERVER_PIDFILE:=/var/run/openvswitch/ovsdb-server.pid}
-: ${OVSDB_SERVER_RUN_DIR:=/var/xen/openvswitch}
-: ${OVSDB_SERVER_PRIORITY:=-10}
-: ${OVSDB_SERVER_LOGFILE:=/var/log/openvswitch/ovsdb-server.log}
-: ${OVSDB_SERVER_FILE_LOGLEVEL:=INFO}
-: ${OVSDB_SERVER_SYSLOG_LOGLEVEL:=ERR}
-: ${OVSDB_SERVER_MEMLEAK_LOGFILE:=}
-: ${OVSDB_SERVER_STRACE_LOG:=}
-: ${OVSDB_SERVER_STRACE_OPT:=}
-: ${OVSDB_SERVER_VALGRIND_LOG:=}
-: ${OVSDB_SERVER_VALGRIND_OPT:=}
-
-# Config variables specific to ovs-vswitchd
-: ${VSWITCHD_OVSDB_SERVER:=unix:/var/run/openvswitch/db.sock}
-: ${VSWITCHD_OVSDB_SCHEMA:=/usr/share/openvswitch/vswitch.ovsschema}
-: ${VSWITCHD_PIDFILE:=/var/run/openvswitch/ovs-vswitchd.pid}
-: ${VSWITCHD_RUN_DIR:=/var/xen/openvswitch}
-: ${VSWITCHD_PRIORITY:=-10}
-: ${VSWITCHD_MLOCKALL:=yes}
-: ${VSWITCHD_LOGFILE:=/var/log/openvswitch/ovs-vswitchd.log}
-: ${VSWITCHD_FILE_LOGLEVEL:=INFO}
-: ${VSWITCHD_SYSLOG_LOGLEVEL:=ERR}
-: ${VSWITCHD_MEMLEAK_LOGFILE:=}
-: ${VSWITCHD_STRACE_LOG:=}
-: ${VSWITCHD_STRACE_OPT:=}
-: ${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:=}
-
-# Config variables specific to ovs-xenserverd
-: ${XENSERVERD_PIDFILE:=/var/run/openvswitch/ovs-xenserverd.pid}
-: ${XENSERVERD_RUN_DIR:=/var/xen/openvswitch}
-: ${XENSERVERD_PRIORITY:=}
-: ${XENSERVERD_LOGFILE:=}
-: ${XENSERVERD_FILE_LOGLEVEL:=}
-: ${XENSERVERD_SYSLOG_LOGLEVEL:=}
-: ${XENSERVERD_MEMLEAK_LOGFILE:=}
-: ${XENSERVERD_STRACE_LOG:=}
-: ${XENSERVERD_STRACE_OPT:=}
-: ${XENSERVERD_VALGRIND_LOG:=}
-: ${XENSERVERD_VALGRIND_OPT:=}
-
-# 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"
-xenserverd="/usr/sbin/ovs-xenserverd"
-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 turn_on_corefiles {
- ulimit -Sc 67108864
-}
-
-function remove_all_dp {
- for dp in $(dp_list); do
- action "Removing datapath: $dp" "$dpctl" del-dp "$dp"
- done
-}
-
-function insert_modules_if_required {
- 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
-}
-
-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
-}
-
-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
-
- # 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
- 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
- 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
-
- # Configure niceness.
- eval local priority=\$${DAEMON}_PRIORITY
- if test -n "$priority"; then
- set -- nice -n $priority "$@"
- fi