Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create logrotate service where not installed by default #3590

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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