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 Oct 4, 2022
1 parent eefc796 commit f25ded7
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions tools/crm_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,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 @@ -1989,6 +1989,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 @@ -2006,10 +2007,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 @@ -2020,7 +2041,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 All @@ -2045,6 +2066,7 @@ mon_st_callback_event(stonith_t * st, stonith_event_t * e)

/* Cause the screen to be redrawn (via mainloop_set_trigger) when various conditions are met:
*
* - The enforce option is set to true, or
* - If the last update occurred more than reconnect_ms ago (defaults to 5s, but
* can be changed via the -i command line option), or
* - After every 10 CIB updates, or
Expand All @@ -2067,7 +2089,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 f25ded7

Please sign in to comment.