On Fri, Aug 16, 2019 at 10:45 PM Mark Michelson <mmich...@redhat.com> wrote:
> On 8/13/19 12:27 PM, nusid...@redhat.com wrote: > > From: Numan Siddique <nusid...@redhat.com> > > > > Until now, OVN uses the openvswitch rundirs (rundir, logdir, etcdir). > > The commit [1] changed the package name from openvswitch to ovn, but > > it didn't take into the account the effects of it. When "make install" > > is run ovn-ctl utility is copied to /usr/local/share/ovn/scripts folder. > > ovn-ctl depends on 'ovs-lib' and it is not present in this scripts foler. > > Because of which we cannot start OVN services using ovn-ctl. > > > > This patch addresses all these issues. It changes the rundir to > > ovn specific ones. (i.e /usr/local/var/run/ovn, /usr/local/var/log/ovn, > > /usr/local/etc/ovn with default configuration). > > > > [1] - 7795e0e28dce("Change the package name from openvswitch to ovn in > AC_INIT()") > > > > Tested:by: Dumitru Ceara <dce...@redhat.com> > > Signed-off-by: Numan Siddique <nusid...@redhat.com> > > --- > > Documentation/intro/install/general.rst | 30 ++-- > > Makefile.am | 5 + > > configure.ac | 1 + > > controller/ovn-controller.c | 4 +- > > lib/.gitignore | 1 + > > lib/automake.mk | 22 ++- > > lib/ovn-dirs.c.in | 112 +++++++++++++ > > lib/ovn-dirs.h | 35 ++++ > > lib/ovn-util.c | 24 ++- > > lib/ovn-util.h | 1 + > > m4/openvswitch.m4 | 11 ++ > > northd/ovn-northd.c | 9 +- > > tests/ovs-macros.at | 1 + > > tutorial/ovs-sandbox | 1 + > > utilities/automake.mk | 5 + > > utilities/ovn-ctl | 71 +++++---- > > utilities/ovn-ctl.8.xml | 12 +- > > utilities/ovn-lib.in | 204 ++++++++++++++++++++++++ > > 18 files changed, 494 insertions(+), 55 deletions(-) > > create mode 100644 lib/ovn-dirs.c.in > > create mode 100644 lib/ovn-dirs.h > > create mode 100644 utilities/ovn-lib.in > > > > diff --git a/Documentation/intro/install/general.rst > b/Documentation/intro/install/general.rst > > index 99d8fec04..4cc9c4c3a 100644 > > --- a/Documentation/intro/install/general.rst > > +++ b/Documentation/intro/install/general.rst > > @@ -153,17 +153,17 @@ invoke configure without any arguments. For > example:: > > > > $ ./configure > > > > -By default all files are installed under ``/usr/local``. OVN and Open > vSwitch > > -also expects to find its database in ``/usr/local/etc/openvswitch`` by > default. > > +By default all files are installed under ``/usr/local``. OVN expects to > find > > +its database in ``/usr/local/etc/ovn`` by default. > > If you want to install all files into, e.g., ``/usr`` and ``/var`` > instead of > > -``/usr/local`` and ``/usr/local/var`` and expect to use > ``/etc/openvswitch`` as > > +``/usr/local`` and ``/usr/local/var`` and expect to use ``/etc/ovn`` as > > the default database directory, add options as shown here:: > > > > $ ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc > > > > .. note:: > > > > - Open vSwitch and OVN installed with packages like .rpm (e.g. via > > + OVN installed with packages like .rpm (e.g. via > > ``yum install`` or ``rpm -ivh``) and .deb (e.g. via > > ``apt-get install`` or ``dpkg -i``) use the above configure options. > > > > @@ -319,9 +319,13 @@ and stopping ovn-northd, ovn-controller and > ovsdb-servers. After installation, > > the daemons can be started by using the ovn-ctl utility. This will > take care > > to setup initial conditions, and start the daemons in the correct > order. > > The ovn-ctl utility is located in '$(pkgdatadir)/scripts', and > defaults to > > -'/usr/local/share/openvswitch/scripts'. An example after install might > be:: > > +'/usr/local/share/ovn/scripts'. ovn-ctl utility requires the 'ovs-lib' > > +helper shell script which is present in > '/usr/local/share/openvswitch/scripts'. > > +So invoking ovn-ctl as "./ovn-ctl" will fail. > > > > - $ export PATH=$PATH:/usr/local/share/openvswitch/scripts > > +An example after install might be:: > > + > > + $ export PATH=$PATH:/usr/local/share/ovn/scripts > > $ ovn-ctl start_northd > > $ ovn-ctl start_controller > > > > @@ -331,7 +335,7 @@ Starting OVN Central services > > OVN central services includes ovn-northd, Northbound and > > Southbound ovsdb-server. > > > > - $ export PATH=$PATH:/usr/local/share/openvswitch/scripts > > + $ export PATH=$PATH:/usr/local/share/ovn/scripts > > $ ovn-ctl start_northd > > > > Refer to ovn-ctl(8) for more information and the supported options. > > @@ -341,23 +345,23 @@ Before starting ovn-northd you need to start OVN > Northbound and Southbound > > ovsdb-servers. Before ovsdb-servers can be started, > > configure the Northbound and Southbound databases:: > > > > - $ mkdir -p /usr/local/etc/openvswitch > > - $ ovsdb-tool create /usr/local/etc/openvswitch/ovnnb_db.db \ > > + $ mkdir -p /usr/local/etc/ovn > > + $ ovsdb-tool create /usr/local/etc/ovn/ovnnb_db.db \ > > ovn-nb.ovsschema > > - $ ovsdb-tool create /usr/local/etc/openvswitch/ovnsb_db.db \ > > + $ ovsdb-tool create /usr/local/etc/ovn/ovnsb_db.db \ > > ovn-sb.ovsschema > > > > Configure ovsdb-servers to use databases created above, to listen on a > Unix > > domain socket and to use the SSL configuration in the database:: > > > > - $ mkdir -p /usr/local/var/run/openvswitch > > - $ ovsdb-server > --remote=punix:/usr/local/var/run/openvswitch/ovnnb_db.sock \ > > + $ mkdir -p /usr/local/var/run/ovn > > + $ ovsdb-server --remote=punix:/usr/local/var/run/ovn/ovnnb_db.sock \ > > --remote=db:OVN_Northbound,NB_Global,connections \ > > --private-key=db:OVN_Northbound,SSL,private_key \ > > --certificate=db:OVN_Northbound,SSL,certificate \ > > --bootstrap-ca-cert=db:OVN_Northbound,SSL,ca_cert \ > > --pidfile --detach --log-file > > - $ovsdb-server > --remote=punix:/usr/local/var/run/openvswitch/ovnsb_db.sock \ > > + $ovsdb-server --remote=punix:/usr/local/var/run/ovn/ovnsb_db.sock \ > > --remote=db:OVN_Southbound,SB_Global,connections \ > > --private-key=db:OVN_Southbound,SSL,private_key \ > > --certificate=db:OVN_Southbound,SSL,certificate \ > > diff --git a/Makefile.am b/Makefile.am > > index f886a8e63..6447e348b 100644 > > --- a/Makefile.am > > +++ b/Makefile.am > > @@ -177,6 +177,7 @@ SUFFIXES += .in > > -e 's,[@]DBDIR[@],$(DBDIR),g' \ > > -e 's,[@]PYTHON[@],$(PYTHON),g' \ > > -e 's,[@]RUNDIR[@],$(RUNDIR),g' \ > > + -e 's,[@]OVN_RUNDIR[@],$(OVN_RUNDIR),g' \ > > Same here. > > > -e 's,[@]VERSION[@],$(VERSION),g' \ > > -e 's,[@]localstatedir[@],$(localstatedir),g' \ > > -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ > > @@ -202,6 +203,7 @@ SUFFIXES += .xml > > DBDIR='$(DBDIR)' \ > > PYTHON='$(PYTHON)' \ > > RUNDIR='$(RUNDIR)' \ > > + OVN_RUNDIR='$(OVN_RUNDIR)' \ > > VERSION='$(VERSION)' \ > > localstatedir='$(localstatedir)' \ > > pkgdatadir='$(pkgdatadir)' \ > > @@ -502,6 +504,9 @@ ALL_LOCAL += ovn-sb.ovsschema.stamp > > ovn-sb.ovsschema.stamp: ovn-sb.ovsschema > > $(srcdir)/build-aux/cksum-schema-check $? $@ > > > > +pkgdata_DATA += ovn-nb.ovsschema > > +pkgdata_DATA += ovn-sb.ovsschema > > + > > CLEANFILES += ovn-sb.ovsschema.stamp > > > > include Documentation/automake.mk > > diff --git a/configure.ac b/configure.ac > > index 8a32d3a18..c74b17a1d 100644 > > --- a/configure.ac > > +++ b/configure.ac > > @@ -123,6 +123,7 @@ AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include > <sys/types.h> > > > > OVS_CHECK_PKIDIR > > OVS_CHECK_RUNDIR > > +OVN_CHECK_RUNDIR > > OVS_CHECK_DBDIR > > OVS_CHECK_BACKTRACE > > OVS_CHECK_PERF_EVENT > > diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c > > index 86f29accf..e27b56b2b 100644 > > --- a/controller/ovn-controller.c > > +++ b/controller/ovn-controller.c > > @@ -1715,7 +1715,9 @@ main(int argc, char *argv[]) > > > > daemonize_start(false); > > > > - retval = unixctl_server_create(NULL, &unixctl); > > + char *abs_unixctl_path = get_abs_unix_ctl_path(); > > + retval = unixctl_server_create(abs_unixctl_path, &unixctl); > > + free(abs_unixctl_path); > > if (retval) { > > exit(EXIT_FAILURE); > > } > > diff --git a/lib/.gitignore b/lib/.gitignore > > index a80a1bce1..3eed4588b 100644 > > --- a/lib/.gitignore > > +++ b/lib/.gitignore > > @@ -5,3 +5,4 @@ > > /ovn-sb-idl.c > > /ovn-sb-idl.h > > /ovn-sb-idl.ovsidl > > +/ovn-dirs.c > > diff --git a/lib/automake.mk b/lib/automake.mk > > index 8e7a1a937..2ee14a261 100644 > > --- a/lib/automake.mk > > +++ b/lib/automake.mk > > @@ -9,6 +9,7 @@ lib_libovn_la_SOURCES = \ > > lib/actions.c \ > > lib/chassis-index.c \ > > lib/chassis-index.h \ > > + lib/ovn-dirs.h \ > > lib/expr.c \ > > lib/extend-table.h \ > > lib/extend-table.c \ > > @@ -24,17 +25,36 @@ lib_libovn_la_SOURCES = \ > > lib/inc-proc-eng.c \ > > lib/inc-proc-eng.h > > nodist_lib_libovn_la_SOURCES = \ > > + lib/ovn-dirs.c \ > > lib/ovn-nb-idl.c \ > > lib/ovn-nb-idl.h \ > > lib/ovn-sb-idl.c \ > > lib/ovn-sb-idl.h > > > > +CLEANFILES += $(nodist_lib_libovn_la_SOURCES) > > + > > # ovn-sb IDL > > OVSIDL_BUILT += \ > > lib/ovn-sb-idl.c \ > > lib/ovn-sb-idl.h \ > > lib/ovn-sb-idl.ovsidl > > -EXTRA_DIST += lib/ovn-sb-idl.ann > > +EXTRA_DIST += \ > > + lib/ovn-sb-idl.ann \ > > + lib/ovn-dirs.c.in > > + > > +lib/ovn-dirs.c: lib/ovn-dirs.c.in Makefile > > + $(AM_V_GEN)($(ro_c) && sed < $(srcdir)/lib/ovn-dirs.c.in \ > > + -e 's,[@]srcdir[@],$(srcdir),g' \ > > + -e 's,[@]LOGDIR[@],"$(LOGDIR)",g' \ > > + -e 's,[@]RUNDIR[@],"$(RUNDIR)",g' \ > > + -e 's,[@]OVN_RUNDIR[@],"$(OVN_RUNDIR)",g' \ > > + -e 's,[@]DBDIR[@],"$(DBDIR)",g' \ > > + -e 's,[@]bindir[@],"$(bindir)",g' \ > > + -e 's,[@]sysconfdir[@],"$(sysconfdir)",g' \ > > + -e 's,[@]pkgdatadir[@],"$(pkgdatadir)",g') \ > > + > lib/ovn-dirs.c.tmp && \ > > + mv lib/ovn-dirs.c.tmp lib/ovn-dirs.c > > + > > OVN_SB_IDL_FILES = \ > > $(srcdir)/ovn-sb.ovsschema \ > > $(srcdir)/lib/ovn-sb-idl.ann > > diff --git a/lib/ovn-dirs.c.in b/lib/ovn-dirs.c.in > > new file mode 100644 > > index 000000000..7ed1e3018 > > --- /dev/null > > +++ b/lib/ovn-dirs.c.in > > @@ -0,0 +1,112 @@ > > +#line 2 "@srcdir@/lib/dirs.c.in" > > +/* > > + * Copyright (c) 2019 > > + * > > + * 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. > > + */ > > + > > +#include <config.h> > > +#include "ovn-dirs.h" > > +#include <stdlib.h> > > +#include "lib/ovs-thread.h" > > +#include "lib/util.h" > > + > > +struct directory { > > + const char *value; /* Actual value; NULL if not yet > determined. */ > > + const char *default_value; /* Default value. */ > > + const char *var_name; /* Environment variable to override > default. */ > > + struct ovsthread_once once; /* Ensures 'value' gets initialized > once. */ > > +}; > > + > > +static const char * > > +get_dir(struct directory *d) > > +{ > > + if (ovsthread_once_start(&d->once)) { > > + d->value = getenv(d->var_name); > > + if (!d->value || !d->value[0]) { > > + d->value = d->default_value; > > + } > > + ovsthread_once_done(&d->once); > > + } > > + return d->value; > > +} > > + > > +const char * > > +ovn_sysconfdir(void) > > +{ > > + static struct directory d = { > > + NULL, @sysconfdir@, "OVN_SYSCONFDIR", > OVSTHREAD_ONCE_INITIALIZER > > + }; > > + > > + return get_dir(&d); > > +} > > + > > +const char * > > +ovn_pkgdatadir(void) > > +{ > > + static struct directory d = { > > + NULL, @pkgdatadir@, "OVN_PKGDATADIR", > OVSTHREAD_ONCE_INITIALIZER > > + }; > > + > > + return get_dir(&d); > > +} > > + > > +const char * > > +ovn_rundir(void) > > +{ > > + static struct directory d = { > > + NULL, @OVN_RUNDIR@, "OVN_RUNDIR", OVSTHREAD_ONCE_INITIALIZER > > + }; > > + > > + return get_dir(&d); > > +} > > + > > +const char * > > +ovn_logdir(void) > > +{ > > + static struct directory d = { > > + NULL, @LOGDIR@, "OVN_LOGDIR", OVSTHREAD_ONCE_INITIALIZER > > + }; > > + > > + return get_dir(&d); > > +} > > + > > +const char * > > +ovn_dbdir(void) > > +{ > > + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; > > + static const char *dbdir; > > + > > + if (ovsthread_once_start(&once)) { > > + dbdir = getenv("OVN_DBDIR"); > > + if (!dbdir || !dbdir[0]) { > > + char *sysconfdir = getenv("OVN_SYSCONFDIR"); > > + > > + dbdir = (sysconfdir > > + ? xasprintf("%s/ovn", sysconfdir) > > + : @DBDIR@); > > + } > > + ovsthread_once_done(&once); > > + } > > + return dbdir; > > +} > > + > > +const char * > > +ovn_bindir(void) > > +{ > > + static struct directory d = { > > + NULL, @bindir@, "OVN_BINDIR", OVSTHREAD_ONCE_INITIALIZER > > + }; > > + > > + return get_dir(&d); > > +} > > diff --git a/lib/ovn-dirs.h b/lib/ovn-dirs.h > > new file mode 100644 > > index 000000000..22ff7a1ee > > --- /dev/null > > +++ b/lib/ovn-dirs.h > > @@ -0,0 +1,35 @@ > > +/* > > + * Copyright (c) 2019. > > + * > > + * 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. > > + */ > > + > > +#ifndef OVN_DIRS_H > > +#define OVN_DIRS_H 1 > > + > > +#ifdef __cplusplus > > +extern "C" { > > +#endif > > + > > +const char *ovn_sysconfdir(void); /* /usr/local/etc */ > > +const char *ovn_pkgdatadir(void); /* /usr/local/share/ovn */ > > +const char *ovn_rundir(void); /* /usr/local/var/run/ovn */ > > +const char *ovn_logdir(void); /* /usr/local/var/log/ovn */ > > +const char *ovn_dbdir(void); /* /usr/local/etc/ovn */ > > +const char *ovn_bindir(void); /* /usr/local/bin */ > > + > > +#ifdef __cplusplus > > +} > > +#endif > > + > > +#endif /* OVN_DIRS_H */ > > diff --git a/lib/ovn-util.c b/lib/ovn-util.c > > index 085498fd1..b425f3f2d 100644 > > --- a/lib/ovn-util.c > > +++ b/lib/ovn-util.c > > @@ -13,8 +13,10 @@ > > */ > > > > #include <config.h> > > +#include <unistd.h> > > + > > #include "ovn-util.h" > > -#include "dirs.h" > > +#include "ovn-dirs.h" > > #include "openvswitch/vlog.h" > > #include "ovn-nb-idl.h" > > #include "ovn-sb-idl.h" > > @@ -296,7 +298,7 @@ default_nb_db(void) > > if (!def) { > > def = getenv("OVN_NB_DB"); > > if (!def) { > > - def = xasprintf("unix:%s/ovnnb_db.sock", ovs_rundir()); > > + def = xasprintf("unix:%s/ovnnb_db.sock", ovn_rundir()); > > } > > } > > return def; > > @@ -309,12 +311,28 @@ default_sb_db(void) > > if (!def) { > > def = getenv("OVN_SB_DB"); > > if (!def) { > > - def = xasprintf("unix:%s/ovnsb_db.sock", ovs_rundir()); > > + def = xasprintf("unix:%s/ovnsb_db.sock", ovn_rundir()); > > } > > } > > return def; > > } > > > > +char * > > +get_abs_unix_ctl_path(void) > > +{ > > +#ifdef _WIN32 > > + enum { WINDOWS = 1 }; > > +#else > > + enum { WINDOWS = 0 }; > > +#endif > > + > > + long int pid = getpid(); > > + char *abs_path = > > + WINDOWS ? xasprintf("%s/%s.ctl", ovn_rundir(), program_name) > > + : xasprintf("%s/%s.%ld.ctl", ovn_rundir(), > program_name, pid); > > + return abs_path; > > +} > > + > > /* l3gateway, chassisredirect, and patch > > * are not in this list since they are > > * only set in the SB DB by northd > > diff --git a/lib/ovn-util.h b/lib/ovn-util.h > > index 6d5e1dfb5..fcd93cd82 100644 > > --- a/lib/ovn-util.h > > +++ b/lib/ovn-util.h > > @@ -67,6 +67,7 @@ char *alloc_nat_zone_key(const struct uuid *key, const > char *type); > > > > const char *default_nb_db(void); > > const char *default_sb_db(void); > > +char *get_abs_unix_ctl_path(void); > > > > struct ovsdb_idl_table_class; > > const char *db_table_usage(struct ds *tables, > > diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4 > > index b599f17d7..964512795 100644 > > --- a/m4/openvswitch.m4 > > +++ b/m4/openvswitch.m4 > > @@ -330,6 +330,17 @@ AC_DEFUN([OVS_CHECK_RUNDIR], > > [RUNDIR='${localstatedir}/run/openvswitch']) > > AC_SUBST([RUNDIR])]) > > > > +dnl Checks for the directory in which to store pidfiles. > > +AC_DEFUN([OVN_CHECK_RUNDIR], > > + [AC_ARG_WITH( > > + [rundir], > > + AC_HELP_STRING([--with-ovn-rundir=DIR], > > + [directory used for pidfiles > > + [[LOCALSTATEDIR/run/ovn]]]), > > + [OVN_RUNDIR=$withval], > > + [OVN_RUNDIR='${localstatedir}/run/ovn']) > > + AC_SUBST([OVN_RUNDIR])]) > > + > > It feels odd to me that we have --with-rundir and --with-ovn-rundir as > configure options. It seems more natural to have --with-rundir (set the > OVN runtime directory) and --with-ovs-rundir (inform the build where the > OVS runtime directory is). > > To me, --with-rundir sounds like an option to configure the rundir for > the project that is being built, not the rundir for a different project. > Hi Mark. Thanks for the reviews. That's true. I agree. I swapped p1 and p2 of this series to address your issues relatively easier as after p1, we will be using ovs frome external directory. Please take a look at v2 of the series - https://patchwork.ozlabs.org/project/openvswitch/list/?series=126020 Thanks Numan > > dnl Checks for the directory in which to store logs. > > AC_DEFUN([OVS_CHECK_LOGDIR], > > [AC_ARG_WITH( > > diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c > > index e86134414..b527f2172 100644 > > --- a/northd/ovn-northd.c > > +++ b/northd/ovn-northd.c > > @@ -9351,7 +9351,14 @@ main(int argc, char *argv[]) > > > > daemonize_start(false); > > > > - retval = unixctl_server_create(unixctl_path, &unixctl); > > + if (!unixctl_path) { > > + char *abs_unixctl_path = get_abs_unix_ctl_path(); > > + retval = unixctl_server_create(abs_unixctl_path, &unixctl); > > + free(abs_unixctl_path); > > + } else { > > + retval = unixctl_server_create(unixctl_path, &unixctl); > > + } > > + > > if (retval) { > > exit(EXIT_FAILURE); > > } > > diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at > > index 10593429d..b2e619f76 100644 > > --- a/tests/ovs-macros.at > > +++ b/tests/ovs-macros.at > > @@ -49,6 +49,7 @@ ovs_setenv() { > > sandbox=$1 > > ovs_dir=$ovs_base${1:+/$1} > > OVS_RUNDIR=$ovs_dir; export OVS_RUNDIR > > + OVN_RUNDIR=$ovs_dir; export OVN_RUNDIR > > OVS_LOGDIR=$ovs_dir; export OVS_LOGDIR > > OVS_DBDIR=$ovs_dir; export OVS_DBDIR > > OVS_SYSCONFDIR=$ovs_dir; export OVS_SYSCONFDIR > > diff --git a/tutorial/ovs-sandbox b/tutorial/ovs-sandbox > > index 47032b499..7546d27ca 100755 > > --- a/tutorial/ovs-sandbox > > +++ b/tutorial/ovs-sandbox > > @@ -360,6 +360,7 @@ sandbox=`cd sandbox && pwd` > > > > # Set up environment for OVS programs to sandbox themselves. > > OVS_RUNDIR=$sandbox; export OVS_RUNDIR > > +OVN_RUNDIR=$sandbox; export OVN_RUNDIR > > OVS_LOGDIR=$sandbox; export OVS_LOGDIR > > OVS_DBDIR=$sandbox; export OVS_DBDIR > > OVS_SYSCONFDIR=$sandbox; export OVS_SYSCONFDIR > > diff --git a/utilities/automake.mk b/utilities/automake.mk > > index d666b9661..db0b0e051 100644 > > --- a/utilities/automake.mk > > +++ b/utilities/automake.mk > > @@ -1,6 +1,7 @@ > > scripts_SCRIPTS += \ > > utilities/ovn-ctl \ > > utilities/ovndb-servers.ocf > > +scripts_DATA += utilities/ovn-lib > > > > man_MANS += \ > > utilities/ovn-ctl.8 \ > > @@ -21,6 +22,7 @@ bin_SCRIPTS += \ > > > > EXTRA_DIST += \ > > utilities/ovn-ctl \ > > + utilities/ovn-lib.in \ > > utilities/ovn-ctl.8.xml \ > > utilities/ovn-docker-overlay-driver.in \ > > utilities/ovn-docker-underlay-driver.in \ > > @@ -31,6 +33,7 @@ EXTRA_DIST += \ > > > > CLEANFILES += \ > > utilities/ovn-ctl.8 \ > > + utilities/ovn-lib \ > > utilities/ovn-docker-overlay-driver \ > > utilities/ovn-docker-underlay-driver \ > > utilities/ovn-nbctl.8 \ > > @@ -39,6 +42,8 @@ CLEANFILES += \ > > utilities/ovn-detrace.1 \ > > utilities/ovn-detrace > > > > +utilities/ovn-lib: $(top_builddir)/config.status > > + > > # ovn-nbctl > > bin_PROGRAMS += utilities/ovn-nbctl > > utilities_ovn_nbctl_SOURCES = utilities/ovn-nbctl.c > > diff --git a/utilities/ovn-ctl b/utilities/ovn-ctl > > index 7e5cd469c..a973b09a2 100755 > > --- a/utilities/ovn-ctl > > +++ b/utilities/ovn-ctl > > @@ -13,12 +13,16 @@ > > # limitations under the License. > > > > case $0 in > > - */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;; > > + */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` > > + ovsdir=`echo "$dir0" | sed 's,/ovn/scripts,,'` > > + ovsdir=$ovsdir/openvswitch/scripts > > + ;; > > *) dir0=./ ;; > > esac > > -. "$dir0/ovs-lib" || exit 1 > > +. "$dir0/ovn-lib" || exit 1 > > +. "$ovsdir/ovs-lib" || exit 1 > > > > -for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin /usr/bin; do > > +for dir in "$sbindir" "$ovn_bindir" "$bindir" /sbin /bin /usr/sbin > /usr/bin; do > > case :$PATH: in > > *:$dir:*) ;; > > *) PATH=$PATH:$dir ;; > > @@ -26,9 +30,9 @@ for dir in "$sbindir" "$bindir" /sbin /bin /usr/sbin > /usr/bin; do > > done > > > > > > -ovnnb_active_conf_file="$etcdir/ovnnb-active.conf" > > -ovnsb_active_conf_file="$etcdir/ovnsb-active.conf" > > -ovn_northd_db_conf_file="$etcdir/ovn-northd-db-params.conf" > > +ovnnb_active_conf_file="$ovn_etcdir/ovnnb-active.conf" > > +ovnsb_active_conf_file="$ovn_etcdir/ovnsb-active.conf" > > +ovn_northd_db_conf_file="$ovn_etcdir/ovn-northd-db-params.conf" > > ## ----- ## > > ## start ## > > ## ----- ## > > @@ -110,6 +114,7 @@ start_ovsdb__() { > > local logfile > > local log > > local sock > > + local ctrl_sock > > local detach > > local create_insecure_remote > > local port > > @@ -134,6 +139,7 @@ start_ovsdb__() { > > eval logfile=\$OVN_${DB}_LOGFILE > > eval log=\$OVN_${DB}_LOG > > eval sock=\$DB_${DB}_SOCK > > + eval ctrl_sock=\$DB_${DB}_CTRL_SOCK > > eval detach=\$DB_${DB}_DETACH > > eval create_insecure_remote=\$DB_${DB}_CREATE_INSECURE_REMOTE > > eval port=\$DB_${DB}_PORT > > @@ -144,7 +150,10 @@ start_ovsdb__() { > > eval ovn_db_ssl_cert=\$OVN_${DB}_DB_SSL_CERT > > eval ovn_db_ssl_cacert=\$OVN_${DB}_DB_SSL_CA_CERT > > > > - install_dir "$OVN_RUNDIR" > > + ovn_install_dir "$OVN_RUNDIR" > > + ovn_install_dir "$ovn_logdir" > > + ovn_install_dir "$ovn_dbdir" > > + > > # Check and eventually start ovsdb-server for DB > > if pidfile_is_running $db_pid_file; then > > return > > @@ -177,7 +186,7 @@ $cluster_remote_port > > set ovsdb-server > > set "$@" $log --log-file=$logfile > > set "$@" --remote=punix:$sock --pidfile=$db_pid_file > > - set "$@" --unixctl=ovn${db}_db.ctl > > + set "$@" --unixctl=$ctrl_sock > > > > [ "$OVS_USER" != "" ] && set "$@" --user "$OVS_USER" > > > > @@ -328,7 +337,7 @@ start_northd () { > > > > set "$@" $OVN_NORTHD_LOG $ovn_northd_params > > > > - OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_NORTHD_PRIORITY" > "$OVN_NORTHD_WRAPPER" "$@" > > + OVS_RUNDIR=${OVS_RUNDIR} start_ovn_daemon > "$OVN_NORTHD_PRIORITY" "$OVN_NORTHD_WRAPPER" "$@" > > fi > > } > > > > @@ -350,7 +359,7 @@ start_controller () { > > > > [ "$OVN_USER" != "" ] && set "$@" --user "$OVN_USER" > > > > - OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_CONTROLLER_PRIORITY" > "$OVN_CONTROLLER_WRAPPER" "$@" > > + OVS_RUNDIR=${OVS_RUNDIR} start_ovn_daemon > "$OVN_CONTROLLER_PRIORITY" "$OVN_CONTROLLER_WRAPPER" "$@" > > } > > > > start_controller_vtep () { > > @@ -377,7 +386,7 @@ start_controller_vtep () { > > > > [ "$OVN_USER" != "" ] && set "$@" --user "$OVN_USER" > > > > - OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_CONTROLLER_PRIORITY" > "$OVN_CONTROLLER_WRAPPER" "$@" > > + OVS_RUNDIR=${OVS_RUNDIR} start_ovn_daemon > "$OVN_CONTROLLER_PRIORITY" "$OVN_CONTROLLER_WRAPPER" "$@" > > } > > > > ## ---- ## > > @@ -385,7 +394,7 @@ start_controller_vtep () { > > ## ---- ## > > > > stop_northd () { > > - OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-northd > > + OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn-northd > > > > if [ ! -e $ovn_northd_db_conf_file ]; then > > if test X"$OVN_MANAGE_OVSDB" = Xyes; then > > @@ -395,11 +404,11 @@ stop_northd () { > > } > > > > stop_controller () { > > - OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-controller "$@" > > + OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn-controller "$@" > > } > > > > stop_controller_vtep () { > > - OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-controller-vtep > > + OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn-controller-vtep > > } > > > > ## ------- ## > > @@ -444,11 +453,12 @@ set_defaults () { > > OVN_MANAGE_OVSDB=yes > > > > OVS_RUNDIR=${OVS_RUNDIR:-${rundir}} > > - OVN_RUNDIR=${OVN_RUNDIR:-${OVS_RUNDIR}} > > + OVN_RUNDIR=${OVN_RUNDIR:-${ovn_rundir}} > > > > DB_NB_SOCK=$OVN_RUNDIR/ovnnb_db.sock > > DB_NB_PID=$OVN_RUNDIR/ovnnb_db.pid > > - DB_NB_FILE=$dbdir/ovnnb_db.db > > + DB_NB_CTRL_SOCK=$OVN_RUNDIR/ovnnb_db.ctl > > + DB_NB_FILE=$ovn_dbdir/ovnnb_db.db > > DB_NB_ADDR=0.0.0.0 > > DB_NB_PORT=6641 > > DB_NB_SYNC_FROM_PROTO=tcp > > @@ -457,17 +467,18 @@ set_defaults () { > > > > DB_SB_SOCK=$OVN_RUNDIR/ovnsb_db.sock > > DB_SB_PID=$OVN_RUNDIR/ovnsb_db.pid > > - DB_SB_FILE=$dbdir/ovnsb_db.db > > + DB_SB_CTRL_SOCK=$OVN_RUNDIR/ovnsb_db.ctl > > + DB_SB_FILE=$ovn_dbdir/ovnsb_db.db > > DB_SB_ADDR=0.0.0.0 > > DB_SB_PORT=6642 > > DB_SB_SYNC_FROM_PROTO=tcp > > DB_SB_SYNC_FROM_ADDR= > > DB_SB_SYNC_FROM_PORT=6642 > > > > - DB_NB_SCHEMA=$datadir/ovn-nb.ovsschema > > - DB_SB_SCHEMA=$datadir/ovn-sb.ovsschema > > + DB_NB_SCHEMA=$ovn_datadir/ovn-nb.ovsschema > > + DB_SB_SCHEMA=$ovn_datadir/ovn-sb.ovsschema > > > > - DB_SOCK=$OVN_RUNDIR/db.sock > > + DB_SOCK=$OVS_RUNDIR/db.sock > > DB_CONF_FILE=$dbdir/conf.db > > > > OVN_NORTHD_PRIORITY=-10 > > @@ -483,8 +494,8 @@ set_defaults () { > > OVN_NORTHD_LOGFILE="" > > OVN_NB_LOG="-vconsole:off -vfile:info" > > OVN_SB_LOG="-vconsole:off -vfile:info" > > - OVN_NB_LOGFILE="$logdir/ovsdb-server-nb.log" > > - OVN_SB_LOGFILE="$logdir/ovsdb-server-sb.log" > > + OVN_NB_LOGFILE="$ovn_logdir/ovsdb-server-nb.log" > > + OVN_SB_LOGFILE="$ovn_logdir/ovsdb-server-sb.log" > > > > OVN_CONTROLLER_SSL_KEY="" > > OVN_CONTROLLER_SSL_CERT="" > > @@ -662,14 +673,14 @@ File location options: > > --db-sb-use-remote-in-db=yes|no OVN_Southbound db listen on target > connection table (default: $DB_SB_USE_REMOTE_IN_DB) > > > > 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) > > + logs: /usr/local/var/log/ovn (--with-logdir, OVN_LOGDIR) > > + pidfiles and sockets: /usr/local/var/run/ovn (--with-rundir, > OVN_RUNDIR) > > + ovn-nb.db: /usr/local/etc/ovn (--with-dbdir, OVN_DBDIR) > > + ovn-sb.db: /usr/local/etc/ovn (--with-dbdir, OVN_DBDIR) > > + system configuration: /usr/local/etc (--sysconfdir, OVN_SYSCONFDIR) > > + data files: /usr/local/share/ovn (--pkgdatadir, OVN_PKGDATADIR) > > + user binaries: /usr/local/bin (--bindir, OVN_BINDIR) > > + system binaries: /usr/local/sbin (--sbindir, OVN_SBINDIR) > > EOF > > } > > > > diff --git a/utilities/ovn-ctl.8.xml b/utilities/ovn-ctl.8.xml > > index c5294d794..f70bd6f0f 100644 > > --- a/utilities/ovn-ctl.8.xml > > +++ b/utilities/ovn-ctl.8.xml > > @@ -203,12 +203,12 @@ > > <h3>Starting standalone ovn db server passing SSL certificates</h3> > > <p> > > <code> > > - # ovn-ctl --ovn-nb-db-ssl-key=/etc/openvswitch/ovnnb-privkey.pem > > - --ovn-nb-db-ssl-cert=/etc/openvswitch/ovnnb-cert.pem > > - --ovn-nb-db-ssl-ca-cert=/etc/openvswitch/cacert.pem > > - --ovn-sb-db-ssl-key=/etc/openvswitch/ovnsb-privkey.pem > > - --ovn-sb-db-ssl-cert=/etc/openvswitch/ovnsb-cert.pem > > - --ovn-sb-db-ssl-ca-cert=/etc/openvswitch/cacert.pem > > + # ovn-ctl --ovn-nb-db-ssl-key=/etc/ovn/ovnnb-privkey.pem > > + --ovn-nb-db-ssl-cert=/etc/ovn/ovnnb-cert.pem > > + --ovn-nb-db-ssl-ca-cert=/etc/ovn/cacert.pem > > + --ovn-sb-db-ssl-key=/etc/ovn/ovnsb-privkey.pem > > + --ovn-sb-db-ssl-cert=/etc/ovn/ovnsb-cert.pem > > + --ovn-sb-db-ssl-ca-cert=/etc/ovn/cacert.pem > > start_northd > > </code> > > </p> > > diff --git a/utilities/ovn-lib.in b/utilities/ovn-lib.in > > new file mode 100644 > > index 000000000..50111a76b > > --- /dev/null > > +++ b/utilities/ovn-lib.in > > @@ -0,0 +1,204 @@ > > +# -*- sh -*- > > +# vi:syntax=sh > > +# This is a shell function library sourced by some OVN scripts. > > +# It is not intended to be invoked on its own. > > +# The code copied from ovs/utilities/ovs-lib.in > > + > > +# > > +# 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. > > +ovn_logdir=${OVN_LOGDIR-'@LOGDIR@'} # /var/log/ovn > > +ovn_rundir=${OVN_RUNDIR-'@OVN_RUNDIR@'} # /var/run/ovn > > +ovn_sysconfdir=${OVN_SYSCONFDIR-'@sysconfdir@'} # /etc > > +ovn_etcdir=$sysconfdir/ovn # /etc/ovn > > +ovn_datadir=${OVN_PKGDATADIR-'@pkgdatadir@'} # /usr/share/ovn > > +ovn_bindir=${OVN_BINDIR-'@bindir@'} # /usr/bin > > +ovn_sbindir=${OVN_SBINDIR-'@sbindir@'} # /usr/sbin > > + > > +# /etc/ovn or /var/lib/ovn > > +if test X"$OVN_DBDIR" != X; then > > + ovn_dbdir=$OVN_DBDIR > > +elif test X"$OVN_SYSCONFDIR" != X; then > > + ovn_dbdir=$OVN_SYSCONFDIR/ovn > > +else > > + ovn_dbdir='@DBDIR@' > > +fi > > + > > +VERSION='@VERSION@' > > + > > +DAEMON_CWD=/ > > + > > +LC_ALL=C; export LC_ALL > > + > > +ovn_install_dir () { > > + DIR="$1" > > + INSTALL_MODE="${2:-755}" > > + INSTALL_USER="root" > > + INSTALL_GROUP="root" > > + [ "$OVN_USER" != "" ] && INSTALL_USER="${OVN_USER%:*}" > > + [ "${OVN_USER##*:}" != "" ] && INSTALL_GROUP="${OVN_USER##*:}" > > + > > + if test ! -d "$DIR"; then > > + install -d -m "$INSTALL_MODE" -o "$INSTALL_USER" -g > "$INSTALL_GROUP" "$DIR" > > + restorecon "$DIR" >/dev/null 2>&1 > > + fi > > +} > > + > > +start_ovn_daemon () { > > + priority=$1 > > + wrapper=$2 > > + shift; shift > > + daemon=$1 > > + strace="" > > + > > + # drop core files in a sensible place > > + ovn_install_dir "$DAEMON_CWD" > > + set "$@" --no-chdir > > + cd "$DAEMON_CWD" > > + > > + # log file > > + ovn_install_dir "$ovn_logdir" "750" > > + set "$@" --log-file="$ovn_logdir/$daemon.log" > > + > > + # pidfile and monitoring > > + ovn_install_dir "$ovn_rundir" > > + set "$@" --pidfile="$ovn_rundir/$daemon.pid" > > + set "$@" --detach > > + test X"$MONITOR" = Xno || set "$@" --monitor > > + > > + # wrapper > > + case $wrapper in > > + valgrind) > > + if (valgrind --version) > /dev/null 2>&1; then > > + set valgrind -q --leak-check=full --time-stamp=yes \ > > + --log-file="$ovn_logdir/$daemon.valgrind.log.%p" > "$@" > > + else > > + log_failure_msg "valgrind not installed, running > $daemon without it" > > + fi > > + ;; > > + strace) > > + if (strace -V) > /dev/null 2>&1; then > > + strace="strace -tt -T -s 256 -ff" > > + if (strace -DV) > /dev/null 2>&1; then > > + # Has the -D option. > > + set $strace -D -o "$ovn_logdir/$daemon.strace.log" > "$@" > > + strace="" > > + fi > > + else > > + log_failure_msg "strace not installed, running $daemon > without it" > > + fi > > + ;; > > + glibc) > > + set env MALLOC_CHECK_=2 MALLOC_PERTURB_=165 "$@" > > + ;; > > + '') > > + ;; > > + *) > > + log_failure_msg "unknown wrapper $wrapper, running $daemon > without it" > > + ;; > > + esac > > + > > + # priority > > + if test X"$priority" != X; then > > + set nice -n "$priority" "$@" > > + fi > > + > > + action "Starting $daemon" "$@" || return 1 > > + > > + if test X"$strace" != X; then > > + # Strace doesn't have the -D option so we attach after the fact. > > + setsid $strace -o "$ovn_logdir/$daemon.strace.log" \ > > + -p `cat $ovn_rundir/$daemon.pid` > /dev/null 2>&1 & > > + fi > > +} > > + > > +stop_ovn_daemon () { > > + if test -e "$ovn_rundir/$1.pid"; then > > + if pid=`cat "$ovn_rundir/$1.pid"`; then > > + if pid_exists "$pid" >/dev/null 2>&1; then :; else > > + rm -f $ovn_rundir/$1.$pid.ctl $ovn_rundir/$1.$pid > > + return 0 > > + fi > > + > > + graceful="EXIT .1 .25 .65 1" > > + actions="TERM .1 .25 .65 1 1 1 1 \ > > + KILL 1 1 1 2 10 15 30 \ > > + FAIL" > > + version=`ovs-appctl -T 1 -t $ovn_rundir/$1.$pid.ctl version > \ > > + | awk 'NR==1{print $NF}'` > > + > > + # Use `ovs-appctl exit` only if the running daemon version > > + # is >= 2.5.90. This script might be used during upgrade to > > + # stop older versions of daemons which do not behave > correctly > > + # with `ovs-appctl exit` (e.g. ovs-vswitchd <= 2.5.0 deletes > > + # internal ports). > > + if version_geq "$version" "2.5.90"; then > > + actions="$graceful $actions" > > + fi > > + for action in $actions; do > > + if pid_exists "$pid" >/dev/null 2>&1; then :; else > > + return 0 > > + fi > > + case $action in > > + EXIT) > > + action "Exiting $1 ($pid)" \ > > + ${bindir}/ovs-appctl -T 1 -t > $ovn_rundir/$1.$pid.ctl exit $2 > > + ;; > > + 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 > > + ;; > > + *) > > + sleep $action > > + ;; > > + esac > > + done > > + fi > > + fi > > + log_success_msg "$1 is not running" > > +} > > + > > +ovn_daemon_status () { > > + pidfile=$ovn_rundir/$1.pid > > + if test -e "$pidfile"; then > > + if pid=`cat "$pidfile"`; then > > + if pid_exists "$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=$ovn_rundir/$1.pid > > + test -e "$pidfile" && pid=`cat "$pidfile"` && pid_exists "$pid" && > pid_comm_check $1 $pid > > +} >/dev/null 2>&1 > > > > _______________________________________________ > dev mailing list > d...@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev > _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev