Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

[6.1] set 100000 fds on systemd unit creation if unspecified (#2315) #2322

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/systemservice/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ExecStartPre={{.}}{{end}}
{{if .StartPostCommand}}ExecStartPost={{.StartPostCommand}}{{end}}
{{if .StopCommand}}ExecStop={{.StopCommand}}{{end}}
{{if .StopPostCommand}}ExecStopPost={{.StopPostCommand}}{{end}}
{{if .LimitNoFile}}LimitNOFILE={{.LimitNoFile}}{{end}}
{{if .LimitNoFile}}LimitNOFILE={{.LimitNoFile}}{{else}}LimitNOFILE=100000{{end}}
{{if .KillMode}}KillMode={{.KillMode}}{{end}}
{{if .KillSignal}}KillSignal={{.KillSignal}}{{end}}
{{if .Restart}}Restart={{.Restart}}{{end}}
Expand Down
165 changes: 127 additions & 38 deletions lib/systemservice/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,49 @@ func (s *SystemdSuite) TestUnitParsing(c *C) {
}

func (s *SystemdSuite) TestServiceTemplate(c *C) {
buf := &bytes.Buffer{}
err := serviceUnitTemplate.Execute(buf, serviceTemplate{
Name: "test.service",
Description: "test",
ServiceSpec: ServiceSpec{
Type: "oneshot",
StartCommand: "start",
StopCommand: "stop",
StopPostCommand: "stop post",
StartPreCommands: []string{"pre-command", "another pre-command"},
StartPostCommand: "start post",
WantedBy: "test.target",
KillMode: "cgroup",
KillSignal: "SIGQUIT",
RestartSec: 3,
Timeout: 4,
Restart: "always",
User: "root",
LimitNoFile: 1000,
RemainAfterExit: true,
Dependencies: Dependencies{
Requires: "foo.service",
After: "foo.service",
Before: "bar.service",
},
Environment: map[string]string{
"PATH": "/usr/bin",
tt := []struct {
in serviceTemplate
out string
description string
}{
{
description: "Full service",
in: serviceTemplate{
Name: "test.service",
Description: "test",
ServiceSpec: ServiceSpec{
Type: "oneshot",
StartCommand: "start",
StopCommand: "stop",
StopPostCommand: "stop post",
StartPreCommands: []string{"pre-command", "another pre-command"},
StartPostCommand: "start post",
WantedBy: "test.target",
KillMode: "cgroup",
KillSignal: "SIGQUIT",
RestartSec: 3,
Timeout: 4,
Restart: "always",
User: "root",
LimitNoFile: 1000,
RemainAfterExit: true,
Dependencies: Dependencies{
Requires: "foo.service",
After: "foo.service",
Before: "bar.service",
},
Environment: map[string]string{
"PATH": "/usr/bin",
},
TasksMax: "infinity",
TimeoutStopSec: "5min",
ConditionPathExists: "/path/to/foo",
RestartPreventExitStatus: "1 2 3",
SuccessExitStatus: "254",
WorkingDirectory: "/foo/bar",
},
},
TasksMax: "infinity",
TimeoutStopSec: "5min",
ConditionPathExists: "/path/to/foo",
RestartPreventExitStatus: "1 2 3",
SuccessExitStatus: "254",
WorkingDirectory: "/foo/bar",
},
})
c.Assert(err, IsNil)
c.Assert(buf.String(), compare.DeepEquals, `[Unit]
out: `[Unit]
Description=test

Requires=foo.service
Expand Down Expand Up @@ -120,7 +125,91 @@ TasksMax=infinity
[Install]
WantedBy=test.target

`)
`,
},
{
description: "unspecified file limits",
in: serviceTemplate{
Name: "test.service",
Description: "test",
ServiceSpec: ServiceSpec{
Type: "oneshot",
StartCommand: "start",
StopCommand: "stop",
StopPostCommand: "stop post",
StartPreCommands: []string{"pre-command", "another pre-command"},
StartPostCommand: "start post",
WantedBy: "test.target",
KillMode: "cgroup",
KillSignal: "SIGQUIT",
RestartSec: 3,
Timeout: 4,
Restart: "always",
User: "root",
RemainAfterExit: true,
Dependencies: Dependencies{
Requires: "foo.service",
After: "foo.service",
Before: "bar.service",
},
Environment: map[string]string{
"PATH": "/usr/bin",
},
TasksMax: "infinity",
TimeoutStopSec: "5min",
ConditionPathExists: "/path/to/foo",
RestartPreventExitStatus: "1 2 3",
SuccessExitStatus: "254",
WorkingDirectory: "/foo/bar",
},
},
out: `[Unit]
Description=test

Requires=foo.service
After=foo.service
Before=bar.service

ConditionPathExists=/path/to/foo

[Service]
TimeoutStartSec=4
Type=oneshot
User=root
ExecStart=start
ExecStartPre=pre-command
ExecStartPre=another pre-command
ExecStartPost=start post
ExecStop=stop
ExecStopPost=stop post
LimitNOFILE=100000
KillMode=cgroup
KillSignal=SIGQUIT
Restart=always
TimeoutStopSec=5min
RestartSec=3
RemainAfterExit=yes
RestartPreventExitStatus=1 2 3
SuccessExitStatus=254
WorkingDirectory=/foo/bar
Environment=PATH=/usr/bin

TasksMax=infinity


[Install]
WantedBy=test.target

`,
},
}

for _, test := range tt {
buf := &bytes.Buffer{}
err := serviceUnitTemplate.Execute(buf, test.in)
c.Assert(err, IsNil, Commentf(test.description))
c.Assert(buf.String(), compare.DeepEquals, test.out, Commentf(test.description))
}
}

func (s *SystemdSuite) TestMountServiceTemplate(c *C) {
Expand Down