Skip to content

Commit

Permalink
wrappers: fix LogNamespace being written to the wrong file
Browse files Browse the repository at this point in the history
  • Loading branch information
Meulengracht committed Jun 15, 2022
1 parent 14bc640 commit efa99b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions wrappers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ TasksAccounting=true
return buf.String()
}

func formatLogNamespaceSlice(grp *quota.Group) string {
if grp.JournalLimit == nil {
return ""
}
return fmt.Sprintf("LogNamespace=snap-%s\n", grp.Name)
}

// generateGroupSliceFile generates a systemd slice unit definition for the
// specified quota group.
func generateGroupSliceFile(grp *quota.Group) []byte {
Expand All @@ -153,7 +146,6 @@ func generateGroupSliceFile(grp *quota.Group) []byte {
cpuOptions := formatCpuGroupSlice(grp)
memoryOptions := formatMemoryGroupSlice(grp)
taskOptions := formatTaskGroupSlice(grp)
logOptions := formatLogNamespaceSlice(grp)
template := `[Unit]
Description=Slice for snap quota group %[1]s
Before=slices.target
Expand All @@ -163,7 +155,7 @@ X-Snappy=yes
`

fmt.Fprintf(&buf, template, grp.Name)
fmt.Fprint(&buf, cpuOptions, memoryOptions, taskOptions, logOptions)
fmt.Fprint(&buf, cpuOptions, memoryOptions, taskOptions)
return buf.Bytes()
}

Expand Down Expand Up @@ -1207,6 +1199,9 @@ OOMScoreAdjust={{.OOMAdjustScore}}
{{- if .SliceUnit}}
Slice={{.SliceUnit}}
{{- end}}
{{- if .LogNamespace}}
LogNamespace={{.LogNamespace}}
{{- end}}
{{- if not (or .App.Sockets .App.Timer .App.ActivatesOn) }}
[Install]
Expand Down Expand Up @@ -1279,6 +1274,7 @@ WantedBy={{.ServicesTarget}}
After []string
InterfaceServiceSnippets string
SliceUnit string
LogNamespace string

Home string
EnvVars string
Expand Down Expand Up @@ -1323,6 +1319,9 @@ WantedBy={{.ServicesTarget}}
// check the quota group slice
if opts.QuotaGroup != nil {
wrapperData.SliceUnit = opts.QuotaGroup.SliceFileName()
if opts.QuotaGroup.JournalLimit != nil {
wrapperData.LogNamespace = "snap-" + opts.QuotaGroup.Name
}
}

// Add extra "After" targets
Expand Down
4 changes: 2 additions & 2 deletions wrappers/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ ExecStopPost=/usr/bin/snap run --command=post-stop hello-snap.svc1
TimeoutStopSec=30
Type=forking
Slice=snap.foogroup.slice
LogNamespace=snap-foogroup
[Install]
WantedBy=multi-user.target
Expand All @@ -575,7 +576,6 @@ MemoryAccounting=true
# Always enable task accounting in order to be able to count the processes/
# threads, etc for a slice
TasksAccounting=true
LogNamespace=snap-foogroup
`

jconfContent := fmt.Sprintf(jconfTempl, grp.Name)
Expand Down Expand Up @@ -653,6 +653,7 @@ ExecStopPost=/usr/bin/snap run --command=post-stop hello-snap.svc1
TimeoutStopSec=30
Type=forking
Slice=snap.foogroup.slice
LogNamespace=snap-foogroup
[Install]
WantedBy=multi-user.target
Expand Down Expand Up @@ -682,7 +683,6 @@ MemoryAccounting=true
# Always enable task accounting in order to be able to count the processes/
# threads, etc for a slice
TasksAccounting=true
LogNamespace=snap-foogroup
`

jconfContent := fmt.Sprintf(jconfTempl, grp.Name)
Expand Down

0 comments on commit efa99b1

Please sign in to comment.