service: enable more config params on systemd.

This commit is contained in:
Daniel Theophanes
2015-01-24 15:29:42 -08:00
parent 60819611ca
commit 18c6e7250d
2 changed files with 18 additions and 5 deletions
+3
View File
@@ -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
View File
@@ -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