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>
|
<string>{{html .}}</string>
|
||||||
{{end}}
|
{{end}}
|
||||||
</array>
|
</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>KeepAlive</key><{{bool .KeepAlive}}/>
|
||||||
<key>RunAtLoad</key><{{bool .RunAtLoad}}/>
|
<key>RunAtLoad</key><{{bool .RunAtLoad}}/>
|
||||||
<key>Disabled</key><false/>
|
<key>Disabled</key><false/>
|
||||||
|
|||||||
+15
-5
@@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -137,7 +138,7 @@ func (f initFlavor) ConfigPath(name string, c *Config) (cp string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f initFlavor) GetTemplate() *template.Template {
|
func (f initFlavor) Template() *template.Template {
|
||||||
var templ string
|
var templ string
|
||||||
switch f {
|
switch f {
|
||||||
case initSystemd:
|
case initSystemd:
|
||||||
@@ -147,7 +148,7 @@ func (f initFlavor) GetTemplate() *template.Template {
|
|||||||
case initUpstart:
|
case initUpstart:
|
||||||
templ = upstartScript
|
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
|
var interactive = false
|
||||||
@@ -196,7 +197,7 @@ func (s *linuxService) Install() error {
|
|||||||
path,
|
path,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = flavor.GetTemplate().Execute(f, to)
|
err = flavor.Template().Execute(f, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -298,6 +299,12 @@ func (s *linuxService) Restart() error {
|
|||||||
return s.Start()
|
return s.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tf = map[string]interface{}{
|
||||||
|
"cmd": func(s string) string {
|
||||||
|
return `"` + strings.Replace(s, `"`, `\"`, -1) + `"`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const systemVScript = `#!/bin/sh
|
const systemVScript = `#!/bin/sh
|
||||||
# For RedHat and cousins:
|
# For RedHat and cousins:
|
||||||
# chkconfig: - 99 01
|
# chkconfig: - 99 01
|
||||||
@@ -420,12 +427,15 @@ exec {{.Path}}
|
|||||||
|
|
||||||
const systemdScript = `[Unit]
|
const systemdScript = `[Unit]
|
||||||
Description={{.Description}}
|
Description={{.Description}}
|
||||||
ConditionFileIsExecutable={{.Path}}
|
ConditionFileIsExecutable={{.Path|cmd}}
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
StartLimitInterval=5
|
StartLimitInterval=5
|
||||||
StartLimitBurst=10
|
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
|
Restart=always
|
||||||
RestartSec=120
|
RestartSec=120
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user