Update launchd template (#346)

* Update XML prolog and DTD

Also converts single-quotes to double-quotes

* Remove whitespace from parent dict

* Only populate EnvironmentVariables when available

* Only add additional arguments when defined

Also cleans up whitespace around each argument

* Cleanup whitespace and only populate when defined

* Convert remaining spaces to tabs

* Sort keys. Similar to `plutil -convert xml1`
This commit is contained in:
Nate Felton
2022-10-10 18:02:22 -04:00
committed by GitHub
parent 645b10f1a8
commit f4a4df2b5e
+50 -38
View File
@@ -290,46 +290,58 @@ func (s *darwinLaunchdService) SystemLogger(errs chan<- error) (Logger, error) {
return newSysLogger(s.Name, errs) return newSysLogger(s.Name, errs)
} }
var launchdConfig = `<?xml version='1.0' encoding='UTF-8'?> var launchdConfig = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" > <plist version="1.0">
<plist version='1.0'> <dict>
<dict> <key>Disabled</key>
<false/>
{{- if .EnvVars}}
<key>EnvironmentVariables</key> <key>EnvironmentVariables</key>
<dict> <dict>
{{range $k, $v := .EnvVars -}} {{- range $k, $v := .EnvVars}}
<key>{{html $k}}</key> <key>{{html $k}}</key>
<string>{{html $v}}</string> <string>{{html $v}}</string>
{{end -}} {{- end}}
</dict> </dict>
<key>Label</key> {{- end}}
<string>{{html .Name}}</string> <key>KeepAlive</key>
<key>ProgramArguments</key> <{{bool .KeepAlive}}/>
<array> <key>Label</key>
<string>{{html .Path}}</string> <string>{{html .Name}}</string>
{{range .Config.Arguments}} <key>ProgramArguments</key>
<string>{{html .}}</string> <array>
{{end}} <string>{{html .Path}}</string>
</array> {{- if .Config.Arguments}}
{{if .UserName}}<key>UserName</key> {{- range .Config.Arguments}}
<string>{{html .UserName}}</string>{{end}} <string>{{html .}}</string>
{{if .ChRoot}}<key>RootDirectory</key> {{- end}}
<string>{{html .ChRoot}}</string>{{end}} {{- end}}
{{if .WorkingDirectory}}<key>WorkingDirectory</key> </array>
<string>{{html .WorkingDirectory}}</string>{{end}} {{- if .ChRoot}}
<key>SessionCreate</key> <key>RootDirectory</key>
<{{bool .SessionCreate}}/> <string>{{html .ChRoot}}</string>
<key>KeepAlive</key> {{- end}}
<{{bool .KeepAlive}}/> <key>RunAtLoad</key>
<key>RunAtLoad</key> <{{bool .RunAtLoad}}/>
<{{bool .RunAtLoad}}/> <key>SessionCreate</key>
<key>Disabled</key> <{{bool .SessionCreate}}/>
<false/> {{- if .StandardErrorPath}}
<key>StandardErrorPath</key>
{{if .StandardOutPath}}<key>StandardOutPath</key> <string>{{html .StandardErrorPath}}</string>
<string>{{html .StandardOutPath}}</string>{{end}} {{- end}}
{{if .StandardErrorPath}}<key>StandardErrorPath</key> {{- if .StandardOutPath}}
<string>{{html .StandardErrorPath}}</string>{{end}} <key>StandardOutPath</key>
</dict> <string>{{html .StandardOutPath}}</string>
{{- end}}
{{- if .UserName}}
<key>UserName</key>
<string>{{html .UserName}}</string>
{{- end}}
{{- if .WorkingDirectory}}
<key>WorkingDirectory</key>
<string>{{html .WorkingDirectory}}</string>
{{- end}}
</dict>
</plist> </plist>
` `