. /etc/init.d/functions
test -e /etc/sysconfig/vswitch && . /etc/sysconfig/vswitch
-SYSLOG_LOGLEVEL="${SYSLOG_LOGLEVEL:-WARN}"
-FILE_LOGLEVEL="${FILE_LOGLEVEL:-}"
-PRIORITY="${PRIORITY:--5}"
-MEMLEAK_LOG="${MEMLEAK_LOG:-}"
-
-# --- Debugging startup options ---
-#
-# These should not generally be used since it requires vswitchd to run
-# in the foreground which is not really what you want in an init
-# script. Used by the restart-valgrind and restart-strace commands
-
-STRACE_LOG="${STRACE_LOG:-}"
-STRACE_OPT="${STRACE_OPT:-}"
-VALGRIND_LOG="${VALGRIND_LOG:-}"
-VALGRIND_OPT="${VALGRIND_OPT:-}"
-
-VSWITCH_BASE=/root/vswitch/openflow/build
-VSWITCHD_CONF=/etc/vswitchd.conf
-VSWITCHD_LOG=/var/log/vswitchd.log
+VSWITCH_BASE="${VSWITCH_BASE:-/root/vswitch/openflow/build}"
+VSWITCHD_CONF="${VSWITCHD_CONF:-/etc/vswitchd.conf}"
+VSWITCHD_PIDFILE="${VSWITCHD_PIDFILE:-/var/run/vswitchd.pid}"
+VSWITCHD_PRIORITY="${VSWITCHD_PRIORITY:--5}"
+VSWITCHD_LOGFILE="${VSWITCHD_LOGFILE:-/var/log/vswitchd.log}"
+VSWITCHD_FILE_LOGLEVEL="${VSWITCHD_FILE_LOGLEVEL:-}"
+VSWITCHD_SYSLOG_LOGLEVEL="${VSWITCHD_SYSLOG_LOGLEVEL:-WARN}"
+VSWITCHD_MEMLEAK_LOGFILE="${VSWITCHD_MEMLEAK_LOGFILE:-}"
+BRCOMPATD_PIDFILE="${BRCOMPATD_PIDFILE:-/var/run/brcompatd.pid}"
+BRCOMPATD_PRIORITY="${BRCOMPATD_PRIORITY:--5}"
+BRCOMPATD_LOGFILE="${BRCOMPATD_LOGFILE:-/var/log/brcompatd.log}"
+BRCOMPATD_FILE_LOGLEVEL="${BRCOMPATD_FILE_LOGLEVEL:-}"
+BRCOMPATD_SYSLOG_LOGLEVEL="${BRCOMPATD_SYSLOG_LOGLEVEL:-WARN}"
+BRCOMPATD_MEMLEAK_LOGFILE="${BRCOMPATD_MEMLEAK_LOGFILE:-}"
function dp_list {
$VSWITCH_BASE/utilities/dpctl showdp | grep '^dp[0-9]\+:' | cut -d':' -f 1
if ! lsmod | grep -q "openflow_mod"; then
action "Inserting openflow module" insmod $VSWITCH_BASE/datapath/linux-2.6/openflow_mod.ko
fi
- if ! lsmod | grep -q "brcompat_mod"; then
+ if [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
action "Inserting brcompat module" insmod $VSWITCH_BASE/datapath/linux-2.6/brcompat_mod.ko
fi
ulimit -c unlimited # Ensure core dump on crash. Will be in '/'.
echo "/var/log/%e-%t" > /proc/sys/kernel/core_pattern
- local syslog_opt="-vANY:SYSLOG:${SYSLOG_LOGLEVEL}"
+ local syslog_opt="-vANY:SYSLOG:${VSWITCHD_SYSLOG_LOGLEVEL}"
local logfile_file_opt=""
local logfile_level_opt=""
- if [ -n "$FILE_LOGLEVEL" ]; then
- logfile_level_opt="-vANY:FILE:${FILE_LOGLEVEL}"
- logfile_file_opt="--log-file=$VSWITCHD_LOG"
+ 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 "$MEMLEAK_LOG" ]; then
- leak_opt="--check-leaks=$MEMLEAK_LOG"
- if [ -e "$MEMLEAK_LOG" ]; then
- mv "$MEMLEAK_LOG" "$MEMLEAK_LOG.prev"
+ 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=""
daemonize_opt=""
fi
#[ "$1" = "update-modules" ] || [ "$1" = "restart" ] || clear_old_bridge_ports
- action "Starting vswitchd" nice -n "$PRIORITY" $strace_opt $valgrind_opt $VSWITCH_BASE/vswitchd/vswitchd -P/var/run/vswitchd.pid $daemonize_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt --brcompat $leak_opt "$VSWITCHD_CONF"
+ action "Starting vswitchd" nice -n "$VSWITCHD_PRIORITY" $strace_opt $valgrind_opt $VSWITCH_BASE/vswitchd/vswitchd -P"$VSWITCHD_PIDFILE" $daemonize_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF"
# Always attempt to force bridge interfaces up because otherwise
# vswitch and XAPI interact badly on startup
sleep 2 # Give time for vswitch to get up and running.
}
function stop {
- if [ -f /var/run/vswitchd.pid ]; then
- local pid=$(cat /var/run/vswitchd.pid)
+ if [ "$1" == "update-modules" ] && [ -n "$BRCOMPATD_PIDFILE" ] && [ -e "$BRCOMPATD_PIDFILE" ]; then
+ printf "brcompatd must be stopped to allow module unloading.\n"
+ exit 1
+ fi
+ if [ -f "$VSWITCHD_PIDFILE" ]; then
+ local pid=$(cat "$VSWITCHD_PIDFILE")
action "Killing vswitchd ($pid)" kill -TERM $pid
fi
- if [ -e /var/run/vswitchd.pid ]; then
- rm -f /var/run/vswitchd.pid
+ if [ -e "$VSWITCHD_PIDFILE" ]; then
+ rm -f "$VSWITCHD_PIDFILE"
fi
if [ "$1" = "update-modules" ]; then
for dp in $(dp_list); do
action "Shutting down datapath interface: $intf" ifdown "$intf"
fi
done
- action "Removing brcompat module" rmmod brcompat_mod.ko
+ if [ -n "$BRCOMPATD_PIDFILE" ]; then
+ action "Removing brcompat module" rmmod brcompat_mod.ko
+ fi
action "Removing openflow module" rmmod openflow_mod.ko
fi
}
start update-modules
;;
reload)
- if [ -f /var/run/vswitchd.pid ]; then
- kill -HUP $(cat /var/run/vswitchd.pid)
+ if [ -f "$VSWITCHD_PIDFILE" ]; then
+ kill -HUP $(cat "$VSWITCHD_PIDFILE")
fi
;;
strace)
shift
- strace -p $(cat /var/run/vswitchd.pid) "$@"
+ strace -p $(cat "$VSWITCHD_PIDFILE") "$@"
;;
unload)
stop update-modules
--- /dev/null
+#!/bin/bash
+#
+# vswitch-brcompatd
+#
+# chkconfig: 2345 09 91
+# description: Manage vswitch kernel modules and user-space daemon
+#
+
+. /etc/init.d/functions
+
+test -e /etc/sysconfig/vswitch && . /etc/sysconfig/vswitch
+VSWITCH_BASE="${VSWITCH_BASE:-/root/vswitch/openflow/build}"
+VSWITCHD_CONF="${VSWITCHD_CONF:-/etc/vswitchd.conf}"
+VSWITCHD_PIDFILE="${VSWITCHD_PIDFILE:-/var/run/vswitchd.pid}"
+VSWITCHD_PRIORITY="${VSWITCHD_PRIORITY:--5}"
+VSWITCHD_LOGFILE="${VSWITCHD_LOGFILE:-/var/log/vswitchd.log}"
+VSWITCHD_FILE_LOGLEVEL="${VSWITCHD_FILE_LOGLEVEL:-}"
+VSWITCHD_SYSLOG_LOGLEVEL="${VSWITCHD_SYSLOG_LOGLEVEL:-WARN}"
+VSWITCHD_MEMLEAK_LOGFILE="${VSWITCHD_MEMLEAK_LOGFILE:-}"
+BRCOMPATD_PIDFILE="${BRCOMPATD_PIDFILE:-/var/run/vswitchd.pid}"
+BRCOMPATD_PRIORITY="${BRCOMPATD_PRIORITY:--5}"
+BRCOMPATD_LOGFILE="${BRCOMPATD_LOGFILE:-/var/log/vswitchd.log}"
+BRCOMPATD_FILE_LOGLEVEL="${BRCOMPATD_FILE_LOGLEVEL:-}"
+BRCOMPATD_SYSLOG_LOGLEVEL="${BRCOMPATD_SYSLOG_LOGLEVEL:-WARN}"
+BRCOMPATD_MEMLEAK_LOGFILE="${BRCOMPATD_MEMLEAK_LOGFILE:-}"
+
+function start {
+ if [ -n "$BRCOMPATD_PIDFILE" ]; then
+ printf "No BRCOMPATD_PIDFILE specified. Check /etc/sysconfig/vswitch\n"
+ exit 1
+ fi
+ ulimit -c unlimited # Ensure core dump on crash. Will be in '/'.
+ echo "/var/log/%e-%t" > /proc/sys/kernel/core_pattern
+ local syslog_opt="-vANY:SYSLOG:${BRCOMPATD_SYSLOG_LOGLEVEL}"
+ local logfile_file_opt=""
+ local logfile_level_opt=""
+ 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_LOG" ]; 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_opt="-D"
+ if [ -n "$STRACE_LOG" ] && [ -n "$VALGRIND_LOG" ]; then
+ printf "Can not start with both VALGRIND and STRACE\n"
+ exit 1
+ fi
+ if [ -n "$STRACE_LOG" ]; then
+ strace_opt="strace -o $STRACE_LOG $STRACE_OPT"
+ daemonize_opt=""
+ fi
+ if [ -n "$VALGRIND_LOG" ]; then
+ valgrind_opt="valgrind --log-file=$VALGRIND_LOG $VALGRIND_OPT"
+ daemonize_opt=""
+ fi
+ action "Starting brcompatd" nice -n "$BRCOMPATD_PRIORITY" $strace_opt $valgrind_opt $VSWITCH_BASE/vswitchd/brcompatd -P$BRCOMPATD_PIDFILE --vswitch-pidfile=$VSWITCHD_PIDFILE $daemonize_opt -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt $leak_opt "$VSWITCHD_CONF"
+}
+
+function stop {
+ if [ -f "$BRCOMPAT_PIDFILE" ]; then
+ local pid=$(cat "$BRCOMPATD_PIDFILE")
+ action "Killing brcompatd ($pid)" kill -TERM $pid
+ fi
+ if [ -e "$BRCOMPATD_PIDFILE" ]; then
+ rm -f "$BRCOMPATD_PIDFILE"
+ fi
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ start restart
+ ;;
+ restart-strace)
+ shift
+ stop
+ STRACE_LOG="/var/log/vswitchd.strace" STRACE_OPT="$*" start restart
+ ;;
+ restart-valgrind)
+ shift
+ stop
+ VALGRIND_LOG="/var/log/vswitchd.valgrind" VALGRIND_OPT="$*" start restart
+ ;;
+ strace)
+ shift
+ strace -p $(cat "$BRCOMPATD_PIDFILE") "$@"
+ ;;
+ status)
+ status -p brcompatd.pid brcompatd
+ ;;
+ version)
+ "$VSWITCH_BASE"/vswitchd/brcompatd -V
+ ;;
+ help)
+ printf "vswitch [start|stop|restart|status|version]\n"
+ ;;
+ *)
+ printf "Unknown command: $1\n"
+ exit 1
+ ;;
+esac
-# SYSLOG_LOGLEVEL: Log level at which to log into syslog. If this is null
-# or not set the default is to log to syslog emergency and warning
-# level messages only. The available options are: EMER, WARN, INFO
-# and DBG.
-# SYSLOG_LOGLEVEL="WARN"
-
-# FILE_LOGLEVEL: Log level at which to log into /var/log/vswitchd.log file.
-# Options are the same as for SYSLOG_LOGLEVEL. If this is null or
-# not set the logfile will not be created and nothing will be sent
-# to it. This is the default.
-# FILE_LOGLEVEL=""
-
-# PRIORITY: "nice" priority at which to run vswitchd and secchan processes
-# PRIORITY=-5
-
-# MEMLEAK_LOG: if non-null, must be filename to which memory usage log is
-# written by vswitchd. This log file can be postprocessed to find
-# incorrect memory allocation and free behavior. If null or not set,
-# no log will be generated. Note that generating the log causes a
-# significant performance hit and should only be done when debugging
-# issues.
-# MEMLEAK_LOG=""
+### Configuration options for vswitch
+
+# VSWITCH_BASE: Root directory where vswitch binaries are installed
+# VSWITCH_BASE=/root/vswitch/openflow/build
+
+# VSWITCHD_CONF: File in which vswitchd stores its configuration.
+# VSWITCHD_CONF=/etc/vswitchd.conf
+
+# VSWITCHD_PIDFILE: File in which to store the pid of the running
+# vswitchd.
+# VSWITCHD_PIDFILE=/var/run/vswitchd.pid
+
+# VSWITCHD_PRIORITY: "nice" priority at which to run vswitchd and related
+# processes.
+# VSWITCHD_PRIORITY=-5
+
+# VSWITCHD_LOGFILE: File to send the FILE_LOGLEVEL log messages to.
+# VSWITCHD_LOGFILE=/var/log/vswitchd.log
+
+# VSWITCHD_FILE_LOGLEVEL: Log level at which to log into the
+# VSWITCHD_LOG file. If this is null or not set the logfile will
+# not be created and nothing will be sent to it. This is the
+# default. The available options are: EMER, WARN, INFO and DBG.
+# VSWITCHD_FILE_LOGLEVEL=""
+
+# VSWITCHD_SYSLOG_LOGLEVEL: Log level at which to log into syslog. If
+# this is null or not set the default is to log to syslog
+# emergency and warning level messages only.
+# VSWITCHD_SYSLOG_LOGLEVEL="WARN"
+
+# VSWITCHD_MEMLEAK_LOGFILE: if non-null, must be filename to which memory
+# usage log is written by vswitchd. This log file can be
+# postprocessed to find incorrect memory allocation and free
+# behavior. If null or not set, no log will be generated. Note
+# that generating the log causes a significant performance hit and
+# should only be done when debugging issues.
+# VSWITCHD_MEMLEAK_LOGFILE=""
+
+# BRCOMPATD_PIDFILE: File in which to store the pid of the running
+# brcompatd (the Linux bridge compatibility daemon for vswitchd).
+# If this is the empty string, brcompatd will not be started and
+# the brcompat_mod kernel module will not be inserted. Note that
+# the default is to use brcompat!
+# BRCOMPATD_PIDFILE=/var/run/brcompatd.pid
+
+# BRCOMPATD_PRIORITY: "nice" priority at which to run vswitchd and related
+# processes.
+# BRCOMPATD_PRIORITY=-5
+
+# BRCOMPATD_LOGFILE: File to send the FILE_LOGLEVEL log messages to.
+# BRCOMPATD_LOGFILE=/var/log/brcompatd.log
+
+# BRCOMPATD_FILE_LOGLEVEL: Log level at which to log into the
+# BRCOMPATD_LOG file. If this is null or not set the logfile will
+# not be created and nothing will be sent to it. This is the
+# default. The available options are: EMER, WARN, INFO and DBG.
+# BRCOMPATD_FILE_LOGLEVEL=""
+
+# BRCOMPATD_SYSLOG_LOGLEVEL: Log level at which to log into syslog. If
+# this is null or not set the default is to log to syslog
+# emergency and warning level messages only.
+# BRCOMPATD_SYSLOG_LOGLEVEL="WARN"
+
+# BRCOMPATD_MEMLEAK_LOG: if non-null, must be filename to which memory
+# usage log is written by vswitchd. This log file can be
+# postprocessed to find incorrect memory allocation and free
+# behavior. If null or not set, no log will be generated. Note
+# that generating the log causes a significant performance hit and
+# should only be done when debugging issues.
+# BRCOMPATD_MEMLEAK_LOG=""