From: Ben Pfaff Date: Wed, 11 Feb 2009 23:32:46 +0000 (-0800) Subject: vswitch: Add startup and config files for the XenServer build. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=011cd26b69134d2d0307d4a7f987d0e84cd0de4e;p=openvswitch vswitch: Add startup and config files for the XenServer build. --- diff --git a/vswitchd/etc/README b/vswitchd/etc/README new file mode 100644 index 00000000..0717652b --- /dev/null +++ b/vswitchd/etc/README @@ -0,0 +1,3 @@ +The files in this subdirectory are intended to be installed into the +/etc directory of a XenServer. They are added to the XenServer +distribution tarball by the automatic build system. diff --git a/vswitchd/etc/init.d/vswitch b/vswitchd/etc/init.d/vswitch new file mode 100755 index 00000000..b27099db --- /dev/null +++ b/vswitchd/etc/init.d/vswitch @@ -0,0 +1,125 @@ +#!/bin/bash +# +# vswitch +# +# chkconfig: 2345 05 95 +# description: Manage vswitch kernel modules and user-space daemon +# + +. /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:-}" + +VSWITCH_BASE=/root/vswitch/openflow/build +VSWITCHD_CONF=/etc/vswitchd.conf +BRCOMPAT_CONF=/etc/vswitchd.brcompat.conf +VSWITCHD_LOG=/var/log/vswitchd.log + +function dp_intf { + $VSWITCH_BASE/utilities/dpctl show nl:$1 | grep '^ LOCAL(' | cut -d'(' -f2 | cut -d')' -f1 +} + +function start { + 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 + action "Inserting brcompat module" insmod $VSWITCH_BASE/datapath/linux-2.6/brcompat_mod.ko + fi + if [ "$1" != "restart" ]; then + # If we are not doing a restart, then presumably Xen's xapi will create all the bridges, etc. + # so the existing config file will just cause vswitchd to add a lot of useless ports + # which it will then conclude don't have any associated interfaces. Therefore, we just + # nuke the config file before vswitchd is initially brought up. + # For debugging purposes, we save teh configuration file as it was when the system + # came up. + cp "$BRCOMPAT_CONF" "$BRCOMPAT_CONF.last" + rm -f "$BRCOMPAT_CONF" + touch "$BRCOMPAT_CONF" + fi + ulimit -c unlimited # Ensure core dump on crash. Will be in '/'. + local syslog_opt="-vANY:SYSLOG:${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" + 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.last" + fi + fi + PATH=$VSWITCH_BASE/secchan:$PATH action "Starting vswitchd" nice -n "$PRIORITY" $VSWITCH_BASE/vswitchd/vswitchd -P/var/run/vswitchd.pid -D -vANY:CONSOLE:EMER $syslog_opt $logfile_level_opt $logfile_file_opt -F "$VSWITCHD_CONF" -F "$BRCOMPAT_CONF" -b "$BRCOMPAT_CONF" $leak_opt + if [ "$1" = "restart" ]; then + sleep 2 # Give time for vswitch to get up and running. + i=0 + while test $i -lt 256; do + if $VSWITCH_BASE/utilities/dpctl show nl:$i >/dev/null 2>&1; then + intf=$(dp_intf $i) + if [ -e "/etc/sysconfig/network-scripts/ifcfg-$intf" ]; then + action "Bringing up datapath interface: $intf" ifup "$intf" + fi + fi + i=$((i + 1)) + done + fi +} + +function stop { + if [ -f /var/run/vswitchd.pid ]; then + action "Killing vswitchd" kill -TERM $(cat /var/run/vswitchd.pid) + fi + if [ -e /var/run/vswitchd.pid ]; then + rm -f /var/run/vswitchd.pid + fi + if [ "$1" = "restart" ]; then + i=0 + while test $i -lt 256; do + if $VSWITCH_BASE/utilities/dpctl show nl:$i >/dev/null 2>&1; then + intf=$(dp_intf $i) + if [ -e "/etc/sysconfig/network-scripts/ifcfg-$intf" ]; then + action "Shutting down datapath interface: $intf" ifdown "$intf" + fi + action "Removing openflow datapath $i" $VSWITCH_BASE/utilities/dpctl deldp nl:$i + fi + i=$((i + 1)) + done + action "Removing brcompat module" rmmod brcompat_mod.ko + action "Removing openflow module" rmmod openflow_mod.ko + fi +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop restart + start restart + ;; + reload) + if [ -f /var/run/vswitchd.pid ]; then + kill -HUP $(cat /var/run/vswitchd.pid) + fi + ;; + unload) + stop restart + ;; + status) + status -p vswitchd.pid vswitchd + ;; + *) + printf "Unknown command: $1\n" + exit 1 + ;; +esac diff --git a/vswitchd/etc/logrotate.d/vswitch b/vswitchd/etc/logrotate.d/vswitch new file mode 100644 index 00000000..97e0e793 --- /dev/null +++ b/vswitchd/etc/logrotate.d/vswitch @@ -0,0 +1,7 @@ +/var/log/vswitchd.log { + sharedscripts + postrotate + # Send sighup to vswitch which will cause it to reopen its log files. + /sbin/service vswitch reload + endscript +} diff --git a/vswitchd/etc/sysconfig/vswitch.example b/vswitchd/etc/sysconfig/vswitch.example new file mode 100644 index 00000000..3b244cd1 --- /dev/null +++ b/vswitchd/etc/sysconfig/vswitch.example @@ -0,0 +1,23 @@ +# 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="" + diff --git a/vswitchd/etc/vswitchd.brcompat.conf b/vswitchd/etc/vswitchd.brcompat.conf new file mode 100644 index 00000000..e69de29b diff --git a/vswitchd/etc/vswitchd.conf b/vswitchd/etc/vswitchd.conf new file mode 100644 index 00000000..e69de29b