service
service copied to clipboard
feat: support custom RestartSec option on POSIX
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