mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +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] = "";
|
char server_command[MAXLEN] = "";
|
||||||
bool server_up = is_server_available(config_file_options.conninfo);
|
bool server_up = is_server_available(config_file_options.conninfo);
|
||||||
char *action = NULL;
|
char *action = NULL;
|
||||||
int r;
|
bool success;
|
||||||
|
|
||||||
|
PQExpBufferData output_buf;
|
||||||
|
initPQExpBuffer(&output_buf);
|
||||||
|
|
||||||
if (server_up == true)
|
if (server_up == true)
|
||||||
{
|
{
|
||||||
@@ -1923,8 +1926,9 @@ do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_recor
|
|||||||
action,
|
action,
|
||||||
server_command);
|
server_command);
|
||||||
|
|
||||||
r = system(server_command);
|
success = local_command(server_command, &output_buf);
|
||||||
if (r != 0)
|
|
||||||
|
if (success == false)
|
||||||
{
|
{
|
||||||
log_error(_("unable to %s server"), action);
|
log_error(_("unable to %s server"), action);
|
||||||
PQfinish(primary_conn);
|
PQfinish(primary_conn);
|
||||||
@@ -2735,7 +2739,8 @@ do_standby_switchover(void)
|
|||||||
termPQExpBuffer(&command_output);
|
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);
|
sleep(config_file_options.reconnect_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2845,13 +2850,10 @@ do_standby_switchover(void)
|
|||||||
|
|
||||||
/* TODO: verify this node's record was updated correctly */
|
/* 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);
|
log_error(_("rejoin failed %i"), r);
|
||||||
|
|
||||||
if (strlen(command_output.data) > 2)
|
|
||||||
log_detail("%s", command_output.data);
|
|
||||||
|
|
||||||
create_event_notification_extended(local_conn,
|
create_event_notification_extended(local_conn,
|
||||||
&config_file_options,
|
&config_file_options,
|
||||||
config_file_options.node_id,
|
config_file_options.node_id,
|
||||||
|
|||||||
@@ -2101,9 +2101,12 @@ test_ssh_connection(char *host, char *remote_user)
|
|||||||
bool
|
bool
|
||||||
local_command(const char *command, PQExpBufferData *outputbuf)
|
local_command(const char *command, PQExpBufferData *outputbuf)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp = NULL;
|
||||||
char output[MAXLEN];
|
char output[MAXLEN];
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
bool success;
|
||||||
|
|
||||||
|
log_verbose(LOG_DEBUG, "executing:\n %s", command);
|
||||||
|
|
||||||
if (outputbuf == NULL)
|
if (outputbuf == NULL)
|
||||||
{
|
{
|
||||||
@@ -2119,20 +2122,28 @@ local_command(const char *command, PQExpBufferData *outputbuf)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: better error handling */
|
|
||||||
while (fgets(output, MAXLEN, fp) != NULL)
|
while (fgets(output, MAXLEN, fp) != NULL)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(outputbuf, "%s", output);
|
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)
|
if (outputbuf->data != NULL)
|
||||||
log_verbose(LOG_DEBUG, "local_command(): output returned was:\n%s", outputbuf->data);
|
log_verbose(LOG_DEBUG, "local_command(): output returned was:\n%s", outputbuf->data);
|
||||||
else
|
else
|
||||||
log_verbose(LOG_DEBUG, "local_command(): no output returned");
|
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);
|
pclose(fp);
|
||||||
|
|
||||||
if (outputbuf != NULL)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user