This patch introduces ovn-ctl, which is similar to ovs-ctl. I opted for a new script as everything in OVN so far is nicely isolated, so a new script seemed to make the most sense.
ovn-ctl supports a few different scenarios. If you'd like to run ovn-controller on a host already running ovs: # ovn-ctl start_controller If you'd like to run ovn-northd and ovsdb-server on a management host that won't be running ovs and ovn-controller: # ovn-ctl start_northd ovn-ctl also supports running everything on the same host. This would be common in a test environment with a single host or small set of hosts. In general, that would look like: # ovn-ctl create_ovn_dbs # ovs-ctl start --extra-dbs="ovnnb.db ovnsb.db" # ovn-ctl start_northd --no-ovsdb-server # ovn-ctl start_controller This script is not strictly needed on systems using systemd, but is still nice to provide as an option to enable running on other systems. Signed-off-by: Russell Bryant <rbry...@redhat.com> Acked-by: Flavio Leitner <f...@redhat.com> --- ovn/automake.mk | 1 + ovn/utilities/.gitignore | 1 + ovn/utilities/automake.mk | 9 ++ ovn/utilities/ovn-ctl | 277 ++++++++++++++++++++++++++++++++++++++++++++ ovn/utilities/ovn-ctl.8.xml | 54 +++++++++ 5 files changed, 342 insertions(+) create mode 100644 ovn/utilities/.gitignore create mode 100644 ovn/utilities/automake.mk create mode 100755 ovn/utilities/ovn-ctl create mode 100644 ovn/utilities/ovn-ctl.8.xml diff --git a/ovn/automake.mk b/ovn/automake.mk index 4be5381..1ebaa55 100644 --- a/ovn/automake.mk +++ b/ovn/automake.mk @@ -86,3 +86,4 @@ ovn_ovn_nbctl_LDADD = ovn/lib/libovn.la ovsdb/libovsdb.la lib/libopenvswitch.la include ovn/controller/automake.mk include ovn/lib/automake.mk include ovn/northd/automake.mk +include ovn/utilities/automake.mk diff --git a/ovn/utilities/.gitignore b/ovn/utilities/.gitignore new file mode 100644 index 0000000..1ddc63e --- /dev/null +++ b/ovn/utilities/.gitignore @@ -0,0 +1 @@ +/ovn-ctl.8 diff --git a/ovn/utilities/automake.mk b/ovn/utilities/automake.mk new file mode 100644 index 0000000..a55c1ad --- /dev/null +++ b/ovn/utilities/automake.mk @@ -0,0 +1,9 @@ +scripts_SCRIPTS += \ + ovn/utilities/ovn-ctl + +man_MANS += \ + ovn/utilities/ovn-ctl.8 + +EXTRA_DIST += \ + ovn/utilities/ovn-ctl \ + ovn/utilities/ovn-ctl.8.xml diff --git a/ovn/utilities/ovn-ctl b/ovn/utilities/ovn-ctl new file mode 100755 index 0000000..59a6698 --- /dev/null +++ b/ovn/utilities/ovn-ctl @@ -0,0 +1,277 @@ +#!/bin/sh +# +# 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" || exit 1 + +for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do + case :$PATH: in + *:$dir:*) ;; + *) PATH=$PATH:$dir ;; + esac +done + + +## ----- ## +## start ## +## ----- ## + +create_db () { + DB_FILE=$1 + DB_SCHEMA=$2 + action "Creating empty database $DB_FILE" ovsdb-tool create "$DB_FILE" "$DB_SCHEMA" +} + +create_ovn_dbs () { + if test ! -e "$DB_NB_FILE"; then + create_db "$DB_NB_FILE" "$DB_NB_SCHEMA" + fi + + if test ! -e "$DB_SB_FILE"; then + create_db "$DB_SB_FILE" "$DB_SB_SCHEMA" + fi +} + +start_ovsdb () { + if test X"$OVSDB_SERVER" != Xyes; then + return + fi + + if daemon_is_running ovsdb-server; then + log_success_msg "ovsdb-server is already running" + return + fi + + create_ovn_dbs + + set ovsdb-server "$DB_NB_FILE" "$DB_SB_FILE" + set "$@" -vconsole:emer -vsyslog:err -vfile:info + set "$@" --remote=punix:"$DB_SOCK" + for remote in $OVSDB_SERVER_REMOTES; do + set "$@" "--remote=$remote" + done + start_daemon "$OVSDB_SERVER_PRIORITY" "$OVSDB_SERVER_WRAPPER" "$@" +} + +start_northd () { + # We expect ovn-northd to be co-located with ovsdb-server handling both the + # OVN_Northbound and OVN_Southbound dbs. + start_ovsdb + + set ovn-northd + set "$@" -vconsole:emer -vsyslog:err -vfile:info + start_daemon "$OVN_NORTHD_PRIORITY" "$OVN_NORTHD_WRAPPER" "$@" +} + +start_controller () { + set ovn-controller "unix:$DB_SOCK" + set "$@" -vconsole:emer -vsyslog:err -vfile:info + start_daemon "$OVN_CONTROLLER_PRIORITY" "$OVN_CONTROLLER_WRAPPER" "$@" +} + +## ---- ## +## stop ## +## ---- ## + +stop_ovsdb_server () { + if test X"$OVSDB_SERVER" != Xyes; then + return + fi + + stop_daemon ovsdb-server +} + +stop_northd () { + stop_ovsdb_server + stop_daemon ovn-northd +} + +stop_controller () { + stop_daemon ovn-controller +} + +## ------- ## +## restart ## +## ------- ## + +restart_northd () { + stop_northd + start_northd +} + +restart_controller () { + stop_controller + start_controller +} + +## ---- ## +## main ## +## ---- ## + +set_defaults () { + DB_SOCK=$rundir/db.sock + DB_NB_FILE=$dbdir/ovnnb.db + DB_SB_FILE=$dbdir/ovnsb.db + DB_NB_SCHEMA=$datadir/ovn-nb.ovsschema + DB_SB_SCHEMA=$datadir/ovn-sb.ovsschema + + OVSDB_SERVER=yes + OVSDB_SERVER_REMOTES= + + OVSDB_SERVER_PRIORITY=-10 + OVN_NORTHD_PRIORITY=-10 + OVSDB_SERVER_WRAPPER= + OVN_NORTHD_WRAPPER= +} + +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 +} + +usage () { + set_defaults + cat << EOF +$0: controls Open Virtual Network daemons +usage: $0 [OPTIONS] COMMAND + +This program is intended to be invoked internally by Open Virtual Network +startup scripts. System administrators should not normally invoke it directly. + +Commands: + start_northd start ovn-northd + start_controller start ovn-controller + stop_northd stop ovn-northd + stop_controller stop ovn-controller + restart_northd restart ovn-northd + restart_controller restart ovn-controller + create_ovn_dbs create OVN_Northbound and OVN_Southbound dbs + +Options: + --no-ovsdb-server Do not automatically run ovsdb-server with ovn-northd. + --ovsdb-server-remotes=REMOTES A list of extra remotes for ovsdb-server + --ovsdb-server-priority=NICE set ovsdb-server's niceness (default: $OVSDB_SERVER_PRIORITY) + --ovn-northd-priority=NICE set ovn-northd's niceness (default: $OVSDB_SERVER_PRIORITY) + --ovsdb-server-wrapper=WRAPPER run with a wrapper like valgrind for debugging + --ovn-northd-wrapper=WRAPPER run with a wrapper like valgrind for debugging + -h, --help display this help message + +File location options: + --db-sock=SOCKET JSON-RPC socket name (default: $DB_SOCK) + --db-nb-file=FILE OVN_Northbound db file (default: $DB_NB_FILE) + --db-sb-file=FILE OVN_Southbound db file (default: $DB_SB_FILE) + --db-nb-schema=FILE OVN_Northbound db file (default: $DB_NB_SCHEMA) + --db-sb-schema=FILE OVN_Southbound db file (default: $DB_SB_SCHEMA) + +Default directories with "configure" option and environment variable override: + logs: /usr/local/var/log/openvswitch (--with-logdir, OVS_LOGDIR) + pidfiles and sockets: /usr/local/var/run/openvswitch (--with-rundir, OVS_RUNDIR) + ovn-nb.db: /usr/local/etc/openvswitch (--with-dbdir, OVS_DBDIR) + ovn-sb.db: /usr/local/etc/openvswitch (--with-dbdir, OVS_DBDIR) + system configuration: /usr/local/etc (--sysconfdir, OVS_SYSCONFDIR) + data files: /usr/local/share/openvswitch (--pkgdatadir, OVS_PKGDATADIR) + user binaries: /usr/local/bin (--bindir, OVS_BINDIR) + system binaries: /usr/local/sbin (--sbindir, OVS_SBINDIR) +EOF +} + +set_defaults +command= +for arg +do + case $arg in + -h | --help) + usage + ;; + --[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_northd) + start_northd + ;; + start_controller) + start_controller + ;; + stop_northd) + stop_northd + ;; + stop_controller) + stop_controller + ;; + restart_northd) + restart_northda + ;; + restart_controller) + restart_controller + ;; + create_ovn_dbs) + create_ovn_dbs + ;; + help) + usage + ;; + preheat) + echo >&2 "$0: preheating ovn to 350 degrees F." + exit 1 + ;; + '') + 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/ovn/utilities/ovn-ctl.8.xml b/ovn/utilities/ovn-ctl.8.xml new file mode 100644 index 0000000..7a8d3d3 --- /dev/null +++ b/ovn/utilities/ovn-ctl.8.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<manpage program="ovn-ctl" section="8" title="ovn-ctl"> + <h1>Name</h1> + <p>ovn-ctl -- Open Virtual Network northbound daemon lifecycle utility</p> + + <h1>Synopsys</h1> + <p><code>ovn-ctl</code> [<var>options</var>] <var>command</var></p> + + <h1>Description</h1> + <p>This program is intended to be invoked internally by Open Virtual Network + startup scripts. System administrators should not normally invoke it directly.</p> + + <h1>Commands</h1> + + <dl> + <dt><code>start_northd</code></dt> + <dt><code>start_controller</code></dt> + <dt><code>stop_northd</code></dt> + <dt><code>stop_controller</code></dt> + <dt><code>restart_northd</code></dt> + <dt><code>restart_controller</code></dt> + <dt><code>create_ovn_dbs</code></dt> + </dl> + + <h1>Options</h1> + <p><code>--no-ovsdb-server</code></p> + <p><code>--ovsdb-server-remotes=<var>REMOTES</var></code></p> + <p><code>--ovsdb-server-priority=<var>NICE</var></code></p> + <p><code>--ovn-northd-priority=<var>NICE</var></code></p> + <p><code>--ovsdb-server-wrapper=<var>WRAPPER</var></code></p> + <p><code>--ovn-northd-wrapper=<var>WRAPPER</var></code></p> + <p><code>-h</code> | <code>--help</code></p> + + <h1>File location options</h1> + <p><code>--db-sock==<var>SOCKET</var></code></p> + <p><code>--db-nb-file==<var>FILE</var></code></p> + <p><code>--db-sb-file==<var>FILE</var></code></p> + <p><code>--db-nb-schema==<var>FILE</var></code></p> + <p><code>--db-sb-schema==<var>FILE</var></code></p> + + <h1>Example Usage</h1> + <h2>Run ovn-controller on a host already running OVS</h2> + <p><code># ovn-ctl start_controller</code></p> + + <h2>Run ovn-northd and ovsdb-server</h2> + <p><code># ovn-ctl start_northd</code></p> + + <h2>All-in-one OVS+OVN for testing</h2> + <p><code># ovn-ctl create_ovn_dbs</code></p> + <p><code># ovs-ctl start --system-id="random" --extra-dbs="ovnnb.db ovnsb.db"</code></p> + <p><code># ovn-ctl --no-ovsdb-server start_northd</code></p> + <p><code># ovn-ctl start_controller</code></p> + +</manpage> -- 2.1.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev