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()") Signed-off-by: Numan Siddique <nusid...@redhat.com> --- Makefile.am | 5 + configure.ac | 1 + controller/ovn-controller.c | 4 +- lib/automake.mk | 20 +++- 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 | 69 ++++++------ utilities/ovn-lib.in | 204 ++++++++++++++++++++++++++++++++++++ 15 files changed, 466 insertions(+), 36 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/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' \ -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/automake.mk b/lib/automake.mk index 8e7a1a937..637b2eb94 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,6 +25,7 @@ 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 \ @@ -34,7 +36,23 @@ 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])]) + 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 e6953a405..8b026a552 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -9347,7 +9347,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..e0dc1ca1a 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,8 @@ 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" # Check and eventually start ovsdb-server for DB if pidfile_is_running $db_pid_file; then return @@ -177,7 +184,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 +335,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 +357,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 +384,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 +392,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 +402,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 +451,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 +465,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 +492,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 +671,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-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 -- 2.21.0 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev