From 81beec54aab55d64db9fceab51df783cff3f43fe Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 23 Nov 2017 10:33:39 +0900 Subject: [PATCH] repmgr: fix return code output for repmgr node check --action=... Addresses GitHub #340 --- HISTORY | 8 +++++++- dbutils.c | 2 +- doc/appendix-release-notes.sgml | 34 +++++++++++++++++++++++++++++++++ repmgr-action-node.c | 34 +++++++++++++++++++++++---------- repmgr-action-node.h | 1 - strutil.h | 13 +++++++++---- 6 files changed, 75 insertions(+), 17 deletions(-) diff --git a/HISTORY b/HISTORY index 12580f24..6721fa4d 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,12 @@ +4.0.1 2017-11- + repmgr: ensure "repmgr node check --action=" returns appropriate return + code (Ian) + repmgr: add missing schema qualification in get_all_node_records_with_upstream() + query (Martín) + 4.0.0 2017-11-21 Complete rewrite with many changes; for details see the repmgr 4.0.0 release - notes at: https://repmgr.org/docs/4.0/release-4.0.html + notes at: https://repmgr.org/docs/4.0/release-4.0.0.html 3.3.2 2017-06-01 Add support for PostgreSQL 10 (Ian) diff --git a/dbutils.c b/dbutils.c index f2b8059f..2b28a7cf 100644 --- a/dbutils.c +++ b/dbutils.c @@ -4050,7 +4050,7 @@ is_active_bdr_node(PGconn *conn, const char *node_name) appendPQExpBuffer(&query, " SELECT COALESCE(s.active, TRUE) AS active" " FROM bdr.bdr_nodes n " - " LEFT JOIN pg_replication_slots s " + " LEFT JOIN pg_catalog.pg_replication_slots s " " ON slot_name=bdr.bdr_format_slot_name(n.node_sysid, n.node_timeline, n.node_dboid, (SELECT oid FROM pg_database WHERE datname = current_database())) " " WHERE node_name='%s' ", node_name); diff --git a/doc/appendix-release-notes.sgml b/doc/appendix-release-notes.sgml index 24ceea3d..cc848927 100644 --- a/doc/appendix-release-notes.sgml +++ b/doc/appendix-release-notes.sgml @@ -16,6 +16,40 @@ See also: + + Release 4.0.1 + + 2017 + + + repmgr 4.0.1 is a bugfix release. + + + Bug fixes + + + + + ensure correct return codes are returned for + repmgr node check --action= operations + (GitHub #340) + + + + + + Fix when repmgr schema not set in search path + (GitHub #341) + + + + + + + + + + Release 4.0.0 diff --git a/repmgr-action-node.c b/repmgr-action-node.c index d084822c..f1160bd7 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -559,6 +559,7 @@ do_node_check(void) t_node_info node_info = T_NODE_INFO_INITIALIZER; + CheckStatus return_code; CheckStatusList status_list = {NULL, NULL}; CheckStatusListCell *cell = NULL; @@ -585,38 +586,51 @@ do_node_check(void) */ if (runtime_options.archive_ready == true) { - (void) do_node_check_archive_ready(conn, runtime_options.output_mode, NULL); + return_code = do_node_check_archive_ready(conn, + runtime_options.output_mode, + NULL); PQfinish(conn); - return; + exit(return_code); } if (runtime_options.downstream == true) { - (void) do_node_check_downstream(conn, runtime_options.output_mode, NULL); + return_code = do_node_check_downstream(conn, + runtime_options.output_mode, + NULL); PQfinish(conn); - return; + exit(return_code); } if (runtime_options.replication_lag == true) { - (void) do_node_check_replication_lag(conn, runtime_options.output_mode, &node_info, NULL); + return_code = do_node_check_replication_lag(conn, + runtime_options.output_mode, + &node_info, + NULL); PQfinish(conn); - return; + exit(return_code); } if (runtime_options.role == true) { - (void) do_node_check_role(conn, runtime_options.output_mode, &node_info, NULL); + return_code = do_node_check_role(conn, + runtime_options.output_mode, + &node_info, + NULL); PQfinish(conn); - return; + exit(return_code); } if (runtime_options.slots == true) { - (void) do_node_check_slots(conn, runtime_options.output_mode, &node_info, NULL); + return_code = do_node_check_slots(conn, + runtime_options.output_mode, + &node_info, + NULL); PQfinish(conn); - return; + exit(return_code); } if (runtime_options.output_mode == OM_NAGIOS) diff --git a/repmgr-action-node.h b/repmgr-action-node.h index 3e0ac400..2ffabca1 100644 --- a/repmgr-action-node.h +++ b/repmgr-action-node.h @@ -22,7 +22,6 @@ extern void do_node_status(void); extern void do_node_check(void); - extern void do_node_rejoin(void); extern void do_node_service(void); diff --git a/strutil.h b/strutil.h index df7ea9f2..19faffd7 100644 --- a/strutil.h +++ b/strutil.h @@ -33,12 +33,17 @@ #define MAXLEN_STR STR(MAXLEN) +/* + * These values must match the Nagios return codes defined here: + * + * https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/pluginapi.html + */ typedef enum { - CHECK_STATUS_OK = 0, - CHECK_STATUS_WARNING, - CHECK_STATUS_CRITICAL, - CHECK_STATUS_UNKNOWN + CHECK_STATUS_OK = 0, + CHECK_STATUS_WARNING = 1, + CHECK_STATUS_CRITICAL = 2, + CHECK_STATUS_UNKNOWN = 3 } CheckStatus; typedef enum