From 17ad5af417cf84ffd35b477f43cdb8400665887a Mon Sep 17 00:00:00 2001 From: Ripta Pasay Date: Thu, 8 Nov 2018 09:04:10 +0000 Subject: [PATCH] Set dateformat on logrotate configs On CoreOS Container Linux, `dateext` is set, which causes log rotation based on maxsize to not run, when a previous rotation already happened on the calendar same day. (cherry picked from commit 585d0a0da42be1eae87fa879b0084d29d77ac605) --- nodeup/pkg/model/logrotate.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/nodeup/pkg/model/logrotate.go b/nodeup/pkg/model/logrotate.go index e78e50df29..53eed5fd62 100644 --- a/nodeup/pkg/model/logrotate.go +++ b/nodeup/pkg/model/logrotate.go @@ -113,7 +113,8 @@ func (b *LogrotateBuilder) addLogrotateService(c *fi.ModelBuilderContext) error } type logRotateOptions struct { - MaxSize string + MaxSize string + DateFormat string } func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path string, options logRotateOptions) { @@ -121,6 +122,12 @@ func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path st options.MaxSize = "100M" } + // CoreOS sets "dateext" options, and maxsize-based rotation will fail if + // the file has been previously rotated on the same calendar date. + if b.Distribution == distros.DistributionCoreOS { + options.DateFormat = "-%Y%m%d-%s" + } + lines := []string{ path + "{", " rotate 5", @@ -129,12 +136,20 @@ func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path st " notifempty", " delaycompress", " maxsize " + options.MaxSize, + } + + if options.DateFormat != "" { + lines = append(lines, " dateformat "+options.DateFormat) + } + + lines = append( + lines, " daily", " create 0644 root root", "}", - } + ) - contents := strings.Join(lines, "\n") + contents := strings.Join(lines, "\n") + "\n" c.AddTask(&nodetasks.File{ Path: "/etc/logrotate.d/" + name,