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> <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
View File
@@ -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