mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
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.
This commit is contained in:
5
HISTORY
5
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)
|
||||
|
||||
@@ -15,6 +15,34 @@
|
||||
See also: <xref linkend="upgrading-repmgr">
|
||||
</para>
|
||||
|
||||
<sect1 id="release-4.1.1">
|
||||
<title>Release 4.1.1</title>
|
||||
<para><emphasis>??? ??? ??, 2018</emphasis></para>
|
||||
<para>
|
||||
</para>
|
||||
|
||||
<sect2>
|
||||
<title>repmgrd enhancements</title>
|
||||
<para>
|
||||
<itemizedlist>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
<application>repmgrd</application>: always reopen the log file after
|
||||
receiving <literal>SIGHUP</literal>. Previously this only happened if
|
||||
a configuration file change was detected.
|
||||
(GitHub #485).
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
|
||||
<sect1 id="release-4.1.0">
|
||||
<title>Release 4.1.0</title>
|
||||
<para><emphasis>Tue July 31, 2018</emphasis></para>
|
||||
|
||||
@@ -323,11 +323,16 @@ REPMGRD_ENABLED=no
|
||||
<secondary>repmgrd</secondary>
|
||||
</indexterm>
|
||||
|
||||
<indexterm>
|
||||
<primary>repmgrd</primary>
|
||||
<secondary>log rotation</secondary>
|
||||
</indexterm>
|
||||
|
||||
<title>repmgrd log rotation</title>
|
||||
<para>
|
||||
To ensure the current <application>repmgrd</application> logfile
|
||||
(specified in <filename>repmgr.conf</filename> with the parameter
|
||||
<option>log_file</option> does not grow indefinitely, configure your
|
||||
<option>log_file</option>) does not grow indefinitely, configure your
|
||||
system's <command>logrotate</command> to regularly rotate it.
|
||||
</para>
|
||||
<para>
|
||||
@@ -340,33 +345,12 @@ REPMGRD_ENABLED=no
|
||||
rotate 52
|
||||
maxsize 100M
|
||||
weekly
|
||||
copytruncate
|
||||
create 0600 postgres postgres
|
||||
postrotate
|
||||
/usr/bin/killall -HUP repmgrd
|
||||
endscript
|
||||
}</programlisting>
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
Currently <application>repmgrd</application> will not reopen the log
|
||||
file unless the configuration is reloaded via <literal>SIGHUP</literal>
|
||||
<emphasis>and</emphasis> the configuration changes.
|
||||
</para>
|
||||
<para>
|
||||
Therefore it's recommended to use <literal>copytruncate</literal> when
|
||||
rotating logs, so that the contents of the existing file are rotated out
|
||||
by creating a copy, then truncating the original file, which
|
||||
<application>repmgrd</application> still holds open.
|
||||
</para>
|
||||
<para>
|
||||
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
|
||||
<ulink url="https://linux.die.net/man/8/logrotate">logrotate documentation</ulink>.
|
||||
</para>
|
||||
<para>
|
||||
This restriction may be lifted in a future &repmgr; version by providing a
|
||||
signal which causes <application>repmgrd</application> to reopen the log file,
|
||||
and which can be sent from <command>logrotate</command> via a <command>postrotate</command>
|
||||
script.
|
||||
</para>
|
||||
</note>
|
||||
</sect1>
|
||||
</chapter>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user