Skip to content

Commit

Permalink
Update launchd template (#346)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
n8felton authored Oct 10, 2022
1 parent 645b10f commit f4a4df2
Showing 1 changed file with 50 additions and 38 deletions.
88 changes: 50 additions & 38 deletions service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,46 +290,58 @@ func (s *darwinLaunchdService) SystemLogger(errs chan<- error) (Logger, error) {
return newSysLogger(s.Name, errs)
}

var launchdConfig = `<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
var launchdConfig = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
{{- if .EnvVars}}
<key>EnvironmentVariables</key>
<dict>
{{range $k, $v := .EnvVars -}}
<key>{{html $k}}</key>
<string>{{html $v}}</string>
{{end -}}
{{- range $k, $v := .EnvVars}}
<key>{{html $k}}</key>
<string>{{html $v}}</string>
{{- end}}
</dict>
<key>Label</key>
<string>{{html .Name}}</string>
<key>ProgramArguments</key>
<array>
<string>{{html .Path}}</string>
{{range .Config.Arguments}}
<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>SessionCreate</key>
<{{bool .SessionCreate}}/>
<key>KeepAlive</key>
<{{bool .KeepAlive}}/>
<key>RunAtLoad</key>
<{{bool .RunAtLoad}}/>
<key>Disabled</key>
<false/>
{{if .StandardOutPath}}<key>StandardOutPath</key>
<string>{{html .StandardOutPath}}</string>{{end}}
{{if .StandardErrorPath}}<key>StandardErrorPath</key>
<string>{{html .StandardErrorPath}}</string>{{end}}
</dict>
{{- end}}
<key>KeepAlive</key>
<{{bool .KeepAlive}}/>
<key>Label</key>
<string>{{html .Name}}</string>
<key>ProgramArguments</key>
<array>
<string>{{html .Path}}</string>
{{- if .Config.Arguments}}
{{- range .Config.Arguments}}
<string>{{html .}}</string>
{{- end}}
{{- end}}
</array>
{{- if .ChRoot}}
<key>RootDirectory</key>
<string>{{html .ChRoot}}</string>
{{- end}}
<key>RunAtLoad</key>
<{{bool .RunAtLoad}}/>
<key>SessionCreate</key>
<{{bool .SessionCreate}}/>
{{- if .StandardErrorPath}}
<key>StandardErrorPath</key>
<string>{{html .StandardErrorPath}}</string>
{{- end}}
{{- if .StandardOutPath}}
<key>StandardOutPath</key>
<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>
`

0 comments on commit f4a4df2

Please sign in to comment.