Compare commits

...

10 Commits

Author SHA1 Message Date
Christian Kruse
069f9ff2ed version push 2014-03-17 14:26:56 +01:00
Christian Kruse
b8ade8e908 fixing some documentation errors 2014-03-10 15:51:55 +01:00
Christian Kruse
c0abb3be31 Merge branch 'master' into REL2_0_STABLE 2014-03-06 15:23:52 +01:00
Christian Kruse
fed5c77653 various improvements and bugfixes in the init script 2014-03-06 15:23:22 +01:00
Christian Kruse
8429b43edf Merge pull request #14 from wamonite/fix_follow_user
fix: store the master connection user name on standby follow
2014-03-06 15:20:02 +01:00
Warren Moore
7e55ce737d fix: store the master connection user name on standby follow 2014-03-05 16:49:56 +00:00
Christian Kruse
98c7635fb5 fixing more compiler warnings 2014-03-04 17:58:36 +01:00
Christian Kruse
90ecb2b107 fix: check return values of freopen()
Some compiles complain about not checking the return value of freopen(),
so we check it
2014-03-04 15:32:48 +01:00
Christian Kruse
50b9022a41 fix: don't use Windows newlines 2014-03-04 12:59:23 +01:00
Christian Kruse
150ccc0662 add option to avoid repmgrd started upon installation
Now repmgr.repmgrd.default has another option: REPMGRD_ENABLED. Valid
values are either yes or no.
2014-03-04 12:46:05 +01:00
7 changed files with 179 additions and 75 deletions

View File

@@ -625,18 +625,18 @@ Now restore to the original configuration by stopping
primary server, then bringing up "node2" as a standby with a valid primary server, then bringing up "node2" as a standby with a valid
``recovery.conf`` file. ``recovery.conf`` file.
Stop the "node2" server:: Stop the "node2" server and type the following on "node1" server::
repmgr -f /var/lib/pgsql/repmgr/repmgr.conf standby promote repmgr -f /var/lib/pgsql/repmgr/repmgr.conf standby promote
Now the original primary, "node1" is acting again as primary. Now the original primary, "node1", is acting again as primary.
Start the "node2" server and type this on "node1":: Start the "node2" server and type this on "node2"::
repmgr standby clone --force -h node2 -p 5432 -U postgres -R postgres --verbose repmgr standby clone --force -h node2 -p 5432 -U postgres -R postgres --verbose
Verify the roles have reversed by attempting to insert a record on "node" Verify the roles have reversed by attempting to insert a record on "node1"
and on "node1". and on "node2".
The servers are now again acting as primary on "node1" and standby on "node2". The servers are now again acting as primary on "node1" and standby on "node2".

View File

@@ -1,14 +1,18 @@
#!/bin/sh
# default settings for repmgrd. This file is source by /bin/sh from # default settings for repmgrd. This file is source by /bin/sh from
# /etc/init.d/repmgrd # /etc/init.d/repmgrd
# Options for repmgrd # disable repmgrd by default so it won't get started upon installation
REPMGRD_OPTS="" # valid values: yes/no
REPMGRD_ENABLED=no
# Options for repmgrd (required)
#REPMGRD_OPTS="--config_file /path/to/repmgr.conf"
# User to run repmgrd as
#REPMGRD_USER=postgres
# repmgrd binary # repmgrd binary
REPMGR_BIN="/usr/bin/repmgr" #REPMGR_BIN=/usr/bin/repmgr
# pid file # pid file
REPMGR_PIDFILE="/var/run/repmgrd.pid" #REPMGR_PIDFILE=/var/run/repmgrd.pid

View File

@@ -1,47 +1,100 @@
#!/bin/sh #!/bin/sh
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: repmgrd # Provides: repmgrd
# Required-Start: $local_fs $remote_fs $network $syslog $postgresql # Required-Start: $local_fs $remote_fs $network $syslog postgresql
# Required-Stop: $local_fs $remote_fs $network $syslog $postgresql # Required-Stop: $local_fs $remote_fs $network $syslog postgresql
# Should-Start: $syslog $postgresql # Should-Start: $syslog postgresql
# Should-Start: $syslog $postgresql
# Default-Start: 2 3 4 5 # Default-Start: 2 3 4 5
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
# Short-Description: Start/stop repmgrd # Short-Description: Start/stop repmgrd
# Description: Enable repmgrd replication management and monitoring daemon for PostgreSQL
### END INIT INFO ### END INIT INFO
set -e set -e
if test -f /etc/default/repmgrd; then DESC="PostgreSQL replication management and monitoring daemon"
. /etc/default/repmgrd NAME=repmgrd
fi
if [ -z "$REPMGRD_BIN" ]; then REPMGRD_ENABLED=no
REPMGRD_BIN="/usr/bin/repmgrd" REPMGRD_OPTS=
fi REPMGRD_USER=postgres
REPMGRD_BIN=/usr/bin/repmgrd
REPMGRD_PIDFILE=/var/run/repmgrd.pid
if [ -z "$REPMGRD_PIDFILE" ]; then # Read configuration variable file if it is present
REPMGRD_PIDFILE="/var/run/repmgrd.pid" [ -r /etc/default/$NAME ] && . /etc/default/$NAME
fi
test -x $REPMGRD_BIN || exit 0 test -x $REPMGRD_BIN || exit 0
case "$REPMGRD_ENABLED" in
[Yy]*)
break
;;
*)
exit 0
;;
esac
# Define LSB log_* functions.
. /lib/lsb/init-functions
if [ -z "$REPMGRD_OPTS" ]
then
log_warning_msg "Not starting $NAME, REPMGRD_OPTS not set in /etc/default/$NAME"
exit 0
fi
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# other if daemon could not be started or a failure occured
start-stop-daemon --start --quiet --chuid $REPMGRD_USER --make-pidfile --pidfile $REPMGRD_PIDFILE --exec $REPMGRD_BIN -- $REPMGRD_OPTS
}
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# other if daemon could not be stopped or a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $REPMGRD_PIDFILE --exec $REPMGRD_BIN
}
case "$1" in case "$1" in
start) start)
start-stop-daemon --start --quiet --make-pidfile --pidfile $REPMGRD_PIDFILE --exec $REPMGRD_BIN $REPMGRD_OPTS log_daemon_msg "Starting $DESC" "$NAME"
;; do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_progress_msg "already started"
log_end_msg 0 ;;
*) log_end_msg 1 ;;
esac
;;
stop) stop)
start-stop-daemon --stop --oknodo --quiet --pidfile $REPMGRD_PIDFILE log_daemon_msg "Stopping $DESC" "$NAME"
;; do_stop
case "$?" in
0) log_end_msg 0 ;;
1) log_progress_msg "already stopped"
log_end_msg 0 ;;
*) log_end_msg 1 ;;
esac
restart)
$0 stop && $0 start || exit 1
;; ;;
restart|force-reload)
$0 stop
$0 start
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*) *)
echo "Usage: $0 {start|stop|restart}" echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
exit 1 exit 3
;; ;;
esac esac

9
log.c
View File

