service: enable more config params on systemd.
This commit is contained in:
@@ -199,6 +199,9 @@ var launchdConfig = `<?xml version='1.0' encoding='UTF-8'?>
|
||||
<string>{{html .}}</string>
|
||||
{{end}}
|
||||
</array>
|
||||
{{if .UserName}}<key>UserName</key><string>{{html .UserName}}</string>{{end}}
|
||||
{{if .ChRoot}}<key>RootDirectory</key><string>{{html .ChRoot}}</string>{{end}}
|
||||
{{if .WorkingDirectory}}<key>WorkingDirectory</key><string>{{html .WorkingDirectory}}</string>{{end}}
|
||||
<key>KeepAlive</key><{{bool .KeepAlive}}/>
|
||||
<key>RunAtLoad</key><{{bool .RunAtLoad}}/>
|
||||
<key>Disabled</key><false/>
|
||||
|
||||
+15
-5
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
@@ -137,7 +138,7 @@ func (f initFlavor) ConfigPath(name string, c *Config) (cp string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (f initFlavor) GetTemplate() *template.Template {
|
||||
func (f initFlavor) Template() *template.Template {
|
||||
var templ string
|
||||
switch f {
|
||||
case initSystemd:
|
||||
@@ -147,7 +148,7 @@ func (f initFlavor) GetTemplate() *template.Template {
|
||||
case initUpstart:
|
||||
templ = upstartScript
|
||||
}
|
||||
return template.Must(template.New(f.String() + "Script").Parse(templ))
|
||||
return template.Must(template.New(f.String() + "Script").Funcs(tf).Parse(templ))
|
||||
}
|
||||
|
||||
var interactive = false
|
||||
@@ -196,7 +197,7 @@ func (s *linuxService) Install() error {
|
||||
path,
|
||||
}
|
||||
|
||||
err = flavor.GetTemplate().Execute(f, to)
|
||||
err = flavor.Template().Execute(f, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -298,6 +299,12 @@ func (s *linuxService) Restart() error {
|
||||
return s.Start()
|
||||
}
|
||||
|
||||
var tf = map[string]interface{}{
|
||||
"cmd": func(s string) string {
|
||||
return `"` + strings.Replace(s, `"`, `\"`, -1) + `"`
|
||||
},
|
||||
}
|
||||
|
||||
const systemVScript = `#!/bin/sh
|
||||
# For RedHat and cousins:
|
||||
# chkconfig: - 99 01
|
||||
@@ -420,12 +427,15 @@ exec {{.Path}}
|
||||
|
||||
const systemdScript = `[Unit]
|
||||
Description={{.Description}}
|
||||
ConditionFileIsExecutable={{.Path}}
|
||||
ConditionFileIsExecutable={{.Path|cmd}}
|
||||
|
||||
[Service]
|
||||
StartLimitInterval=5
|
||||
StartLimitBurst=10
|
||||
ExecStart={{.Path}}
|
||||
ExecStart={{.Path|cmd}}{{range .Arguments}} {{.|cmd}}{{end}}
|
||||
{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}}
|
||||
{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmd}}{{end}}
|
||||
{{if .UserName}}User={{.UserName}}{{end}}
|
||||
Restart=always
|
||||
RestartSec=120
|
||||
|
||||
|
||||
Reference in New Issue
Block a user