Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jared Allard 2018-11-24 15:57:56 -08:00
commit 3048307cee
No known key found for this signature in database
GPG Key ID: 0CA9135F5BB08943
1 changed files with 18 additions and 3 deletions

View File

@ -113,7 +113,8 @@ func (b *LogrotateBuilder) addLogrotateService(c *fi.ModelBuilderContext) error
} }
type logRotateOptions struct { type logRotateOptions struct {
MaxSize string MaxSize string
DateFormat string
} }
func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path string, options logRotateOptions) { 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" 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{ lines := []string{
path + "{", path + "{",
" rotate 5", " rotate 5",
@ -129,12 +136,20 @@ func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path st
" notifempty", " notifempty",
" delaycompress", " delaycompress",
" maxsize " + options.MaxSize, " maxsize " + options.MaxSize,
}
if options.DateFormat != "" {
lines = append(lines, " dateformat "+options.DateFormat)
}
lines = append(
lines,
" daily", " daily",
" create 0644 root root", " create 0644 root root",
"}", "}",
} )
contents := strings.Join(lines, "\n") contents := strings.Join(lines, "\n") + "\n"
c.AddTask(&nodetasks.File{ c.AddTask(&nodetasks.File{
Path: "/etc/logrotate.d/" + name, Path: "/etc/logrotate.d/" + name,