From 6e3fe059d8bbcbb6b0c3bdcd8d446e1401e6e563 Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Thu, 9 Jan 2014 14:12:37 +0100 Subject: [PATCH] added config options pg_bindir and pg_ctl_options --- config.c | 12 ++++++++++++ config.h | 2 ++ repmgr.c | 19 ++++++++----------- repmgr.conf.sample | 8 ++++++++ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index 3b6ffca6..6f8f0362 100644 --- a/config.c +++ b/config.c @@ -42,6 +42,8 @@ parse_config(const char *config_file, t_configuration_options *options) memset(options->follow_command, 0, sizeof(options->follow_command)); memset(options->rsync_options, 0, sizeof(options->rsync_options)); memset(options->ssh_options, 0, sizeof(options->ssh_options)); + memset(options->pg_bindir, 0, sizeof(options->pg_bindir)); + memset(options->pgctl_options, 0, sizeof(options->pgctl_options)); /* if nothing has been provided defaults to 60 */ options->master_response_timeout = 60; @@ -114,6 +116,10 @@ parse_config(const char *config_file, t_configuration_options *options) options->reconnect_attempts = atoi(value); else if (strcmp(name, "reconnect_interval") == 0) options->reconnect_intvl = atoi(value); + else if (strcmp(name, "pg_bindir") == 0) + strncpy (options->pg_bindir, value, MAXLEN); + else if (strcmp(name, "pg_ctl_options") == 0) + strncpy (options->pgctl_options, value, MAXLEN); else log_warning(_("%s/%s: Unknown name/value pair!\n"), name, value); } @@ -151,6 +157,12 @@ parse_config(const char *config_file, t_configuration_options *options) log_err(_("Reconnect intervals must be zero or greater. Check the configuration file.\n")); exit(ERR_BAD_CONFIG); } + + if (*options->pg_bindir == '\0') + { + log_err(_("pg_bindir config value not found. Check the configuration file.\n")); + exit(ERR_BAD_CONFIG); + } } diff --git a/config.h b/config.h index 9e4d3c67..cd4e9a7d 100644 --- a/config.h +++ b/config.h @@ -40,6 +40,8 @@ typedef struct int master_response_timeout; int reconnect_attempts; int reconnect_intvl; + char pg_bindir[MAXLEN]; + char pgctl_options[MAXLEN]; } t_configuration_options; void parse_config(const char *config_file, t_configuration_options *options); diff --git a/repmgr.c b/repmgr.c index b6a9bc9e..aa7f1acc 100644 --- a/repmgr.c +++ b/repmgr.c @@ -86,7 +86,7 @@ bool require_password = false; /* Initialization of runtime options */ t_runtime_options runtime_options = { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0 }; -t_configuration_options options = { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1 }; +t_configuration_options options = { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "" }; static char *server_mode = NULL; static char *server_cmd = NULL; @@ -1317,13 +1317,12 @@ do_standby_promote(void) rename(recovery_file_path, recovery_done_path); /* - * We assume the pg_ctl script is in the PATH. Restart and wait for - * the server to finish starting, so that the check below will - * find an active server rather than one starting up. This may + * Restart and wait for the server to finish starting, so that the check + * below will find an active server rather than one starting up. This may * hang for up the default timeout (60 seconds). */ - log_notice(_("%s: restarting server using pg_ctl\n"), progname); - maxlen_snprintf(script, "pg_ctl -D %s -w -m fast restart", data_dir); + log_notice(_("%s: restarting server using %s/pg_ctl\n"), progname, options.pg_bindir); + maxlen_snprintf(script, "%s/pg_ctl %s -D %s -w -m fast restart", options.pg_bindir, options.pgctl_options, data_dir); r = system(script); if (r != 0) { @@ -1468,8 +1467,7 @@ do_standby_follow(void) exit(ERR_BAD_CONFIG); /* Finally, restart the service */ - /* We assume the pg_ctl script is in the PATH */ - maxlen_snprintf(script, "pg_ctl -w -D %s -m fast restart", data_dir); + maxlen_snprintf(script, "%s/pg_ctl %s -w -D %s -m fast restart", options.pg_bindir, options.pgctl_options, data_dir); r = system(script); if (r != 0) { @@ -1558,8 +1556,7 @@ do_witness_create(void) */ /* Create the cluster for witness */ - /* We assume the pg_ctl script is in the PATH */ - sprintf(script, "pg_ctl -D %s init -o \"-W\"", runtime_options.dest_dir); + sprintf(script, "%s/pg_ctl %s -D %s init -o \"-W\"", options.pg_bindir, options.pgctl_options, runtime_options.dest_dir); log_info("Initialize cluster for witness: %s.\n", script); r = system(script); @@ -1632,7 +1629,7 @@ do_witness_create(void) } /* start new instance */ - sprintf(script, "pg_ctl -w -D %s start", runtime_options.dest_dir); + sprintf(script, "%s/pg_ctl %s -w -D %s start", options.pg_bindir, options.pgctl_options, runtime_options.dest_dir); log_info(_("Start cluster for witness: %s"), script); r = system(script); if (r != 0) diff --git a/repmgr.conf.sample b/repmgr.conf.sample index 86378b46..8a8de2d4 100644 --- a/repmgr.conf.sample +++ b/repmgr.conf.sample @@ -34,3 +34,11 @@ loglevel=NOTICE # Logging facility: possible values are STDERR or - for Syslog integration - one of LOCAL0, LOCAL1, ..., LOCAL7, USER # Default: STDERR logfacility=STDERR + +# path to pg_ctl executable +pg_bindir=/usr/bin/ + +# +# you may add command line arguments for pg_ctl +# +# pg_ctl_options='-s' \ No newline at end of file