From 92d0e6809b9f9879efb6c73ae4edca8bbe369060 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 5 Jul 2018 13:32:50 +0900 Subject: [PATCH] repmgr: "cluster show" to return non-zero value if an issue encountered --- HISTORY | 1 + doc/repmgr-node-status.sgml | 29 +++++++++++++++++++++++++++++ repmgr-action-node.c | 14 +++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/HISTORY b/HISTORY index 26e063b5..a853e75f 100644 --- a/HISTORY +++ b/HISTORY @@ -4,6 +4,7 @@ repmgr: fix "standby register --wait-sync" when no timeout provided (Ian) repmgr: "cluster show" returns non-zero value if an issue encountered; GitHub #456 (Ian) + repmgr: "node status" returns non-zero value if an issue encountered (Ian) repmgrd: create a PID file by default; GitHub #457 (Ian) repmgrd: daemonize process by default; GitHub #458 (Ian) diff --git a/doc/repmgr-node-status.sgml b/doc/repmgr-node-status.sgml index c7474e67..d85f819b 100644 --- a/doc/repmgr-node-status.sgml +++ b/doc/repmgr-node-status.sgml @@ -52,6 +52,35 @@ + + Exit codes + + Following exit codes can be emitted by repmgr node status: + + + + + + + + No issues were detected. + + + + + + + + + One or more issues were detected. + + + + + + + + See also diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 07389e36..88493343 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -487,7 +487,7 @@ do_node_status(void) termPQExpBuffer(&output); - if (runtime_options.output_mode == OM_TEXT && warnings.head != NULL && runtime_options.terse == false) + if (warnings.head != NULL && runtime_options.terse == false && runtime_options.output_mode == OM_TEXT) { log_warning(_("following issue(s) were detected:")); print_item_list(&warnings); @@ -498,8 +498,20 @@ do_node_status(void) key_value_list_free(&node_status); item_list_free(&warnings); PQfinish(conn); + + /* + * If warnings were noted, even if they're not displayed (e.g. in --csv node), + * that means something's not right so we need to emit a non-zero exit code. + */ + if (warnings.head != NULL) + { + exit(ERR_NODE_STATUS); + } + + return; } + /* * Returns information about the running state of the node. * For internal use during "standby switchover".