summaryrefslogtreecommitdiff
path: root/utilities
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-06-17 12:24:31 -0700
committerBen Pfaff <blp@nicira.com>2011-06-17 12:53:52 -0700
commit43bb5f82ec051f335a5c5a8975150ec6352d5d73 (patch)
treecc129acfbd1ea5767f522860ca83d2499cf95c1e /utilities
parentec610b7bf4f4890f50c2c7d2fbfe6120ad9312f1 (diff)
downloadopenvswitch-43bb5f82ec051f335a5c5a8975150ec6352d5d73.tar.gz
Refactor initscripts into distro-independent and distro-specific pieces.
This should make it easier to add OVS support to new distributions.
Diffstat (limited to 'utilities')
-rw-r--r--utilities/automake.mk6
-rw-r--r--utilities/ovs-ctl.8309
-rwxr-xr-xutilities/ovs-ctl.in445
-rw-r--r--utilities/ovs-lib.sh.in166
4 files changed, 926 insertions, 0 deletions
diff --git a/utilities/automake.mk b/utilities/automake.mk
index 47e3a1f77..7c82b739e 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 000000000..d649d5625
--- /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 000000000..923e1b539
--- /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 <<EOF
+$0: controls Open vSwitch daemons
+usage: $0 [OPTIONS] COMMAND
+
+This program is intended to be invoked internally by Open vSwitch startup
+scripts. System administrators should not normally invoke it directly.
+
+Commands:
+ start start Open vSwitch daemons
+ stop stop Open vSwitch daemons
+ status check whether Open vSwitch daemons are running
+ version print versions of Open vSwitch daemons
+ force-reload-kmod save OVS network device state, stop OVS, unload kernel
+ module, reload kernel module, start OVS, restore state
+ help display this help message
+
+One of the following options should be specified when starting Open vSwitch:
+ --system-id=UUID set specific ID to uniquely identify this system
+ --system-id=random use a random but persistent UUID to identify this system
+
+Other important options for starting Open vSwitch:
+ --system-type=TYPE set system type (e.g. "XenServer")
+ --system-version=VERSION set system version (e.g. "5.6.100-39265p")
+ --external-id="key=value"
+ add given key-value pair to Open_vSwitch external-ids
+ --delete-bridges delete all bridges just before starting ovs-vswitchd
+
+Less important options for starting Open vSwitch:
+ --daemon-cwd=DIR current working directory for OVS daemons (default: $DAEMON_CWD)
+ --no-force-corefiles
+ do not forcibly enable core dumps for OVS daemons
+ --no-mlockall do not lock all of ovs-vswitchd into memory
+ --ovsdb-server-priority=NICE
+ set ovsdb-server's niceness (default: $OVSDB_SERVER_PRIORITY)
+ --ovs-vswitchd-priority=NICE
+ set ovs-vswitchd's niceness (default: $OVS_VSWITCHD_PRIORITY)
+
+File location options:
+ --db-file=FILE database file name (default: $DB_FILE)
+ --db-sock=SOCKET JSON-RPC socket name (default: $DB_SOCK)
+ --db-schema=FILE database schema file name (default: $DB_SCHEMA)
+
+Other options:
+ -h, --help display this help message
+ -V, --version display version information
+
+Default directories with "configure" option and environment variable override:
+ logs: @LOGDIR@ (--log-dir, OVS_LOGDIR)
+ pidfiles and sockets: @RUNDIR@ (--run-dir, OVS_RUNDIR)
+ system configuration: @sysconfdir@ (--sysconfdir, OVS_SYSCONFDIR)
+ data files: @pkgdatadir@ (--pkgdatadir, OVS_PKGDATADIR)
+ user binaries: @bindir@ (--bindir, OVS_BINDIR)
+ system binaries: @sbindir@ (--sbindir, OVS_SBINDIR)
+
+Please report bugs to bugs@openvswitch.org (see REPORTING-BUGS for details).
+EOF
+
+ exit 0
+}
+
+set_option () {
+ var=`echo "$option" | tr abcdefghijklmnopqrstuvwxyz- ABCDEFGHIJKLMNOPQRSTUVWXYZ_`
+ eval set=\${$var+yes}
+ eval old_value=\$$var
+ if test X$set = X || \
+ (test $type = bool && \
+ test X"$old_value" != Xno && test X"$old_value" != Xyes); then
+ echo >&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 000000000..179d85e11
--- /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