mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 15:16:29 +00:00
repmgr: improve switchover handling when "pg_ctl" used
If logging output not explicitly rediretced with "-l" in the pg_ctl options, repmgr would hang waiting for pg_ctl output. Note that we recommend using the OS-level service commands where available.
This commit is contained in:
@@ -1905,7 +1905,10 @@ do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_recor
|
||||
char server_command[MAXLEN] = "";
|
||||
bool server_up = is_server_available(config_file_options.conninfo);
|
||||
char *action = NULL;
|
||||
int r;
|
||||
bool success;
|
||||
|
||||
PQExpBufferData output_buf;
|
||||
initPQExpBuffer(&output_buf);
|
||||
|
||||
if (server_up == true)
|
||||
{
|
||||
@@ -1923,8 +1926,9 @@ do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_recor
|
||||
action,
|
||||
server_command);
|
||||
|
||||
r = system(server_command);
|
||||
if (r != 0)
|
||||
success = local_command(server_command, &output_buf);
|
||||
|
||||
if (success == false)
|
||||
{
|
||||
log_error(_("unable to %s server"), action);
|
||||
PQfinish(primary_conn);
|
||||
@@ -2735,7 +2739,8 @@ do_standby_switchover(void)
|
||||
termPQExpBuffer(&command_output);
|
||||
}
|
||||
|
||||
log_debug("sleeping %i seconds until next check", config_file_options.reconnect_interval);
|
||||
log_debug("sleeping %i seconds (\"reconnect_interval\") until next check",
|
||||
config_file_options.reconnect_interval);
|
||||
sleep(config_file_options.reconnect_interval);
|
||||
}
|
||||
|
||||
@@ -2845,13 +2850,10 @@ do_standby_switchover(void)
|
||||
|
||||
/* TODO: verify this node's record was updated correctly */
|
||||
|
||||
if (command_success == false || command_output.data[0] == '0')
|
||||
if (command_success == false)
|
||||
{
|
||||
log_error(_("rejoin failed %i"), r);
|
||||
|
||||
if (strlen(command_output.data) > 2)
|
||||
log_detail("%s", command_output.data);
|
||||
|
||||
create_event_notification_extended(local_conn,
|
||||
&config_file_options,
|
||||
config_file_options.node_id,
|
||||
|
||||
@@ -2101,9 +2101,12 @@ test_ssh_connection(char *host, char *remote_user)
|
||||
bool
|
||||
local_command(const char *command, PQExpBufferData *outputbuf)
|
||||
{
|
||||
FILE *fp;
|
||||
FILE *fp = NULL;
|
||||
char output[MAXLEN];
|
||||
int retval = 0;
|
||||
bool success;
|
||||
|
||||
log_verbose(LOG_DEBUG, "executing:\n %s", command);
|
||||
|
||||
if (outputbuf == NULL)
|
||||
{
|
||||
@@ -2119,20 +2122,28 @@ local_command(const char *command, PQExpBufferData *outputbuf)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO: better error handling */
|
||||
|
||||
while (fgets(output, MAXLEN, fp) != NULL)
|
||||
{
|
||||
appendPQExpBuffer(outputbuf, "%s", output);
|
||||
if (!feof(fp))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
retval = pclose(fp);
|
||||
|
||||
success = (WEXITSTATUS(retval) == 0) ? true : false;
|
||||
|
||||
log_verbose(LOG_DEBUG, "result of command was %i (%i)", WEXITSTATUS(retval), retval);
|
||||
|
||||
if (outputbuf->data != NULL)
|
||||
log_verbose(LOG_DEBUG, "local_command(): output returned was:\n%s", outputbuf->data);
|
||||
else
|
||||
log_verbose(LOG_DEBUG, "local_command(): no output returned");
|
||||
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
@@ -2394,7 +2405,12 @@ remote_command(const char *host, const char *user, const char *command, PQExpBuf
|
||||
pclose(fp);
|
||||
|
||||
if (outputbuf != NULL)
|
||||
log_verbose(LOG_DEBUG, "remote_command(): output returned was:\n %s", outputbuf->data);
|
||||
{
|
||||
if (strlen(outputbuf->data))
|
||||
log_verbose(LOG_DEBUG, "remote_command(): output returned was:\n %s", outputbuf->data);
|
||||
else
|
||||
log_verbose(LOG_DEBUG, "remote_command(): no output returned");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user