Skip to content

feat: support custom RestartSec option on POSIX#324

Open
jiyeyuran wants to merge 1 commit intokardianos:masterfrom
jiyeyuran:master
Open

feat: support custom RestartSec option on POSIX#324
jiyeyuran wants to merge 1 commit intokardianos:masterfrom
jiyeyuran:master

Conversation

@jiyeyuran
Copy link
Copy Markdown

No description provided.

@ympek
Copy link
Copy Markdown

ympek commented Mar 7, 2023

Not a maintainer; I just arrived here from search engine, because I wanted to change this setting (and couple more) too.
Sadly the PR is not merged, but there is nice workaround - you can provide your own systemd script template.
Just copy default one: (https://github.com/kardianos/service/blob/master/service_systemd_linux.go#L301)

const mySystemdScript = `[Unit]
Description={{.Description}}
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}} 
{{$dep}} {{end}}

[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}}
{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}}
{{if .UserName}}User={{.UserName}}{{end}}
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
{{if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:{{.LogDirectory}}/{{.Name}}.out
StandardError=file:{{.LogDirectory}}/{{.Name}}.err
{{- end}}
{{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}}
{{if .Restart}}Restart={{.Restart}}{{end}}
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
RestartSec=120
EnvironmentFile=-/etc/sysconfig/{{.Name}}

{{range $k, $v := .EnvVars -}}
Environment={{$k}}={{$v}}
{{end -}}

[Install]
WantedBy=multi-user.target
`

and adjust to your needs.

Then you can replace the default with your custom template like this:

serviceConfig.Option = service.KeyValue{
	"SystemdScript": mySystemdScript,
}

Hope it helps someone
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants