From 33dedf4e9615d86b91361496237125e57c648ae3 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 2 Aug 2018 10:51:18 +0900 Subject: [PATCH] repmgrd: always reopen log file after receiving SIGHUP For whatever reason, since at least repmgr 2.0 the log file was only ever reopened if a configuration file change took place. GitHub #485. --- HISTORY | 5 +++++ doc/appendix-release-notes.sgml | 28 +++++++++++++++++++++++++ doc/repmgrd-configuration.sgml | 36 +++++++++------------------------ repmgrd-physical.c | 21 ++++++++++--------- 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/HISTORY b/HISTORY index 8809e5b8..163040d4 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,8 @@ + +4.1.1 2018-??-?? + repmgrd: ensure that sending SIGHUP always results in the log file + being reopened; GitHub #485 (Ian) + 4.1.0 2018-07-31 repmgr: change default log_level to INFO, add documentation; GitHub #470 (Ian) repmgr: add "--missing-slots" check to "repmgr node check" (Ian) diff --git a/doc/appendix-release-notes.sgml b/doc/appendix-release-notes.sgml index ab3e3c5f..b78051e7 100644 --- a/doc/appendix-release-notes.sgml +++ b/doc/appendix-release-notes.sgml @@ -15,6 +15,34 @@ See also: + + Release 4.1.1 + ??? ??? ??, 2018 + + + + + repmgrd enhancements + + + + + + repmgrd: always reopen the log file after + receiving SIGHUP. Previously this only happened if + a configuration file change was detected. + (GitHub #485). + + + + + + + + + + + Release 4.1.0 Tue July 31, 2018 diff --git a/doc/repmgrd-configuration.sgml b/doc/repmgrd-configuration.sgml index a6078ffc..ce43bd07 100644 --- a/doc/repmgrd-configuration.sgml +++ b/doc/repmgrd-configuration.sgml @@ -323,11 +323,16 @@ REPMGRD_ENABLED=no repmgrd + + repmgrd + log rotation + + repmgrd log rotation To ensure the current repmgrd logfile (specified in repmgr.conf with the parameter - does not grow indefinitely, configure your + ) does not grow indefinitely, configure your system's logrotate to regularly rotate it. @@ -340,33 +345,12 @@ REPMGRD_ENABLED=no rotate 52 maxsize 100M weekly - copytruncate + create 0600 postgres postgres + postrotate + /usr/bin/killall -HUP repmgrd + endscript } - - - Currently repmgrd will not reopen the log - file unless the configuration is reloaded via SIGHUP - and the configuration changes. - - - Therefore it's recommended to use copytruncate when - rotating logs, so that the contents of the existing file are rotated out - by creating a copy, then truncating the original file, which - repmgrd still holds open. - - - Note that any logging data written in the (short) timespan after the existing file - is copied, but before it is truncated, will be lost; see the - logrotate documentation. - - - This restriction may be lifted in a future &repmgr; version by providing a - signal which causes repmgrd to reopen the log file, - and which can be sent from logrotate via a postrotate - script. - - diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 735ec1b7..e9d04741 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -2936,18 +2936,21 @@ handle_sighup(PGconn *conn) { close_connection(&conn); conn = establish_db_connection(config_file_options.conninfo, true); + } - if (*config_file_options.log_file) + if (*config_file_options.log_file) + { + FILE *fd; + + log_debug("reopening %s", config_file_options.log_file); + + fd = freopen(config_file_options.log_file, "a", stderr); + if (fd == NULL) { - FILE *fd; - - fd = freopen(config_file_options.log_file, "a", stderr); - if (fd == NULL) - { - fprintf(stderr, "error reopening stderr to \"%s\": %s", - config_file_options.log_file, strerror(errno)); - } + fprintf(stderr, "error reopening stderr to \"%s\": %s", + config_file_options.log_file, strerror(errno)); } } + got_SIGHUP = false; }