From d4ee4cc14ca80bd5070ec438aedd4951f38471b0 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 30 Jan 2019 14:49:43 +0900 Subject: [PATCH] "daemon stop": be careful with hints about "daemon status" If PostgreSQL is not running, "repmgr daemon status" can't be executed. --- repmgr-action-daemon.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/repmgr-action-daemon.c b/repmgr-action-daemon.c index df20b561..17c66c28 100644 --- a/repmgr-action-daemon.c +++ b/repmgr-action-daemon.c @@ -524,6 +524,7 @@ void do_daemon_stop(void) PQExpBufferData repmgrd_command; PQExpBufferData output_buf; bool success; + bool have_db_connection = true; pid_t pid = UNKNOWN_PID; if (config_file_options.repmgrd_service_stop_command[0] == '\0') @@ -547,6 +548,7 @@ void do_daemon_stop(void) * a PostgreSQL connection is not required to stop repmgrd, */ log_warning(_("unable to connect to local node")); + have_db_connection = false; } else { @@ -598,7 +600,8 @@ void do_daemon_stop(void) if (runtime_options.no_wait == true || runtime_options.wait == 0) { - log_hint(REPMGR_DAEMON_STATUS_STOP_HINT); + if (have_db_connection == true) + log_hint(REPMGR_DAEMON_STATUS_STOP_HINT); } else { @@ -616,7 +619,10 @@ void do_daemon_stop(void) * if PID still unknown, exit here */ log_warning(_("unable to determine repmgrd PID")); - log_hint(REPMGR_DAEMON_STATUS_STOP_HINT); + + if (have_db_connection == true) + log_hint(REPMGR_DAEMON_STATUS_STOP_HINT); + exit(ERR_REPMGRD_SERVICE); } @@ -645,7 +651,10 @@ void do_daemon_stop(void) { log_error(_("repmgrd does not appear to have stopped after %i seconds"), timeout); - log_hint(REPMGR_DAEMON_STATUS_START_HINT); + + if (have_db_connection == true) + log_hint(REPMGR_DAEMON_STATUS_START_HINT); + exit(ERR_REPMGRD_SERVICE); }