Your message dated Wed, 22 Aug 2018 12:25:24 +0200
with message-id
<CAJ2a_DexZtS37tWf4sf-fqM6G_6vVgBbyN+qhTk=awkzysh...@mail.gmail.com>
and subject line logrotate: Logs are never rotated on the first run (when using
datebased criteria)
has caused the Debian Bug report #580069,
regarding logrotate: Logs are never rotated on the first run (when using
datebased criteria)
to be marked as done.
This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.
(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)
--
580069: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=580069
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: logrotate
Version: 3.7.8-6
Severity: normal
Tags: patch
Hi,
while testing my logrotate setup, I found that logrotate would never rotate a
new logfile on the first run (when using date-based criteria like daily or
monthly). Only a day after the first run the files are actually rotated.
This was a bit unexpected to me and made debugging using the -d option hard,
since it would always just say that the logs needed no rotation. Also, when
using daily rotation on a new log file, this causes the first rotation of the
file to contain two days worth of logs.
Investigation shows this issue is caused when logrotate looks at a file that
is not in its index file yet. It then assigns today as the "last rotated"
date, meaning it won't be rotated tomorrow at its earliest.
The attached patch changes this to use yesterday as the "last rotated" date
for new files. This causes behaviour to become as expected: A new file is
immediately rotated with daily, if today is the first day of the week with
weekly and if today is the first day of the month with montly.
Please consider adding this patch.
Gr.
Matthijs
Treat new files as rotated yesterday (instead of today), so they will be
rotated right away if appropriate (e.g. always for daily rotations, or when
today is the first day of the month for monthly rotations).
Patch from: Matthijs Kooijman <[email protected]>
Index: logrotate-3.7.8/logrotate.c
===================================================================
--- logrotate-3.7.8.orig/logrotate.c 2010-05-03 11:09:21.000000000 +0200
+++ logrotate-3.7.8/logrotate.c 2010-05-03 11:19:34.696646754 +0200
@@ -56,7 +56,7 @@
int numLogs = 0;
int debug = 0;
char *mailCommand = DEFAULT_MAIL_COMMAND;
-time_t nowSecs = 0;
+time_t nowSecs = 0, yesterdaySecs = 0;
static int shred_file(char *filename, struct logInfo *log);
@@ -124,7 +124,7 @@
static struct logState *newState(const char *fn)
{
- struct tm now = *localtime(&nowSecs);
+ struct tm now = *localtime(&yesterdaySecs);
struct logState *new;
time_t lr_time;
@@ -1644,6 +1644,7 @@
{"verbose", 'v', 0, 0, 'v', "Display messages during rotation"},
POPT_AUTOHELP {0, 0, 0, 0, 0}
};
+ struct tm nowTm;
logSetLevel(MESS_NORMAL);
setlocale (LC_ALL, "");
@@ -1696,6 +1697,11 @@
poptFreeContext(optCon);
nowSecs = time(NULL);
+ /* Use mktime to calculate yesterday's date (since we can't rely on time_t
+ * being seconds since 1970, according to libc specs) */
+ nowTm = *gmtime(&nowSecs);
+ nowTm.tm_mday -= 1;
+ yesterdaySecs = mktime(&nowTm);
if (allocateHash() != 0)
return 1;
--- End Message ---
--- Begin Message ---
Upstream thinks it is the desired behavior:
https://github.com/logrotate/logrotate/issues/215#issuecomment-414984405
--- End Message ---