@@ -144,7 +144,14 @@ bool logger_init(t_configuration_options *opts, const char* ident, const char* l
if (*opts->logfile) if (*opts->logfile)
{ {
freopen(opts->logfile, "a", stderr); FILE *fd;
fd = freopen(opts->logfile, "a", stderr);
if (fd == NULL)
{
fprintf(stderr, "error reopening stderr to '%s': %s",
opts->logfile, strerror(errno));
}
} }
return true; return true;

View File

@@ -1494,6 +1494,7 @@ do_standby_follow(void)
*/ */
strncpy(runtime_options.host, PQhost(master_conn), MAXLEN); strncpy(runtime_options.host, PQhost(master_conn), MAXLEN);
strncpy(runtime_options.masterport, PQport(master_conn), MAXLEN); strncpy(runtime_options.masterport, PQport(master_conn), MAXLEN);
strncpy(runtime_options.username, PQuser(master_conn), MAXLEN);
PQfinish(master_conn); PQfinish(master_conn);
log_info(_("%s Changing standby's master\n"),progname); log_info(_("%s Changing standby's master\n"),progname);

View File

@@ -179,6 +179,7 @@ main(int argc, char **argv)
int optindex; int optindex;
int c, ret; int c, ret;
bool daemonize = false; bool daemonize = false;
FILE *fd;
char standby_version[MAXVERSIONSTR], *ret_ver; char standby_version[MAXVERSIONSTR], *ret_ver;
@@ -248,8 +249,19 @@ main(int argc, char **argv)
terminate(ERR_BAD_CONFIG); terminate(ERR_BAD_CONFIG);
} }
freopen("/dev/null", "r", stdin); fd = freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout); if (fd == NULL)
{
fprintf(stderr, "error reopening stdin to '/dev/null': %s",
strerror(errno));
}
fd = freopen("/dev/null", "w", stdout);
if (fd == NULL)
{
fprintf(stderr, "error reopening stdout to '/dev/null': %s",
strerror(errno));
}
logger_init(&local_options, progname, local_options.loglevel, local_options.logfacility); logger_init(&local_options, progname, local_options.loglevel, local_options.logfacility);
if (verbose) if (verbose)
@@ -257,7 +269,13 @@ main(int argc, char **argv)
if (log_type == REPMGR_SYSLOG) if (log_type == REPMGR_SYSLOG)
{ {
freopen("/dev/null", "w", stderr); fd = freopen("/dev/null", "w", stderr);
if (fd == NULL)
{
fprintf(stderr, "error reopening stderr to '/dev/null': %s",
strerror(errno));
}
} }
snprintf(repmgr_schema, MAXLEN, "%s%s", DEFAULT_REPMGR_SCHEMA_PREFIX, local_options.cluster_name); snprintf(repmgr_schema, MAXLEN, "%s%s", DEFAULT_REPMGR_SCHEMA_PREFIX, local_options.cluster_name);
@@ -365,7 +383,14 @@ main(int argc, char **argv)
if (*local_options.logfile) if (*local_options.logfile)
{ {
freopen(local_options.logfile, "a", stderr); FILE *fd;
fd = freopen(local_options.logfile, "a", stderr);
if (fd == NULL)
{
fprintf(stderr, "error reopening stderr to '%s': %s",
local_options.logfile, strerror(errno));
}
} }
update_registration(); update_registration();
@@ -1341,6 +1366,7 @@ do_daemonize()
{ {
char *ptr, path[MAXLEN]; char *ptr, path[MAXLEN];
pid_t pid = fork(); pid_t pid = fork();
int ret;
switch (pid) switch (pid)
{ {
@@ -1389,7 +1415,12 @@ do_daemonize()
*path = '/'; *path = '/';
} }
chdir(path); ret = chdir(path);
if (ret != 0)
{
log_err("Error changing directory to '%s': %s", path,
strerror(errno));
}
break; break;
@@ -1405,6 +1436,7 @@ check_and_create_pid_file(const char *pid_file)
FILE *fd; FILE *fd;
char buff[MAXLEN]; char buff[MAXLEN];
pid_t pid; pid_t pid;
size_t nread;
if (stat(pid_file, &st) != -1) if (stat(pid_file, &st) != -1)
{ {
@@ -1418,7 +1450,14 @@ check_and_create_pid_file(const char *pid_file)
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
fread(buff, MAXLEN - 1, 1, fd); nread = fread(buff, MAXLEN - 1, 1, fd);
if (nread == 0 && ferror(fd))
{
log_err("Error reading PID file '%s', giving up...\n", pid_file);
exit(ERR_BAD_CONFIG);
}
fclose(fd); fclose(fd);
pid = atoi(buff); pid = atoi(buff);

View File

@@ -1,5 +1,5 @@
#ifndef _VERSION_H_ #ifndef _VERSION_H_
#define _VERSION_H_ #define _VERSION_H_
#define REPMGR_VERSION "2.0RC1" #define REPMGR_VERSION "2.0"
#endif #endif