Skip to content

Commit

Permalink
Fix: tools: crm_mon --daemonize should update when disconnected
Browse files Browse the repository at this point in the history
With crm_mon --daemonize, the output will continue to show the last
known status after the cluster is stopped on the local node. It
should go back to something like "Cluster is not available".

It's questionable whether we want to print "Cluster is not available"
when we're in interactive mode or only in daemonized mode. For now,
we'll do daemonized-only. Interactive (console) mode already gets the
"Connection to cluster daemons terminated" message, which is quickly
replaced by "Reconnecting...".

External agents are notified via traps rather than via output, so we can
ignore them.

Closes T15

Signed-off-by: Reid Wahl <[email protected]>
  • Loading branch information
nrwahl2 committed Sep 15, 2022
1 parent 64172ba commit ba96437
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions tools/crm_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ mon_cib_connection_destroy(gpointer user_data)
reconnect_timer = g_timeout_add(options.reconnect_ms,
reconnect_after_timeout, NULL);
}
return;
refresh_after_event(FALSE, TRUE);
}

/* Signal handler installed into the mainloop for normal program shutdown */
Expand Down Expand Up @@ -1992,6 +1992,7 @@ static int
mon_refresh_display(gpointer user_data)
{
int rc = pcmk_rc_ok;
crm_exit_t exit_code = CRM_EX_OK;

last_refresh = time(NULL);

Expand All @@ -2009,10 +2010,30 @@ mon_refresh_display(gpointer user_data)
out->reset(out);
}

rc = pcmk__output_cluster_status(out, st, cib, current_cib, fence_history,
show, show_opts, options.only_node,
options.only_rsc, options.neg_location_prefix,
output_format == mon_output_monitor);
if ((cib != NULL) && (cib->state != cib_disconnected)) {
rc = pcmk__output_cluster_status(out, st, cib, current_cib,
fence_history, show, show_opts,
options.only_node, options.only_rsc,
options.neg_location_prefix,
output_format == mon_output_monitor);
} else {
exit_code = CRM_EX_DISCONNECT;

// Print an unavailable message for daemonized crm_mon
switch (output_format) {
case mon_output_plain:
// out->err() goes to stderr instead of to out->dest
out->info(out, "Cluster is not available");
break;
case mon_output_html:
case mon_output_xml:
// out->info() is a no-op
out->err(out, "Cluster is not available");
break;
default:
break;
}
}

if (output_format == mon_output_monitor && rc != pcmk_rc_ok) {
clean_up(MON_STATUS_WARN);
Expand All @@ -2023,7 +2044,7 @@ mon_refresh_display(gpointer user_data)
}

if (out->dest != stdout) {
out->finish(out, CRM_EX_OK, true, NULL);
out->finish(out, exit_code, true, NULL);
}

return G_SOURCE_CONTINUE;
Expand Down Expand Up @@ -2070,7 +2091,7 @@ refresh_after_event(gboolean data_updated, gboolean enforce)
refresh_timer = mainloop_timer_add("refresh", 2000, FALSE, mon_trigger_refresh, NULL);
}

if (reconnect_timer > 0) {
if (!enforce && (reconnect_timer > 0)) {
/* we will receive a refresh request after successful reconnect */
mainloop_timer_stop(refresh_timer);
return;
Expand Down

0 comments on commit ba96437

Please sign in to comment.