From: Babu Shanmugam <bscha...@redhat.com> This patch adds support to start_ovsdb() function in ovn-ctl to start the ovn db servers in backup mode. This can be done in the following ways 1. Use parameters --ovn-nb-sync-from-addr and --ovn-sb-sync-from-addr to set the addresses of the active server. 2. Create files $etcdir/ovnnb-active.conf and $etcdir/ovnsb-active.conf with the tcp url of the active servers.
Additional functions to promote a backup server to active and demote active server to backup mode are also added in this patch One can optionally set the DB parameters for northd in $etcdir/ovn-northd-db-params.conf. For example, --ovnnb-db=tcp:172.16.247.230:6641 --ovnsb-db=tcp:172.16.247.230:6642 The parameters will be used as is, by start_northd(). If this file exists, start_northd() will not start the DB servers even if $OVN_MANAGE_OVSDB is 'yes'. Signed-off-by: Babu Shanmugam <bscha...@redhat.com> --- ovn/utilities/ovn-ctl | 173 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 148 insertions(+), 25 deletions(-) diff --git a/ovn/utilities/ovn-ctl b/ovn/utilities/ovn-ctl index 07bff8a..1c1687f 100755 --- a/ovn/utilities/ovn-ctl +++ b/ovn/utilities/ovn-ctl @@ -26,6 +26,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" ## ----- ## ## start ## ## ----- ## @@ -45,6 +48,44 @@ stop_ovsdb () { fi } +demote_ovnnb() { + if test ! -z "$DB_NB_SYNC_FROM_ADDR"; then + echo "tcp:$DB_NB_SYNC_FROM_ADDR:$DB_NB_SYNC_FROM_PORT" > $ovnnb_active_conf_file + fi + + if test -e $ovnnb_active_conf_file; then + ovs-appctl -t $rundir/ovnnb_db.ctl ovsdb-server/set-active-ovsdb-server `cat $ovnnb_active_conf_file` + ovs-appctl -t $rundir/ovnnb_db.ctl ovsdb-server/connect-active-ovsdb-server + else + echo >&2 "$0: active server details not set" + exit 1 + fi +} + +demote_ovnsb() { + if test ! -z "$DB_SB_SYNC_FROM_ADDR"; then + echo "tcp:$DB_SB_SYNC_FROM_ADDR:$DB_SB_SYNC_FROM_PORT" > $ovnsb_active_conf_file + fi + + if test -e $ovnsb_active_conf_file; then + ovs-appctl -t $rundir/ovnsb_db.ctl ovsdb-server/set-active-ovsdb-server `cat $ovnsb_active_conf_file` + ovs-appctl -t $rundir/ovnsb_db.ctl ovsdb-server/connect-active-ovsdb-server + else + echo >&2 "$0: active server details not set" + exit 1 + fi +} + +promote_ovnnb() { + rm -f $ovnnb_active_conf_file + ovs-appctl -t $rundir/ovnnb_db.ctl ovsdb-server/disconnect-active-ovsdb-server +} + +promote_ovnsb() { + rm -f $ovnsb_active_conf_file + ovs-appctl -t $rundir/ovnsb_db.ctl ovsdb-server/disconnect-active-ovsdb-server +} + start_ovsdb () { # Check and eventually start ovsdb-server for Northbound DB if ! pidfile_is_running $DB_NB_PID; then @@ -52,7 +93,20 @@ start_ovsdb () { set ovsdb-server - set "$@" --detach --monitor $OVN_NB_LOG --log-file=$OVN_NB_LOGFILE --remote=punix:$DB_NB_SOCK --remote=ptcp:$DB_NB_PORT:$DB_NB_ADDR --pidfile=$DB_NB_PID --unixctl=ovnnb_db.ctl + set "$@" --detach --monitor $OVN_NB_LOG \ + --log-file=$OVN_NB_LOGFILE \ + --remote=punix:$DB_NB_SOCK \ + --remote=ptcp:$DB_NB_PORT:$DB_NB_ADDR \ + --pidfile=$DB_NB_PID \ + --unixctl=ovnnb_db.ctl + + if test ! -z "$DB_NB_SYNC_FROM_ADDR"; then + echo "tcp:$DB_NB_SYNC_FROM_ADDR:$DB_NB_SYNC_FROM_PORT" > $ovnnb_active_conf_file + fi + + if test -e $ovnnb_active_conf_file; then + set "$@" --sync-from=`cat $ovnnb_active_conf_file` + fi $@ $DB_NB_FILE fi @@ -63,11 +117,45 @@ start_ovsdb () { set ovsdb-server - set "$@" --detach --monitor $OVN_SB_LOG --log-file=$OVN_SB_LOGFILE --remote=punix:$DB_SB_SOCK --remote=ptcp:$DB_SB_PORT:$DB_SB_ADDR --pidfile=$DB_SB_PID --unixctl=ovnsb_db.ctl + set "$@" --detach --monitor $OVN_SB_LOG \ + --log-file=$OVN_SB_LOGFILE \ + --remote=punix:$DB_SB_SOCK \ + --remote=ptcp:$DB_SB_PORT:$DB_SB_ADDR \ + --pidfile=$DB_SB_PID \ + --unixctl=ovnsb_db.ctl + + if test ! -z "$DB_SB_SYNC_FROM_ADDR"; then + echo "tcp:$DB_SB_SYNC_FROM_ADDR:$DB_SB_SYNC_FROM_PORT" > $ovnsb_active_conf_file + fi + + if test -e $ovnsb_active_conf_file; then + set "$@" --sync-from=`cat $ovnsb_active_conf_file` + fi + $@ $DB_SB_FILE fi } +sync_status() { + ovs-appctl -t $rundir/ovn${1}_db.ctl ovsdb-server/sync-status | awk '{if(NR==1) print $2}' +} + +status_ovnnb() { + if ! pidfile_is_running $DB_NB_PID; then + echo "not-running" + else + echo "running/$(sync_status nb)" + fi +} + +status_ovnsb() { + if ! pidfile_is_running $DB_SB_PID; then + echo "not-running" + else + echo "running/$(sync_status sb)" + fi +} + status_ovsdb () { if ! pidfile_is_running $DB_NB_PID; then log_success_msg "OVN Northbound DB is not running" @@ -83,29 +171,36 @@ status_ovsdb () { } start_northd () { - if test X"$OVN_MANAGE_OVSDB" = Xyes; then - start_ovsdb - fi + if [ ! -e $ovn_northd_db_conf_file ]; then + if test X"$OVN_MANAGE_OVSDB" = Xyes; then + start_ovsdb + fi + + if ! pidfile_is_running $DB_NB_PID; then + log_failure_msg "OVN Northbound DB is not running" + exit + fi + if ! pidfile_is_running $DB_SB_PID; then + log_failure_msg "OVN Southbound DB is not running" + exit + fi + ovn_northd_params="--ovnnb-db=unix:$DB_NB_SOCK --ovnsb-db=unix:$DB_SB_SOCK" + else + ovn_northd_params="`cat $ovn_northd_db_conf_file`" + fi - if ! pidfile_is_running $DB_NB_PID; then - log_failure_msg "OVN Northbound DB is not running" - exit - fi - if ! pidfile_is_running $DB_SB_PID; then - log_failure_msg "OVN Southbound DB is not running" - exit - fi + if daemon_is_running ovn-northd; then + log_success_msg "ovn-northd is already running" + else + set ovn-northd + if test X"$OVN_NORTHD_LOGFILE" != X; then + set "$@" --log-file=$OVN_NORTHD_LOGFILE + fi - if daemon_is_running ovn-northd; then - log_success_msg "ovn-northd is already running" - else - set ovn-northd - if test X"$OVN_NORTHD_LOGFILE" != X; then - set "$@" --log-file=$OVN_NORTHD_LOGFILE - fi - set "$@" $OVN_NORTHD_LOG --ovnnb-db=unix:$DB_NB_SOCK --ovnsb-db=unix:$DB_SB_SOCK - OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_NORTHD_PRIORITY" "$OVN_NORTHD_WRAPPER" "$@" - fi + set "$@" $OVN_NORTHD_LOG $ovn_northd_params + + OVS_RUNDIR=${OVN_RUNDIR} start_daemon "$OVN_NORTHD_PRIORITY" "$OVN_NORTHD_WRAPPER" "$@" + fi } start_controller () { @@ -127,8 +222,10 @@ start_controller_vtep () { stop_northd () { OVS_RUNDIR=${OVN_RUNDIR} stop_daemon ovn-northd - if test X"$OVN_MANAGE_OVSDB" = Xyes; then - stop_ovsdb + if [ ! -e $ovn_northd_db_conf_file ]; then + if test X"$OVN_MANAGE_OVSDB" = Xyes; then + stop_ovsdb + fi fi } @@ -176,12 +273,16 @@ set_defaults () { DB_NB_FILE=$dbdir/ovnnb_db.db DB_NB_ADDR=0.0.0.0 DB_NB_PORT=6641 + DB_NB_SYNC_FROM_ADDR= + DB_NB_SYNC_FROM_PORT=6641 DB_SB_SOCK=$rundir/ovnsb_db.sock DB_SB_PID=$rundir/ovnsb_db.pid DB_SB_FILE=$dbdir/ovnsb_db.db DB_SB_ADDR=0.0.0.0 DB_SB_PORT=6642 + 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 @@ -272,6 +373,10 @@ File location options: --db-sb-port=PORT OVN Southbound db ptcp port (default: $DB_SB_PORT) --ovn-nb-logfile=FILE OVN Northbound log file (default: $OVN_NB_LOGFILE) --ovn-sb-logfile=FILE OVN Southbound log file (default: $OVN_SB_LOGFILE) + --db-nb-sync-from-addr=ADDR OVN Northbound active db tcp address (default: $DB_NB_SYNC_FROM_ADDR) + --db-nb-sync-from-port=PORT OVN Northdbound active db tcp port (default: $DB_NB_SYNC_FROM_PORT) + --db-sb-sync-from-addr=ADDR OVN Southbound active db tcp address (default: $DB_SB_SYNC_FROM_ADDR) + --db-sb-sync-from-port=ADDR OVN Southbound active db tcp port (default: $DB_SB_SYNC_FROM_PORT) Default directories with "configure" option and environment variable override: logs: /usr/local/var/log/openvswitch (--with-logdir, OVS_LOGDIR) @@ -377,6 +482,24 @@ case $command in status_controller_vtep) daemon_status ovn-controller-vtep || exit 1 ;; + promote_ovnnb) + promote_ovnnb + ;; + promote_ovnsb) + promote_ovnsb + ;; + demote_ovnnb) + demote_ovnnb + ;; + demote_ovnsb) + demote_ovnsb + ;; + status_ovnnb) + status_ovnnb + ;; + status_ovnsb) + status_ovnsb + ;; help) usage ;; -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev