Skip to content

Commit

Permalink
ovn-ctl: stop databases with stop_ovn_daemon()
Browse files Browse the repository at this point in the history
Wait for the databases to actually exit before returning to
the caller of ovn-ctl. In containerized use-cases the container
runtime often kills the container when the process calling
ovn-ctl exits, which may not give the DBs time to clean up
after themselves.

Reported-at: https://bugzilla.redhat.com/1944239

Signed-off-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
  • Loading branch information
dcbw authored and numansiddique committed Apr 20, 2021
1 parent d7db870 commit f4b4465
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
16 changes: 5 additions & 11 deletions utilities/ovn-ctl
Expand Up @@ -45,18 +45,12 @@ pidfile_is_running () {
test -e "$pidfile" && [ -s "$pidfile" ] && pid=`cat "$pidfile"` && pid_exists "$pid"
} >/dev/null 2>&1

stop_xx_ovsdb() {
if pidfile_is_running $1; then
ovn-appctl -t $OVN_RUNDIR/$2 exit
fi
}

stop_nb_ovsdb() {
stop_xx_ovsdb $DB_NB_PID ovnnb_db.ctl
OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovnnb_db $DB_NB_PID $OVN_RUNDIR/ovnnb_db.ctl
}

stop_sb_ovsdb() {
stop_xx_ovsdb $DB_SB_PID ovnsb_db.ctl
OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovnsb_db $DB_SB_PID $OVN_RUNDIR/ovnsb_db.ctl
}

stop_ovsdb () {
Expand All @@ -65,11 +59,11 @@ stop_ovsdb () {
}

stop_ic_nb_ovsdb() {
stop_xx_ovsdb $DB_IC_NB_PID ovn_ic_nb_db.ctl
OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn_ic_nb_db $DB_IC_NB_PID $OVN_RUNDIR/ovn_ic_nb_db.ctl
}

stop_ic_sb_ovsdb() {
stop_xx_ovsdb $DB_IC_SB_PID ovn_ic_sb_db.ctl
OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn_ic_sb_db $DB_IC_SB_PID $OVN_RUNDIR/ovn_ic_sb_db.ctl
}

stop_ic_ovsdb () {
Expand Down Expand Up @@ -590,7 +584,7 @@ stop_ic () {
}

stop_controller () {
OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn-controller "$@"
OVS_RUNDIR=${OVS_RUNDIR} stop_ovn_daemon ovn-controller "" "" "$@"
}

stop_controller_vtep () {
Expand Down
24 changes: 18 additions & 6 deletions utilities/ovn-lib.in
Expand Up @@ -137,18 +137,30 @@ start_ovn_daemon () {
}

stop_ovn_daemon () {
if test -e "$ovn_rundir/$1.pid"; then
if pid=`cat "$ovn_rundir/$1.pid"`; then
local pid_file=$2
local ctl_file=$3
local other_args=$4

if [ -z "$pid_file" ]; then
pid_file="$ovn_rundir/$1.pid"
fi

if test -e "$pid_file"; then
if pid=`cat "$pid_file"`; then
if [ -z "$ctl_file" ]; then
ctl_file="$ovn_rundir/$1.$pid.ctl"
fi

if pid_exists "$pid" >/dev/null 2>&1; then :; else
rm -f $ovn_rundir/$1.$pid.ctl $ovn_rundir/$1.$pid
rm -f $ctl_file $pid_file
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 \
version=`ovs-appctl -T 1 -t $ctl_file version \
| awk 'NR==1{print $NF}'`

# Use `ovs-appctl exit` only if the running daemon version
Expand All @@ -169,15 +181,15 @@ stop_ovn_daemon () {
# But, does the file exist? We may have had a daemon
# segfault with `ovs-appctl exit`. Check one more time
# before deciding that the daemon is dead.
[ -e "$ovn_rundir/$1.pid" ] && sleep 2 && pid=`cat "$ovn_rundir/$1.pid"` 2>/dev/null
[ -e "$pid_file" ] && sleep 2 && pid=`cat "$pid_file"` 2>/dev/null
if pid_exists "$pid" >/dev/null 2>&1; then :; else
return 0
fi
fi
case $action in
EXIT)
action "Exiting $1 ($pid)" \
${bindir}/ovs-appctl -T 1 -t $ovn_rundir/$1.$pid.ctl exit $2
${bindir}/ovs-appctl -T 1 -t $ctl_file exit $other_args
# The above command could have resulted in delayed
# daemon segfault. And if a monitor is running, it
# would restart the daemon giving it a new pid.
Expand Down

0 comments on commit f4b4465

Please sign in to comment.