fixed some bugs with standby clone

This commit is contained in:
Gabriele Bartolini
2010-12-30 00:59:39 +01:00
committed by Greg Smith
parent 3f1c6a5852
commit 3146d2c676
2 changed files with 46 additions and 35 deletions

20
log.c
View File

@@ -59,7 +59,7 @@ bool logger_init(const char* ident, const char* level, const char* facility)
ident = DEFAULT_IDENT; ident = DEFAULT_IDENT;
} }
if (level) { if (level && *level) {
l = detect_log_level(level); l = detect_log_level(level);
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
printf("Assigned level for logger: %d\n", l); printf("Assigned level for logger: %d\n", l);
@@ -68,10 +68,10 @@ bool logger_init(const char* ident, const char* level, const char* facility)
if (l > 0) if (l > 0)
log_level = l; log_level = l;
else else
stderr_log_warning(_("Cannot detect log level %s (use any of DEBUG, INFO, NOTICE, WARNING, ERR, ALERT, CRIT or EMERG)"), level); stderr_log_warning(_("Cannot detect log level %s (use any of DEBUG, INFO, NOTICE, WARNING, ERR, ALERT, CRIT or EMERG)\n"), level);
} }
if (facility) { if (facility && *facility) {
f = detect_log_facility(facility); f = detect_log_facility(facility);
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
@@ -83,25 +83,27 @@ bool logger_init(const char* ident, const char* level, const char* facility)
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
printf(_("Use stderr for logging\n")); printf(_("Use stderr for logging\n"));
#endif #endif
return true;
} }
else if (f == -1) { else if (f == -1) {
stderr_log_warning(_("Cannot detect log facility %s (use any of LOCAL0, LOCAL1, ..., LOCAL7, USER or STDERR)"), facility); stderr_log_warning(_("Cannot detect log facility %s (use any of LOCAL0, LOCAL1, ..., LOCAL7, USER or STDERR)\n"), facility);
} }
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
else { else {
syslog_facility = f; syslog_facility = f;
log_type = REPMGR_SYSLOG;
} }
#endif #endif
} }
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
setlogmask (LOG_UPTO (log_level)); if (log_type == REPMGR_SYSLOG)
openlog (ident, LOG_CONS | LOG_PID | LOG_NDELAY, syslog_facility); {
setlogmask (LOG_UPTO (log_level));
openlog (ident, LOG_CONS | LOG_PID | LOG_NDELAY, syslog_facility);
log_type = REPMGR_SYSLOG; stderr_log_notice(_("Setup syslog (level: %s, facility: %s)\n"), level, facility);
stderr_log_notice(_("Setup syslog (level: %s, facility: %s)"), level, facility); }
#endif #endif

View File

@@ -63,6 +63,7 @@ static const char *progname;
static const char *keywords[6]; static const char *keywords[6];
static const char *values[6]; static const char *values[6];
char repmgr_schema[MAXLEN]; char repmgr_schema[MAXLEN];
bool read_config_file = true;
/* Initialization of runtime options */ /* Initialization of runtime options */
t_runtime_options runtime_options = { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, "" }; t_runtime_options runtime_options = { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, "" };
@@ -228,9 +229,6 @@ main(int argc, char **argv)
if (!check_parameters_for_action(action)) if (!check_parameters_for_action(action))
exit(1); exit(1);
if (!runtime_options.config_file[0])
strncpy(runtime_options.config_file, DEFAULT_CONFIG_FILE, MAXLEN);
if (!runtime_options.dbname[0]) if (!runtime_options.dbname[0])
{ {
if (getenv("PGDATABASE")) if (getenv("PGDATABASE"))
@@ -261,18 +259,25 @@ main(int argc, char **argv)
keywords[5] = NULL; keywords[5] = NULL;
values[5] = NULL; values[5] = NULL;
/* if (read_config_file) {
* Read the configuration file: repmgr.conf
*/ if (!runtime_options.config_file[0])
if (runtime_options.verbose) strncpy(runtime_options.config_file, DEFAULT_CONFIG_FILE, MAXLEN);
printf(_("Opening configuration file: %s\n"), runtime_options.config_file);
/*
* Read the configuration file: repmgr.conf
*/
if (runtime_options.verbose)
printf(_("Opening configuration file: %s\n"), runtime_options.config_file);
parse_config(runtime_options.config_file, &options);
if (options.node == -1)
{
log_err("Node information is missing. "
"Check the configuration file.\n");
exit(1);
}
parse_config(runtime_options.config_file, &options);
if (options.node == -1)
{
log_err("Node information is missing. "
"Check the configuration file.\n");
exit(1);
} }
logger_init(progname, options.loglevel, options.logfacility); logger_init(progname, options.loglevel, options.logfacility);
@@ -941,27 +946,30 @@ stop_backup:
return; return;
} }
last_wal_segment = PQgetvalue(res, 0, 0); last_wal_segment = PQgetvalue(res, 0, 0);
PQclear(res);
PQfinish(conn);
/* Now, if the rsync failed then exit */ /* Now, if the rsync failed then exit */
if (r != 0) if (r == 0)
return; {
if (runtime_options.verbose) if (runtime_options.verbose)
printf(_("%s requires primary to keep WAL files %s until at least %s\n"), printf(_("%s requires primary to keep WAL files %s until at least %s\n"),
progname, first_wal_segment, last_wal_segment); progname, first_wal_segment, last_wal_segment);
/* we need to create the pg_xlog sub directory too, i'm reusing a variable here */ /* we need to create the pg_xlog sub directory too, i'm reusing a variable here */
snprintf(local_control_file, MAXFILENAME, "%s/pg_xlog", runtime_options.dest_dir); snprintf(local_control_file, MAXFILENAME, "%s/pg_xlog", runtime_options.dest_dir);
if (!create_directory(local_control_file)) if (!create_directory(local_control_file))
{ {
log_err(_("%s: couldn't create directory %s, you will need to do it manually...\n"), log_err(_("%s: couldn't create directory %s, you will need to do it manually...\n"),
progname, runtime_options.dest_dir); progname, runtime_options.dest_dir);
}
/* Finally, write the recovery.conf file */
create_recovery_file(runtime_options.dest_dir);
} }
/* Finally, write the recovery.conf file */ PQclear(res);
create_recovery_file(runtime_options.dest_dir); PQfinish(conn);
/* We don't start the service because we still may want to move the directory */ /* We don't start the service because we still may want to move the directory */
return; return;
@@ -1414,6 +1422,7 @@ check_parameters_for_action(const int action)
usage(); usage();
ok = false; ok = false;
} }
read_config_file = false;
break; break;
} }