From: Ben Pfaff Date: Fri, 17 Jun 2011 19:24:31 +0000 (-0700) Subject: Refactor initscripts into distro-independent and distro-specific pieces. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43bb5f82ec051f335a5c5a8975150ec6352d5d73;p=openvswitch Refactor initscripts into distro-independent and distro-specific pieces. This should make it easier to add OVS support to new distributions. --- diff --git a/Makefile.am b/Makefile.am index f0e75711..ea6df2aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,9 +61,12 @@ noinst_man_MANS = noinst_PROGRAMS = noinst_SCRIPTS = OVSIDL_BUILT = +scripts_SCRIPTS = SUFFIXES = check_DATA = +scriptsdir = $(pkgdatadir)/scripts + # This ensures that files added to EXTRA_DIST are always distributed, # even if they are inside an Automake if...endif conditional block that is # disabled by some particular "configure" run. For more information, see: @@ -85,9 +88,12 @@ SUFFIXES += .in -e 's,[@]PYTHON[@],$(PYTHON),g' \ -e 's,[@]RUNDIR[@],$(RUNDIR),g' \ -e 's,[@]VERSION[@],$(VERSION),g' \ + -e 's,[@]BUILDNR[@],$(BUILDNR),g' \ -e 's,[@]localstatedir[@],$(localstatedir),g' \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ + -e 's,[@]bindir[@],$(bindir),g' \ + -e 's,[@]sbindir[@],$(sbindir),g' \ -e 's,[@]abs_top_srcdir[@],$(abs_top_srcdir),g' \ -e 's,[@]ovsdbmonitordir[@],$(ovsdbmonitordir),g' \ > $@.tmp diff --git a/debian/control b/debian/control index 59651675..25f65ce5 100644 --- a/debian/control +++ b/debian/control @@ -36,7 +36,7 @@ Description: Open vSwitch common components Package: openvswitch-switch Architecture: linux-any Suggests: openvswitch-datapath-module -Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, openvswitch-common (= ${binary:Version}), module-init-tools, procps +Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, openvswitch-common (= ${binary:Version}), module-init-tools, procps, uuid-runtime Description: Open vSwitch switch implementations openvswitch-switch provides the userspace components and utilities for the Open vSwitch kernel-based switch. diff --git a/debian/openvswitch-switch.init b/debian/openvswitch-switch.init index 8ea58660..44ec67c0 100755 --- a/debian/openvswitch-switch.init +++ b/debian/openvswitch-switch.init @@ -1,13 +1,18 @@ #! /bin/sh # -# /etc/init.d/openvswitch-switch +# Copyright (C) 2011 Nicira Networks, Inc. # -# Written by Miquel van Smoorenburg . -# Modified for Debian by Ian Murdock . -# Further changes by Javier Fernandez-Sanguino -# Modified for openvswitch-switch. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: # -# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 @@ -18,359 +23,40 @@ # Short-Description: Open vSwitch switch ### END INIT INFO -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -ovs_vswitchd=/usr/sbin/ovs-vswitchd -ovsdb_server=/usr/bin/ovsdb-server - -(test -x $ovsdb_server && test -x $ovs_vswitchd) || exit 0 - -DODTIME=1 # Time to wait for the server to die, in seconds - # If this value is set too low you might not - # let some servers to die gracefully and - # 'restart' will not work - -# Include openvswitch-switch defaults if available -unset OVSDB_SERVER_OPTS -unset OVS_VSWITCHD_OPTS -unset CORE_LIMIT -unset ENABLE_MONITOR -default=/etc/default/openvswitch-switch -if [ -f $default ] ; then - . $default -fi - -: ${ENABLE_MONITOR:=y} +(test -x /usr/sbin/ovs-vswitchd && test -x /usr/bin/ovsdb-server) || exit 0 set -e -# running_pid pid name -# -# Check if 'pid' is a process named 'name' -running_pid() -{ - local pid=$1 name=$2 - [ -z "$pid" ] && return 1 - [ ! -d /proc/$pid ] && return 1 - cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1` - # Is this the expected child? - case $cmd in - $name|*/$name) - return 0 - ;; - *) - return 1 - ;; - esac -} - -# running name -# -# Checks for a running process named 'name' by looking for a pidfile -# named /var/run/openvswitch/${name}.pid -running() -{ - local name=$1 - local pidfile=/var/run/openvswitch/${name}.pid - - # No pidfile, probably no daemon present - [ ! -f "$pidfile" ] && return 1 - - # Obtain the pid and check it against the binary name - pid=`cat $pidfile` - running_pid $pid $name || return 1 - return 0 -} - -# force_stop name -# -# Checks for a running process named 'name', by looking for a pidfile -# named /var/run/openvswitch/${name}.pid, and then kills it and waits -# for it to die. -force_stop() { - local name=$1 - local pidfile=/var/run/openvswitch/${name}.pid - - [ ! -f "$pidfile" ] && return - if running $name; then - kill $pid - [ -n "$DODTIME" ] && sleep "$DODTIME" - if running $name; then - kill -KILL $pid - [ -n "$DODTIME" ] && sleep "$DODTIME" - if running $name; then - echo "Cannot kill $name (pid=$pid)!" - exit 1 - fi - fi - fi - rm -f $pidfile - return 0 -} - -must_succeed() { - echo -n "$1: " - shift - if "$@"; then - echo "success." - else - echo " ERROR." - exit 1 - fi -} - -check_op() { - echo -n "$1: " - shift - if "$@"; then - echo "success." - else - echo " ERROR." - fi -} - -# is_module_loaded module -# -# Returns 0 if 'module' is loaded, 1 otherwise. - -is_module_loaded() { - local module=$1 - grep -q "^$module " /proc/modules -} - -# load_module module -# -# Loads 'module' into the running kernel, if it is not already loaded. -load_module() { - local module=$1 - echo -n "Loading $module: " - if is_module_loaded $module; then - echo "already loaded, nothing to do." - elif modprobe $module; then - echo "success." - else - echo "ERROR." - echo "$module has probably not been built for this kernel." - if ! test -d /usr/share/doc/openvswitch-datapath-source; then - echo "Install the openvswitch-datapath-source package, then read" - echo "/usr/share/doc/openvswitch-datapath-source/README.Debian" - else - echo "For instructions, read" - echo "/usr/share/doc/openvswitch-datapath-source/README.Debian" - fi - exit 0 - fi -} - -# unload_module module -# -# Unloads 'module' from the running kernel, if it is loaded. -unload_module() { - local module=$1 - echo -n "Unloading $module: " - if is_module_loaded $module; then - if rmmod $module; then - echo "success." - else - echo "ERROR." - exit 1 - fi - else - echo "not loaded, nothing to do." - fi -} - -unload_modules() { - if is_module_loaded openvswitch_mod; then - for dp in $(ovs-dpctl dump-dps); do - echo -n "Deleting datapath $dp: " - if ovs-dpctl del-dp $dp; then - echo "success." - else - echo "ERROR." - fi - done - fi - unload_module openvswitch_mod -} - -set_system_info() { - ovs_version=`ovs-vswitchd --version | sed 's/.*) //;1q'` - ovs-vsctl --no-wait --timeout=5 set Open_vSwitch . \ - ovs-version="$ovs_version" - - if (lsb_release --id) >/dev/null 2>&1; then - system_type=`lsb_release --id -s` - system_release=`lsb_release --release -s` - system_codename=`lsb_release --codename -s` - system_version="${system_release}-${system_codename}" - - ovs-vsctl --no-wait --timeout=5 set Open_vSwitch . \ - system-type="$system_type" \ - system-version="$system_version" - fi -} +test -e /etc/default/openvswitch-switch && . /etc/default/openvswitch-switch -case "$1" in +ovs_ctl=/usr/share/openvswitch/scripts/ovs-ctl +case $1 in start) - conf_file=/etc/openvswitch/conf.db - schema_file=/usr/share/openvswitch/vswitch.ovsschema - schema_ver=`ovsdb-tool schema-version "$schema_file"` - - load_module openvswitch_mod - - if test -n "$CORE_LIMIT"; then - check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT" - fi - - # Create an empty configuration database if it doesn't exist. - if test ! -e $conf_file; then - # Create configuration database. - ovsdb-tool -vANY:console:emer create $conf_file $schema_file - elif test "X`ovsdb-tool needs-conversion $conf_file $schema_file`" != Xno; then - # Back up the old version. - version=`ovsdb-tool db-version "$conf_file"` - cksum=`ovsdb-tool db-cksum "$conf_file" | awk '{print $1}'` - cp "$conf_file" "$conf_file.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 $conf_file - - # Upgrade or downgrade schema and compact database. - ovsdb-tool -vANY:console:emer convert $conf_file $schema_file - fi - - if test "$ENABLE_MONITOR" = y; then - monitor_opt=--monitor - else - monitor_opt= - fi + set $ovs_ctl start --system-id=random + if test X"$FORCE_COREFILES" != X; then + set "$@" --force-oorefiles="$FORCE_COREFILES" + fi - if [ ! -d /var/run/openvswitch ]; then - install -d -m 755 -o root -g root /var/run/openvswitch - fi + # Allow GRE traffic. + test ! -x /sbin/iptables || /sbin/iptables -I INPUT -p gre -j ACCEPT - if [ ! -d /var/log/openvswitch ]; then - install -d -m 755 -o root -g root /var/log/openvswitch - fi - - if [ ! -d /var/log/openvswitch/cores ]; then - install -d -m 755 -o root -g root /var/log/openvswitch/cores - fi - - # Start ovsdb-server. - set -- - set -- "$@" $conf_file - set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err - set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log - set -- "$@" --detach --no-chdir --pidfile $monitor_opt - set -- "$@" --remote punix:/var/run/openvswitch/db.sock - set -- "$@" --remote db:Open_vSwitch,manager_options - set -- "$@" --private-key=db:SSL,private_key - set -- "$@" --certificate=db:SSL,certificate - set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert - set -- "$@" $OVSDB_SERVER_OPTS - echo -n "Starting ovsdb-server: " - start-stop-daemon --start --quiet --oknodo \ - --pidfile /var/run/openvswitch/ovsdb-server.pid \ - --chdir /var/log/openvswitch/cores \ - --exec $ovsdb_server -- "$@" - if running ovsdb-server; then - echo "ovsdb-server." - else - echo " ERROR." - fi - - ovs-vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schema_ver" - - set_system_info - - # Start ovs-vswitchd. - set -- - set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err - set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log - set -- "$@" --detach --no-chdir --pidfile $monitor_opt - set -- "$@" unix:/var/run/openvswitch/db.sock - set -- "$@" $OVS_VSWITCHD_OPTS - echo -n "Starting ovs-vswitchd: " - start-stop-daemon --start --quiet --oknodo \ - --pidfile /var/run/openvswitch/ovs-vswitchd.pid \ - --chdir /var/log/openvswitch/cores \ - --exec $ovs_vswitchd -- "$@" - if running ovs-vswitchd; then - echo "ovs-vswitchd." - else - echo " ERROR." - fi - ;; - stop) - echo -n "Stopping ovs-vswitchd: " - start-stop-daemon --stop --quiet --oknodo --retry 5 \ - --pidfile /var/run/openvswitch/ovs-vswitchd.pid \ - --chdir /var/log/openvswitch/cores \ - --exec $ovs_vswitchd - echo "ovs-vswitchd." - - echo -n "Stopping ovsdb-server: " - start-stop-daemon --stop --quiet --oknodo --retry 5 \ - --pidfile /var/run/openvswitch/ovsdb-server.pid \ - --chdir /var/log/openvswitch/cores \ - --exec $ovsdb_server - echo "ovsdb-server." - ;; - force-stop) - echo -n "Forcefully stopping ovs-vswitchd: " - force_stop ovs-vswitchd - if ! running ovs-vswitchd; then - echo "ovs-vswitchd." - else - echo " ERROR." - fi - - echo -n "Forcefully stopping ovsdb-server: " - force_stop ovsdb-server - if ! running ovsdb-server; then - echo "ovsdb-server." - else - echo " ERROR." - fi - ;; - unload) - unload_modules + "$@" ;; - reload) + stop | force-stop) + $ovs_ctl stop ;; - force-reload) - # Nothing to do, since ovs-vswitchd automatically reloads - # whenever its configuration changes, and ovsdb-server doesn't - # have anything to reload. + reload | force-reload) + # The OVS daemons keep up-to-date. ;; restart) $0 stop || true $0 start ;; status) - for daemon in ovs-vswitchd ovsdb-server; do - echo -n "$daemon is " - if running $daemon; then - echo "running" - else - echo "not running." - exit 1 - fi - done + $ovs_ctl status ;; *) - N=/etc/init.d/openvswitch-switch - echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2 + echo "Usage: $0 {start|stop|restart|force-reload|status|force-stop}" >&2 exit 1 ;; esac diff --git a/debian/openvswitch-switch.install b/debian/openvswitch-switch.install index 088b8606..bfffe100 100644 --- a/debian/openvswitch-switch.install +++ b/debian/openvswitch-switch.install @@ -1,5 +1,7 @@ _debian/ovsdb/ovsdb-server usr/bin _debian/utilities/ovs-dpctl usr/sbin +_debian/utilities/ovs-ctl usr/share/openvswitch/scripts +_debian/utilities/ovs-lib.sh usr/share/openvswitch/scripts _debian/utilities/ovs-vsctl usr/sbin _debian/utilities/ovs-pcap usr/bin _debian/utilities/ovs-tcpundump usr/bin diff --git a/debian/openvswitch-switch.template b/debian/openvswitch-switch.template index e322badc..82f4e52f 100644 --- a/debian/openvswitch-switch.template +++ b/debian/openvswitch-switch.template @@ -5,21 +5,5 @@ # automatically at boot time. It can be started immediately with # /etc/init.d/openvswitch-switch start -# OVSDB_SERVER_OPTS: Additional options to pass to ovsdb-server, -# e.g. "--fail=open" -OVSDB_SERVER_OPTS= - -# OVS_VSWITCHD_OPTS: Additional options to pass to ovs-vswitchd, -# e.g. "--fail=open" -OVS_VSWITCHD_OPTS= - -# CORE_LIMIT: Maximum size for core dumps. -# -# Leaving this unset will use the system default. Setting it to 0 -# will disable core dumps. Setting it to "unlimited" will dump all -# core files regardless of size. -#CORE_LIMIT=unlimited - -# ENABLE_MONITOR: If 'y' then monitor daemon processes and restart them -# if they die due to an error signal. -# ENABLE_MONITOR=y +# FORCE_COREFILES: If 'yes' then core files will be enabled. +# FORCE_COREFILES=yes diff --git a/debian/rules b/debian/rules index 68069801..76d11a05 100755 --- a/debian/rules +++ b/debian/rules @@ -36,7 +36,7 @@ configure-stamp: cd _debian && ( \ test -e Makefile || \ ../configure --prefix=/usr --localstatedir=/var --enable-ssl \ - --with-build-number=$(BUILD_NUMBER) \ + --sysconfdir=/etc --with-build-number=$(BUILD_NUMBER) \ CFLAGS="$(CFLAGS)" $(DATAPATH_CONFIGURE_OPTS)) touch configure-stamp diff --git a/utilities/automake.mk b/utilities/automake.mk index 47e3a1f7..7c82b739 100644 --- a/utilities/automake.mk +++ b/utilities/automake.mk @@ -12,11 +12,14 @@ bin_SCRIPTS += \ utilities/ovs-vlan-test endif noinst_SCRIPTS += utilities/ovs-pki-cgi utilities/ovs-parse-leaks +scripts_SCRIPTS += utilities/ovs-ctl utilities/ovs-lib.sh EXTRA_DIST += \ utilities/ovs-appctl.8.in \ utilities/ovs-controller.8.in \ + utilities/ovs-ctl.in \ utilities/ovs-dpctl.8.in \ + utilities/ovs-lib.sh.in \ utilities/ovs-ofctl.8.in \ utilities/ovs-parse-leaks.8 \ utilities/ovs-parse-leaks.in \ @@ -35,8 +38,10 @@ EXTRA_DIST += \ utilities/ovs-vsctl.8.in DISTCLEANFILES += \ utilities/ovs-appctl.8 \ + utilities/ovs-ctl \ utilities/ovs-controller.8 \ utilities/ovs-dpctl.8 \ + utilities/ovs-lib.sh \ utilities/ovs-ofctl.8 \ utilities/ovs-parse-leaks \ utilities/ovs-pcap \ @@ -63,6 +68,7 @@ man_MANS += \ utilities/ovs-vlan-bug-workaround.8 \ utilities/ovs-vlan-test.8 \ utilities/ovs-vsctl.8 +dist_man_MANS += utilities/ovs-ctl.8 utilities_ovs_appctl_SOURCES = utilities/ovs-appctl.c utilities_ovs_appctl_LDADD = lib/libopenvswitch.a diff --git a/utilities/ovs-ctl.8 b/utilities/ovs-ctl.8 new file mode 100644 index 00000000..d649d562 --- /dev/null +++ b/utilities/ovs-ctl.8 @@ -0,0 +1,309 @@ +.\" -*- nroff -*- +.de IQ +. br +. ns +. IP "\\$1" +.. +.de ST +. PP +. RS -0.15in +. I "\\$1" +. RE +.. +.TH ovs\-ctl 8 "June 2011" "Open vSwitch" "Open vSwitch Manual" +.ds PN ovs\-ctl +. +.SH NAME +ovs\-ctl \- OVS startup helper script +. +.SH SYNOPSIS +\fBovs\-ctl\fR [\fB\-\-system\-id=random\fR | \fIuuid\fR] +[\fIoptions\fR] \fBstart +.br +\fBovs\-ctl stop +.br +\fBovs\-ctl status +.br +\fBovs\-ctl version +.br +\fBovs\-ctl force-reload-kmod +.br +\fBovs\-ctl help \fR| \fB\-h \fR| \fB\-\-help +.br +\fBovs\-ctl \-\-version +. +.SH DESCRIPTION +. +.PP +The \fBovs\-ctl\fR program starts, stops, and checks the status of +Open vSwitch daemons. It is not meant to be invoked directly by +system administrators but to be called internally by system startup +scripts. +. +.PP +Each of \fBovs\-ctl\fR's commands is described separately below. +. +.SH "The ``start'' command" +. +.PP +The \fBstart\fR command starts Open vSwitch. It performs the +following tasks: +. +.IP 1. +Loads the Open vSwitch kernel module. If this fails, and the Linux +bridge module is loaded but no bridges exist, it tries to unload the +bridge module and tries loading the Open vSwitch kernel module again. +(This is because the Open vSwitch kernel module cannot coexist with +the Linux bridge module before 2.6.37.) +. +.PP +The \fBstart\fR command skips the following steps if +\fBovsdb\-server\fR is already running: +.IP 2. +If the Open vSwitch database file does not exist, it creates it. +If the database does exist, but it has an obsolete version, it +upgrades it to the latest schema. +. +.IP 3. +Starts \fBovsdb-server\fR. +. +.IP 4. +Initializes a few values inside the database. +. +.IP 5. +If the \fB\-\-delete\-bridges\fR option was used, deletes all of the +bridges from the database. +. +.PP +The \fBstart\fR command skips the following step if +\fBovs\-vswitchd\fR is already running: +.IP 6. +Starts \fBovs\-vswitchd\fR. +. +.SS "Options" +.PP +Several command-line options influence the \fBstart\fR command's +behavior. Some form of the following option should ordinarily be +specified: +. +.IP "\fB\-\-system\-id=\fIuuid\fR" +.IQ "\fB\-\-system\-id=random\fR" +This specifies a unique system identifier to store into +\fBexternal-ids:system-id\fR in the database's \fBOpen_vSwitch\fR +table. Remote managers that talk to the Open vSwitch database server +over network protocols use this value to identify and distinguish Open +vSwitch instances, so it should be unique (at least) within OVS +instances that will connect to a single controller. +.IP +When \fBrandom\fR is specified, \fBovs\-ctl\fR will generate a random +ID that persists from one run to another (stored in a file). When +another string is specified \fBovs\-ctl\fR uses it literally. +. +.PP +On systems that have the \fBlsb_release\fR program, \fBovs\-ctl\fR +chooses reasonable defaults for the following options. Other systems +should specify values: +. +.IP "\fB\-\-system\-type=\fItype\fR" +.IQ "\fB\-\-system\-version=\fIversion\fR" +Sets the value to store in the \fBsystem-type\fR and +\fBsystem-version\fR columns, respectively, in the database's +\fBOpen_vSwitch\fR table. Remote managers may use these values to +determine the kind of system to which they are connected (primarily +for display to human administrators). +. +.PP +The following options are also likely to be useful: +. +.IP "\fB\-\-external\-id=\(dq\fIname\fB=\fIvalue\fB\(dq" +Sets \fBexternal-ids:\fIname\fR to \fIvalue\fR in the database's +\fBOpen_vSwitch\fR table. Specifying this option multiple times adds +multiple key-value pairs. +. +.IP "\fB\-\-delete\-bridges\fR" +Ordinarily Open vSwitch bridges persist from one system boot to the +next, as long as the database is preserved. Some environments instead +expect to re-create all of the bridges and other configuration state +on every boot. This option supports that, by deleting all Open +vSwitch bridges after starting \fBovsdb\-server\fR but before starting +\fBovs\-vswitchd\fR. +. +.PP +The following options are less important: +. +.IP "\fB\-\-daemon-cwd=\fIdirectory\fR" +Specifies the current working directory that the OVS daemons should +run from. The default is \fB/\fR (the root directory) if this option +is not specified. (This option is useful because most systems create +core files in a process's current working directory and because a file +system that is in use as a process's current working directory cannot +be unmounted.) +. +.IP "\fB\-\-no\-force\-corefiles\fR" +By default, \fBovs\-ctl\fR enables core dumps for the OVS daemons. +This option disables that behavior. +. +.IP "\fB\-\-no\-mlockall\fR" +By default \fBovs\-ctl\fR passes \fB\-\-mlockall\fR to +\fBovs\-vswitchd\fR, requesting that it lock all of its virtual +memory, preventing it from being paged to disk. This option +suppresses that behavior. +. +.IP "\fB\-\-ovsdb\-server\-priority=\fIniceness\fR" +.IQ "\fB\-\-ovs\-vswitchd\-priority=\fIniceness\fR" +Sets the \fBnice\fR(1) level used for \fBovsdb\-server\fR and +\fBovs\-vswitchd\fR, respectively. Both default to \fB\-10\fR. +. +.PP +The following options control file locations. They should only be +used if the default locations cannot be used. See \fBFILES\fR, below, +for more information. +. +.IP "\fB\-\-db\-file=\fIfile\fR" +Overrides the file name for the OVS database. +. +.IP "\fB\-\-db\-sock=\fIsocket\fR" +Overrides the file name for the Unix domain socket used to connect to +\fBovsdb\-server\fR. +. +.IP "\fB\-\-db\-schema=\fIschema\fR" +Overrides the file name for the OVS database schema. +. +.SH "The ``stop'' command" +. +.PP +The \fBstart\fR command shuts down Open vSwitch. If +\fBovs\-vswitchd\fR is running, kills it and waits for it to +terminate, then it does the same for \fBovsdb\-server\fR. +. +.PP +This command does nothing and finishes successfully if the OVS daemons +aren't running. +. +.SH "The ``status'' command" +. +.PP +The \fBstatus\fR command checks whether the OVS daemons are running +and prints messages with that information. It exits with status 0 if +the daemons are running, 1 otherwise. +. +.SH "The ``version'' command" +. +.PP +The \fBversion\fR command runs \fBovsdb\-server \-\-version\fR and +\fBovs\-vswitchd \-\-version\fR. +. +.SH "The ``force\-reload\-kmod'' command" +. +.PP +The \fBforce\-reload\-kmod\fR command allows upgrading the Open +vSwitch kernel module without rebooting. It performs the following +tasks: +. +.IP 1. +Gets a list of OVS ``internal'' interfaces, that is, network devices +implemented by Open vSwitch. The most common examples of these are +bridge ``local ports''. +. +.IP 2. +Stops the Open vSwitch daemons, as if by a call to \fBovs\-ctl +stop\fR. +. +.IP 3. +Saves the kernel configuration state of the OVS internal interfaces +listed in step 1, including IP and IPv6 addresses and routing table +entries. +. +.IP 4. +Unloads the Open vSwitch kernel module. +. +.IP 5. +Starts OVS back up, as if by a call to \fBovs\-ctl start\fR. This +reloads the kernel module and restarts the OVS daemons. +. +.IP 6. +Restores the kernel configuration state that was saved in step 3. +. +.PP +The steps above are often enough to hot-upgrade a new kernel module +with only a few seconds of downtime. DHCP is a common problem: if the +ISC DHCP client is running on an OVS internal interface, then it will +have to be restarted after completing the above procedure. +. +.PP +Because \fBforce\-kmod\-reload\fR internally stops and starts OVS, it +accepts all of the options accepted by the \fBstart\fR command. +. +.SS "The ``help'' command" +. +Prints a usage message and exits successfully. +. +.SH "EXIT STATUS" +. +\fBovs\-ctl\fR exits with status 0 on success and nonzero on failure. +The \fBstart\fR command is considered to succeed if OVS is already +started; the \fBstop\fR command is considered to succeed if OVS is +already stopped. +. +.SH "ENVIRONMENT" +. +The following environment variables affect \fBovs\-ctl\fR: +. +.IP "\fBPATH\fR" +\fBovs\-ctl\fR does not hardcode the location of any of the programs +that it runs. \fBovs\-ctl\fR will add the \fIsbindir\fR and +\fIbindir\fR that were specified at \fBconfigure\fR time to +\fBPATH\fR, if they are not already present. +. +.IP "\fBOVS_LOGDIR\fR" +.IQ "\fBOVS_RUNDIR\fR" +.IQ "\fBOVS_SYSCONFDIR\fR" +.IQ "\fBOVS_PKGDATADIR\fR" +.IQ "\fBOVS_BINDIR\fR" +.IQ "\fBOVS_SBINDIR\fR" +Setting one of these variables in the environment overrides the +respective \fBconfigure\fR option, both for \fBovs\-ctl\fR itself and +for the other Open vSwitch programs that it runs. +. +.SH "FILES" +. +\fBovs\-ctl\fR uses the following files: +. +.IP "\fBovs\-lib.sh" +Shell function library used internally by \fBovs\-ctl\fR. It must be +installed in the same directory as \fBovs\-ctl\fR. +. +.IP "\fIlogdir\fB/\fIdaemon\fB.log\fR" +Per-daemon logfiles. +. +.IP "\fIrundir\fB/\fIdaemon\fB.pid\fR" +Per-daemon pidfiles to track whether a daemon is running and with what +process ID. +. +.IP "\fIpkgdatadir\fB/vswitch.ovsschema\fR" +The OVS database schema used to initialize the database (use +\fB\-\-db\-schema to override this location). +. +.IP "\fIsysconfdir\fB/openvswitch/conf.db\fR" +The OVS database (use \fB\-\-db\-file\fR to override this location). +. +.IP "\fIrundir\fB/openvswitch/db.sock\fR" +The Unix domain socket used for local communication with +\fBovsdb\-server\fR (use \fB\-\-db\-sock\fR to override this +location). +. +.IP "\fIsysconfdir\fB/openvswitch/system-id.conf\fR" +The persistent system UUID created and read by +\fB\-\-system\-id=random\fR. +. +.SH "EXAMPLE" +. +.PP +The files \fBdebian/openvswitch\-switch.init\fR and +\fBxenserver/etc_init.d_openvswitch\fR in the Open vSwitch source +distribution are good examples of how to use \fBovs\-ctl\fR. +. +.SH "SEE ALSO" +. +\fBREADME\fR, \fBINSTALL.LINUX\fR, \fBovsdb\-server\fR(8), +\fBovs\-vswitchd\fR(8). diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in new file mode 100755 index 00000000..923e1b53 --- /dev/null +++ b/utilities/ovs-ctl.in @@ -0,0 +1,445 @@ +#! /bin/sh +# 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. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +case $0 in + */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;; + *) dir0=./ ;; +esac +. "$dir0/ovs-lib.sh" || exit 1 + +for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do + case :$PATH: in + *:$dir:*) ;; + *) PATH=$PATH:$dir ;; + esac +done + +## ----- ## +## start ## +## ----- ## + +insert_modules_if_required () { + # If openvswitch_mod is already loaded then we're done. + test -e /sys/module/openvswitch_mod && return 0 + + # Load openvswitch_mod. If that's successful then we're done. + action "Inserting openvswitch module" modprobe openvswitch_mod && return 0 + + # If the bridge module is loaded, then that might be blocking + # openvswitch_mod. Try to unload it, if there are no bridges. + test -e /sys/module/bridge || return 1 + 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)" + return 1 + fi + action "removing bridge module" rmmod bridge || return 1 + + # Try loading openvswitch_mod again. + action "Inserting openvswitch module" modprobe openvswitch_mod +} + +ovs_vsctl () { + ovs-vsctl --no-wait --timeout=5 "$@" +} + +ovsdb_tool () { + ovsdb-tool -vANY:console:emer "$@" +} + +upgrade_db () { + schemaver=`ovsdb_tool schema-version "$DB_SCHEMA"` + if test ! -e "$DB_FILE"; then + log_warning_msg "$DB_FILE does not exist" + install -d -m 755 -o root -g root `dirname $DB_FILE` + + action "Creating empty database $DB_FILE" true + ovsdb_tool create "$DB_FILE" "$DB_SCHEMA" + elif test X"`ovsdb_tool needs-conversion "$DB_FILE" "$DB_SCHEMA"`" != Xno; then + # Back up the old version. + version=`ovsdb_tool db-version "$DB_FILE"` + cksum=`ovsdb_tool db-cksum "$DB_FILE" | awk '{print $1}'` + cp "$DB_FILE" "$DB_FILE.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 compact "$DB_FILE" + + # Upgrade or downgrade schema. + ovsdb_tool convert "$DB_FILE" "$DB_SCHEMA" + fi +} + +set_system_ids () { + set ovs_vsctl set Open_vSwitch . + + OVS_VERSION=`ovs-vswitchd --version | sed 's/.*) //;1q'` + set "$@" ovs-version="$OVS_VERSION" + + case $SYSTEM_ID in + random) + id_file=$etcdir/system-id.conf + uuid_file=$etcdir/install_uuid.conf + if test -e "$id_file"; then + SYSTEM_ID=`cat "$id_file"` + elif test -e "$uuid_file"; then + # Migrate from old file name. + . "$uuid_file" + SYSTEM_ID=$INSTALLATION_UUID + echo "$SYSTEM_ID" > "$id_file" + elif SYSTEM_ID=`uuidgen`; then + echo "$SYSTEM_ID" > "$id_file" + else + log_failure_msg "missing uuidgen, could not generate system ID" + fi + ;; + + '') + log_failure_msg "system ID not configured, please use --system-id" + ;; + + *) + ;; + esac + set "$@" external-ids:system-id="\"$SYSTEM_ID\"" + + if test X"$SYSTEM_TYPE" != X; then + set "$@" system-type="\"$SYSTEM_TYPE\"" + else + log_failure_msg "no default system type, please use --system-type" + fi + + if test X"$SYSTEM_VERSION" != X; then + set "$@" system-version="\"$SYSTEM_VERSION\"" + else + log_failure_msg "no default system version, please use --system-version" + fi + + action "Configuring Open vSwitch system IDs" "$@" $extra_ids +} + +start () { + if test X"$FORCE_COREFILES" = Xyes; then + ulimit -Sc 67108864 + fi + + insert_modules_if_required || return 1 + + if daemon_is_running ovsdb-server; then + log_success_msg "ovsdb-server is already running" + else + # Create initial database or upgrade database schema. + upgrade_db || return 1 + + # Start ovsdb-server. + set ovsdb-server "$DB_FILE" + set "$@" -vANY:CONSOLE:EMER -vANY:SYSLOG:ERR -vANY:FILE:INFO + set "$@" --remote=punix:"$DB_SOCK" + set "$@" --remote=db:Open_vSwitch,manager_options + set "$@" --private-key=db:SSL,private_key + set "$@" --certificate=db:SSL,certificate + set "$@" --bootstrap-ca-cert=db:SSL,ca_cert + start_daemon "$OVSDB_SERVER_PRIORITY" "$@" || return 1 + + # Initialize database settings. + ovs_vsctl -- init -- set Open_vSwitch . db-version="$schemaver" \ + || return 1 + set_system_ids || return 1 + if test X"$DELETE_BRIDGES" = Xyes; then + for bridge in `ovs_vsctl list-br`; do + ovs_vsctl del-br $bridge + done + fi + fi + + if daemon_is_running ovs-vswitchd; then + log_success_msg "ovs-vswitchd is already running" + else + # Increase the limit on the number of open file descriptors since + # ovs-vswitchd needs a few per bridge + ulimit -n 4096 + + # Start ovs-vswitchd. + set ovs-vswitchd unix:"$DB_SOCK" + set "$@" -vANY:CONSOLE:EMER -vANY:SYSLOG:ERR -vANY:FILE:INFO + if test X"$MLOCKALL" != Xno; then + set "$@" --mlockall + fi + start_daemon "$VSWITCHD_PRIORITY" "$@" + fi +} + +## ---- ## +## stop ## +## ---- ## + +stop () { + stop_daemon ovs-vswitchd + stop_daemon ovsdb-server +} + +## ----------------- ## +## force-reload-kmod ## +## ----------------- ## + +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 or not. + # + # - 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 +} + +force_reload_kmod () { + ifaces=`internal_interfaces` + action "Detected internal interfaces: $ifaces" true + + stop + + script=`mktemp` + action "Save interface configuration to $script" true + if "$datadir/scripts/ovs-save" $ifaces > "$script"; then + : + else + log_warning_msg "Failed to save configuration, not replacing kernel module" + start + exit 1 + fi + chmod +x "$script" + + for dp in `ovs-dpctl dump-dps`; do + action "Removing datapath: $dp" "$dpctl" del-dp "$dp" + done + + if test -e /sys/module/openvswitch_mod; then + action "Removing openvswitch module" rmmod openvswitch_mod + fi + + start + + action "Restore interface configuration from $script" "$script" +} + +## ---- ## +## main ## +## ---- ## + +set_defaults () { + SYSTEM_ID= + + DELETE_BRIDGES=no + + DAEMON_CWD=/ + FORCE_COREFILES=yes + MLOCKALL=yes + OVSDB_SERVER_PRIORITY=-10 + OVS_VSWITCHD_PRIORITY=-10 + + DB_FILE=$etcdir/conf.db + DB_SOCK=$rundir/db.sock + DB_SCHEMA=$datadir/vswitch.ovsschema + + if (lsb_release --id) >/dev/null 2>&1; then + SYSTEM_TYPE=`lsb_release --id -s` + system_release=`lsb_release --release -s` + system_codename=`lsb_release --codename -s` + SYSTEM_VERSION="${system_release}-${system_codename}" + else + SYSTEM_TYPE=unknown + SYSTEM_VERSION=unknown + fi +} + +usage () { + set_defaults + cat <&2 "$0: unknown option \"$arg\" (use --help for help)" + return + fi + eval $var=\$value +} + +set_defaults +extra_ids= +command= +for arg +do + case $arg in + -h | --help) + usage + ;; + -V | --version) + echo "$0 (Open vSwitch) $VERSION$BUILDNR" + exit 0 + ;; + --external-id=*) + value=`expr X"$arg" : 'X[^=]*=\(.*\)'` + case $value in + *=*) + extra_ids="$extra_ids external-ids:$value" + ;; + *) + echo >&2 "$0: --external-id argument not in the form \"key=value\"" + exit 1 + ;; + esac + ;; + --[a-z]*=*) + option=`expr X"$arg" : 'X--\([^=]*\)'` + value=`expr X"$arg" : 'X[^=]*=\(.*\)'` + type=string + set_option + ;; + --no-[a-z]*) + option=`expr X"$arg" : 'X--no-\(.*\)'` + value=no + type=bool + set_option + ;; + --[a-z]*) + option=`expr X"$arg" : 'X--\(.*\)'` + value=yes + type=bool + set_option + ;; + -*) + echo >&2 "$0: unknown option \"$arg\" (use --help for help)" + exit 1 + ;; + *) + if test X"$command" = X; then + command=$arg + else + echo >&2 "$0: exactly one non-option argument required (use --help for help)" + exit 1 + fi + ;; + esac +done +case $command in + start) + start + ;; + stop) + stop + ;; + status) + daemon_status ovsdb-server && daemon_status ovs-vswitchd + ;; + version) + ovsdb-server --version && ovs-vswitchd --version + ;; + force-reload-kmod) + force_reload_kmod + ;; + help) + usage + ;; + '') + echo >&2 "$0: missing command name (use --help for help)" + exit 1 + ;; + *) + echo >&2 "$0: unknown command \"$command\" (use --help for help)" + exit 1 + ;; +esac + diff --git a/utilities/ovs-lib.sh.in b/utilities/ovs-lib.sh.in new file mode 100644 index 00000000..179d85e1 --- /dev/null +++ b/utilities/ovs-lib.sh.in @@ -0,0 +1,166 @@ +# This is a shell function library sourced by some Open vSwitch scripts. +# It is not intended to be invoked on its own. + +# 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. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +## ----------------- ## +## configure options ## +## ----------------- ## + +# All of these should be substituted by the Makefile at build time. +logdir=${OVS_LOGDIR-'@LOGDIR@'} # /var/log/openvswitch +rundir=${OVS_RUNDIR-'@RUNDIR@'} # /var/run/openvswitch +sysconfdir=${OVS_SYSCONFDIR-'@sysconfdir@'} # /etc +etcdir=$sysconfdir/openvswitch # /etc/openvswitch +datadir=${OVS_PKGDATADIR-'@pkgdatadir@'} # /usr/share/openvswitch +bindir=${OVS_BINDIR-'@bindir@'} # /usr/bin +sbindir=${OVS_SBINDIR-'@sbindir@'} # /usr/sbin + +VERSION='@VERSION@' +case @BUILDNR@ in + [1-9]*) BUILDNR='+build@BUILDNR@' ;; + *) BUILDNR= ;; +esac + +LC_ALL=C; export LC_ALL + +## ------------- ## +## LSB functions ## +## ------------- ## + +# Use the system's own implementations if it has any. +if test -e /etc/init.d/functions; then + . /etc/init.d/functions +elif test -e /etc/rc.d/init.d/functions; then + . /etc/rc.d/init.d/functions +elif test -e /lib/lsb/init-functions; then + . /lib/lsb/init-functions +fi + +# Implement missing functions (e.g. OpenSUSE lacks 'action'). +if type log_success_msg >/dev/null 2>&1; then :; else + log_success_msg () { + printf '%s.\n' "$*" + } +fi +if type log_failure_msg >/dev/null 2>&1; then :; else + log_failure_msg () { + printf '%s ... failed!\n' "$*" + } +fi +if type log_warning_msg >/dev/null 2>&1; then :; else + log_warning_msg () { + printf '%s ... (warning).\n' "$*" + } +fi +if type action >/dev/null 2>&1; then :; else + action () { + STRING=$1 + shift + "$@" + rc=$? + if test $rc = 0; then + log_success_msg "$STRING" + else + log_failure_msg "$STRING" + fi + return $rc + } +fi + +## ------- ## +## Daemons ## +## ------- ## + +start_daemon () { + priority=$1 + shift + daemon=$1 + + # drop core files in a sensible place + test -d "$DAEMON_CWD" || install -d -m 755 -o root -g root "$DAEMON_CWD" + set "$@" --no-chdir + cd "$DAEMON_CWD" + + # log file + test -d "$logdir" || install -d -m 755 -o root -g root "$logdir" + set "$@" --log-file="$logdir/$daemon.log" + + # pidfile and monitoring + test -d "$rundir" || install -d -m 755 -o root -g root "$rundir" + set "$@" --pidfile="$rundir/$daemon.pid" + set "$@" --detach --monitor + + # priority + if test X"$priority" != X; then + set nice -n "$priority" "$@" + fi + + action "Starting $daemon" "$@" +} + +DAEMON_CWD=/ +stop_daemon () { + if test -e "$rundir/$1.pid"; then + if pid=`cat "$rundir/$1.pid"`; then + for action in TERM .1 .25 .65 1 1 1 1 KILL 1 1 1 1 FAIL; do + case $action in + TERM) + action "Killing $1 ($pid)" kill $pid + ;; + KILL) + action "Killing $1 ($pid) with SIGKILL" kill -9 $pid + ;; + FAIL) + log_failure_msg "Killing $1 ($pid) failed" + return 1 + ;; + *) + if kill -0 $pid >/dev/null 2>&1; then + sleep $action + else + return 0 + fi + ;; + esac + done + fi + fi + log_success_msg "$1 is not running" +} + +daemon_status () { + pidfile=$rundir/$1.pid + if test -e "$pidfile"; then + if pid=`cat "$pidfile"`; then + if kill -0 "$pid"; then + echo "$1 is running with pid $pid" + return 0 + else + echo "Pidfile for $1 ($pidfile) is stale" + fi + else + echo "Pidfile for $1 ($pidfile) exists but cannot be read" + fi + else + echo "$1 is not running" + fi + return 1 +} + +daemon_is_running () { + pidfile=$rundir/$1.pid + test -e "$pidfile" && pid=`cat "$pidfile"` && kill -0 "$pid" +} >/dev/null 2>&1 diff --git a/xenserver/etc_init.d_openvswitch b/xenserver/etc_init.d_openvswitch index 9d5577ee..941a94d2 100755 --- a/xenserver/etc_init.d_openvswitch +++ b/xenserver/etc_init.d_openvswitch @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # openvswitch # @@ -27,43 +27,11 @@ # 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 - -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 - -test -e /etc/xensource-inventory && . /etc/xensource-inventory +. /usr/share/openvswitch/scripts/ovs-lib.sh || exit 1 +. /etc/xensource-inventory test -e /etc/sysconfig/openvswitch && . /etc/sysconfig/openvswitch -if test -e /etc/xensource/network.conf; then - NETWORK_MODE=$(cat /etc/xensource/network.conf) -fi -case ${NETWORK_MODE:=openvswitch} in +case `cat /etc/xensource/network.conf` in vswitch|openvswitch) ;; bridge) @@ -75,339 +43,53 @@ case ${NETWORK_MODE:=openvswitch} in ;; 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,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} -: ${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:=} - -: ${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" -dpctl="/usr/bin/ovs-dpctl" -appctl="/usr/bin/ovs-appctl" -ofctl="/usr/bin/ovs-ofctl" -vsctl="/usr/bin/ovs-vsctl" - -if test "$ENABLE_MONITOR" = "y"; then - monitor_opt="--monitor" -else - monitor_opt= -fi - -function hup_monitor_external_ids { - if [ -e "$OVS_XAPI_SYNC_PIDFILE" ]; then - action "Configuring Open vSwitch external IDs" kill -HUP `cat "$OVS_XAPI_SYNC_PIDFILE"` - fi -} - -function turn_on_corefiles { - ulimit -Sc 67108864 -} - -function remove_all_dp { - 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 -} - -function remove_modules { - 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" +start () { + set $ovs_ctl start + set "$@" --system-id="$INSTALLATION_UUID" + set "$@" --system-type="$PRODUCT_BRAND" + set "$@" --system-version="$PRODUCT_VERSION-$BUILD_NUMBER" + set "$@" --external-id=xs-system-uuid="$INSTALLATION_UUID" + set "$@" --daemon-cwd=/var/xen/openvswitch + if test X"$FORCE_COREFILES" != X; then + set "$@" --force-oorefiles="$FORCE_COREFILES" 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" + if test X"$OVSDB_SERVER_PRIORITY" != X; then + set "$@" --ovsdb-server-priority="$OVSDB_SERVER_PRIORITY" 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 + if test X"$VSWITCHD_PRIORITY" != X; then + set "$@" --ovs-vswitchd-priority="$VSWITCHD_PRIORITY" 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 - - if test $mode = production; then - action "Starting `basename $BINARY`" "$@" - else - # Start in background and force a "success" message - action "Starting `basename $BINARY` with $mode debugging" true - ("$@") & - 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 start_vswitchd { - local mlockall_opt= - if [ "$VSWITCHD_MLOCKALL" != "no" ]; then - mlockall_opt="--mlockall" + if test X"$VSWITCHD_MLOCKALL" != X; then + set "$@" --mlockall="$VSWITCHD_MLOCKALL" fi - - 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 + if test ! -e /var/run/openvswitch.booted; then + touch /var/run/openvswitch.booted + set "$@" --delete-bridges fi -} + "$@" -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" + if daemon_is_running ovs-xapi-sync; then + log_success_msg "ovs-xapi-sync is already running" else - 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 + PYTHONPATH=/usr/share/openvswitch/python \ + /usr/share/openvswitch/scripts/ovs-xapi-sync \ + --pidfile --detach --monitor unix:/var/run/openvswitch/db.sock fi -} - -function start { - if [ "$FORCE_COREFILES" = "y" ]; then - turn_on_corefiles - fi - - insert_modules_if_required - - # Increase the limit on the number of open file descriptors since - # ovs-vswitchd needs a few per bridge - ulimit -n 4096 # 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" - 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 --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 --timeout=5 del-br $bridge - done - fi - - set_system_ids - - start_vswitchd - - 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 + /sbin/iptables -I INPUT -p gre -j ACCEPT touch /var/lock/subsys/openvswitch } -function stop { - stop_daemon VSWITCHD "$vswitchd" - stop_daemon OVSDB_SERVER "$ovsdb_server" - stop_daemon OVS_XAPI_SYNC ovs-xapi-sync +stop () { + $ovs_ctl stop + stop_daemon ovs-xapi-sync rm -f /var/lock/subsys/openvswitch } -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 -} - -case "$1" in +ovs_ctl=/usr/share/openvswitch/scripts/ovs-ctl +case $1 in start) start ;; @@ -419,25 +101,21 @@ case "$1" in start ;; 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") "$@" + # The main OVS daemons keep up-to-date, but ovs-xapi-sync needs help. + pidfile=/var/run/openvswitch/ovs-xapi-sync.pid + if test -e "$pidfile"; then + pid=`cat "$pidfile"` + action "Configuring Open vSwitch external IDs" kill -HUP $pid + fi ;; status) - status -p "$OVSDB_SERVER_PIDFILE" ovsdb-server && - status -p "$VSWITCHD_PIDFILE" ovs-vswitchd + $ovs_ctl status && daemon_status ovs-xapi-sync ;; version) - /usr/sbin/ovsdb-server -V - /usr/sbin/ovs-vswitchd -V + $ovs_ctl version ;; force-reload-kmod) - force_reload_kmod + $ovs_ctl force_reload_kmod ;; help) printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n" diff --git a/xenserver/openvswitch-xen.spec b/xenserver/openvswitch-xen.spec index 2c247094..d6565b8f 100644 --- a/xenserver/openvswitch-xen.spec +++ b/xenserver/openvswitch-xen.spec @@ -367,6 +367,8 @@ exit 0 /usr/share/openvswitch/scripts/sysconfig.template /usr/share/openvswitch/scripts/xen-bugtool-tc-class-show /usr/share/openvswitch/scripts/ovs-save +/usr/share/openvswitch/scripts/ovs-ctl +/usr/share/openvswitch/scripts/ovs-lib.sh /usr/share/openvswitch/vswitch.ovsschema /usr/sbin/ovs-vlan-bug-workaround /usr/sbin/ovs-vswitchd @@ -386,6 +388,7 @@ exit 0 /usr/share/man/man1/ovsdb-tool.1.gz /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz /usr/share/man/man8/ovs-appctl.8.gz +/usr/share/man/man8/ovs-ctl.8.gz /usr/share/man/man8/ovs-dpctl.8.gz /usr/share/man/man8/ovs-ofctl.8.gz /usr/share/man/man8/ovs-parse-leaks.8.gz diff --git a/xenserver/usr_share_openvswitch_scripts_sysconfig.template b/xenserver/usr_share_openvswitch_scripts_sysconfig.template index 2636588b..26543af1 100644 --- a/xenserver/usr_share_openvswitch_scripts_sysconfig.template +++ b/xenserver/usr_share_openvswitch_scripts_sysconfig.template @@ -1,110 +1,15 @@ ### Configuration options for openvswitch # Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc. -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without warranty of any kind. - -# ENABLE_MONITOR: If 'y' then monitor daemon processes and restart them -# if they die due to an error signal. -# ENABLE_MONITOR=y - -# FORCE_COREFILES: If 'y' then core files will be enabled. -# FORCE_COREFILES=y - -# COREFILE_PATTERN: Pattern used to determine path and filename for -# core files when FORCE_COREFILES is 'y'. This is Linux specific. -# See the manpage for "core". -# COREFILE_PATTERN="/var/xen/openvswitch/%e-%t" - -# OVSDB_SERVER_REMOTES: Space-separated list of methods on which to have -# ovsdb-server listen or connect for a JSON-RPC connection. -# OVSDB_SERVER_REMOTES="punix:/var/run/openvswitch/db.sock db:Open_vSwitch,manager_options" - -# OVSDB_SERVER_DB: File for which ovsdb-server uses for storage. -# OVSDB_SERVER_DB=/etc/openvswitch/conf.db - -# OVSDB_SERVER_PIDFILE: File in which to store the pid of the running -# ovsdb-server. -# OVSDB_SERVER_PIDFILE=/var/run/openvswitch/ovsdb-server.pid -# OVSDB_SERVER_RUN_DIR: Set the directory in which ovsdb-server should be -# run. This mainly affects where core files will be placed. -# OVSDB_SERVER_RUN_DIR=/var/xen/openvswitch +# FORCE_COREFILES: If 'yes' then core files will be enabled. +# FORCE_COREFILES=yes -# OVSDB_SERVER_PRIORITY: "nice" priority at which to run ovsdb-server and -# related processes. +# OVSDB_SERVER_PRIORITY: "nice" priority at which to run ovsdb-server. +# # OVSDB_SERVER_PRIORITY=-10 -# OVSDB_SERVER_LOGFILE: File to send the FILE_LOGLEVEL log messages to. -# OVSDB_SERVER_LOGFILE=/var/log/openvswitch/ovsdb-server.log - -# OVSDB_SERVER_FILE_LOGLEVEL: Log level at which to log into the -# OVSDB_SERVER_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. -# OVSDB_SERVER_FILE_LOGLEVEL="" - -# OVSDB_SERVER_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. -# OVSDB_SERVER_SYSLOG_LOGLEVEL="WARN" - -# OVSDB_SERVER_MEMLEAK_LOGFILE: File for logging memory leak data. -# Enabling this option will slow ovsdb-server significantly. Do not -# enable it except to debug a suspected memory leak. Use the -# ovs-parse-leaks utility included with Open vSwitch to parse the -# log file. For best results, you also need debug symbols. -# OVSDB_SERVER_MEMLEAK_LOGFILE="" - -# OVSDB_SERVER_STRACE_LOG: File for logging strace output. -# If this is set to a nonempty string, then ovsdb-server will run -# under strace, whose output will be logged to the specified file. -# Enabling this option will slow ovsdb-server significantly. -# OVSDB_SERVER_STRACE_LOG and OVSDB_SERVER_VALGRIND_LOG are mutually -# exclusive. -# OVSDB_SERVER_STRACE_LOG="" - -# OVSDB_SERVER_STRACE_OPT: Options to pass to strace. -# This option's value is honored only when OVSDB_SERVER_STRACE_LOG is -# set to a nonempty string. -# OVSDB_SERVER_STRACE_OPT="" - -# OVSDB_SERVER_VALGRIND_LOG: File for logging valgrind output. -# If this is set to a nonempty string, then ovsdb-server will run -# under valgrind, whose output will be logged to the specified file. -# Enabling this option will slow ovsdb-server by 100X or more. -# valgrind is not installed by default on XenServer systems; you must -# install it by hand to usefully enable this option. -# OVSDB_SERVER_STRACE_LOG and OVSDB_SERVER_VALGRIND_LOG are mutually -# exclusive. -# OVSDB_SERVER_VALGRIND_LOG="" - -# OVSDB_SERVER_VALGRIND_OPT: Options to pass to valgrind. -# This option's value is honored only when OVSDB_SERVER_VALGRIND_LOG is -# set to a nonempty string. -# OVSDB_SERVER_VALGRIND_OPT="" - -# VSWITCHD_OVSDB_SERVER: Method to have ovs-vswitchd initiate a JSON-RPC -# connection to an ovsdb-server instance. -# VSWITCHD_OVSDB_SERVER=unix:/var/run/openvswitch/db.sock - -# VSWITCHD_OVSDB_SCHEMA: Schema file to use for generating a new OVSDB -# ovs-vswitchd database. -# VSWITCHD_OVSDB_SCHEMA=/usr/share/openvswitch/vswitch.ovsschema - -# VSWITCHD_PIDFILE: File in which to store the pid of the running -# ovs-vswitchd. -# VSWITCHD_PIDFILE=/var/run/openvswitch/ovs-vswitchd.pid - -# VSWITCHD_RUN_DIR: Set the directory in which ovs-vswitchd should be -# run. This mainly affects where core files will be placed. -# VSWITCHD_RUN_DIR=/var/xen/openvswitch - -# VSWITCHD_PRIORITY: "nice" priority at which to run ovs-vswitchd and related -# processes. +# VSWITCHD_PRIORITY: "nice" priority at which to run ovs-vswitchd. # VSWITCHD_PRIORITY=-10 # VSWITCHD_MLOCKALL: Whether to pass ovs-vswitchd the --mlockall option. @@ -113,50 +18,3 @@ # system memory pressure in extraordinary situations, such as multiple # concurrent VM import operations. # VSWITCHD_MLOCKALL=yes - -# VSWITCHD_LOGFILE: File to send the FILE_LOGLEVEL log messages to. -# VSWITCHD_LOGFILE=/var/log/openvswitch/ovs-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: File for logging memory leak data. -# Enabling this option will slow ovs-vswitchd significantly. Do not -# enable it except to debug a suspected memory leak. Use the -# ovs-parse-leaks utility included with Open vSwitch to parse the -# log file. For best results, you also need debug symbols. -# VSWITCHD_MEMLEAK_LOGFILE="" - -# VSWITCHD_STRACE_LOG: File for logging strace output. -# If this is set to a nonempty string, then ovs-vswitchd will run -# under strace, whose output will be logged to the specified file. -# Enabling this option will slow ovs-vswitchd significantly. -# VSWITCHD_STRACE_LOG and VSWITCHD_VALGRIND_LOG are mutually exclusive. -# VSWITCHD_STRACE_LOG="" - -# VSWITCHD_STRACE_OPT: Options to pass to strace. -# This option's value is honored only when VSWITCHD_STRACE_LOG is -# set to a nonempty string. -# VSWITCHD_STRACE_OPT="" - -# VSWITCHD_VALGRIND_LOG: File for logging valgrind output. -# If this is set to a nonempty string, then ovs-vswitchd will run -# under valgrind, whose output will be logged to the specified file. -# Enabling this option will slow ovs-vswitchd by 100X or more. -# valgrind is not installed by default on XenServer systems; you must -# install it by hand to usefully enable this option. -# VSWITCHD_STRACE_LOG and VSWITCHD_VALGRIND_LOG are mutually exclusive. -# VSWITCHD_VALGRIND_LOG="" - -# VSWITCHD_VALGRIND_OPT: Options to pass to valgrind. -# This option's value is honored only when VSWITCHD_VALGRIND_LOG is -# set to a nonempty string. -# VSWITCHD_VALGRIND_OPT=""