Skip to content

Commit

Permalink
Merge pull request #3590 from justinsb/logrotate_service
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

Create logrotate service where not installed by default
  • Loading branch information
Kubernetes Submit Queue authored Oct 10, 2017
2 parents 4798a67 + f6a995b commit 7b65c54
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions nodeup/pkg/model/logrotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,47 @@ func (b *LogrotateBuilder) Build(c *fi.ModelBuilderContext) error {
b.addLogRotate(c, "kube-scheduler", "/var/log/kube-scheduler.log", logRotateOptions{})
b.addLogRotate(c, "kubelet", "/var/log/kubelet.log", logRotateOptions{})

if err := b.addLogrotateService(c); err != nil {
return err
}

// Add timer to run hourly.
unit := &systemd.Manifest{}
unit.Set("Unit", "Description", "Hourly Log Rotation")
unit.Set("Timer", "OnCalendar", "hourly")
{
unit := &systemd.Manifest{}
unit.Set("Unit", "Description", "Hourly Log Rotation")
unit.Set("Timer", "OnCalendar", "hourly")

service := &nodetasks.Service{
Name: "logrotate.timer", // Override (by name) any existing timer
Definition: s(unit.Render()),
service := &nodetasks.Service{
Name: "logrotate.timer", // Override (by name) any existing timer
Definition: s(unit.Render()),
}

service.InitDefaults()

c.AddTask(service)
}

service.InitDefaults()
return nil
}

// addLogrotateService creates a logrotate systemd task to act as target for the timer, if one is needed
func (b *LogrotateBuilder) addLogrotateService(c *fi.ModelBuilderContext) error {
switch b.Distribution {
case distros.DistributionCoreOS:
case distros.DistributionContainerOS:
// logrotate service already exists
return nil
}

manifest := &systemd.Manifest{}
manifest.Set("Unit", "Description", "Rotate and Compress System Logs")
manifest.Set("Service", "ExecStart", "/usr/sbin/logrotate /etc/logrotate.conf")

service := &nodetasks.Service{
Name: "logrotate.service",
Definition: s(manifest.Render()),
}
service.InitDefaults()
c.AddTask(service)

return nil
Expand Down

0 comments on commit 7b65c54

Please sign in to comment.