Redirect logs to std for mac (#196)

Add support for StandardOutPath and StandardErrorPath for darwin
This commit is contained in:
ANDREY KHASANOV
2019-12-11 06:12:41 +03:00
committed by Daniel Theophanes
parent 4df36c9fc1
commit 6b582019e8
2 changed files with 36 additions and 19 deletions
+1 -1
View File
@@ -141,7 +141,7 @@ type Config struct {
// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return. // - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return.
// - ReloadSignal string () [USR1, ...] - Signal to send on reaload. // - ReloadSignal string () [USR1, ...] - Signal to send on reaload.
// - PIDFile string () [/run/prog.pid] - Location of the PID file. // - PIDFile string () [/run/prog.pid] - Location of the PID file.
// - LogOutput bool (false) - Redirect StdErr & StdOut to files. // - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files.
// - Restart string (always) - How shall service be restarted. // - Restart string (always) - How shall service be restarted.
// - SuccessExitStatus string () - The list of exit status that shall be considered as successful, // - SuccessExitStatus string () - The list of exit status that shall be considered as successful,
// in addition to the default ones. // in addition to the default ones.
+35 -18
View File
@@ -160,6 +160,9 @@ func (s *darwinLaunchdService) Install() error {
KeepAlive, RunAtLoad bool KeepAlive, RunAtLoad bool
SessionCreate bool SessionCreate bool
StandardOut bool
StandardError bool
}{ }{
Config: s.Config, Config: s.Config,
Path: path, Path: path,
@@ -184,7 +187,7 @@ func (s *darwinLaunchdService) Uninstall() error {
func (s *darwinLaunchdService) Status() (Status, error) { func (s *darwinLaunchdService) Status() (Status, error) {
exitCode, out, err := runWithOutput("launchctl", "list", s.Name) exitCode, out, err := runWithOutput("launchctl", "list", s.Name)
if exitCode == 0 && err != nil { if exitCode == 0 && err != nil {
if !strings.Contains(err.Error(), "failed with stderr") { if !strings.Contains(err.Error(), "failed with StandardError") {
return StatusUnknown, err return StatusUnknown, err
} }
} }
@@ -261,22 +264,36 @@ var launchdConfig = `<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" <!DOCTYPE plist PUBLIC "-//Apple Computer//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>Label</key><string>{{html .Name}}</string> <key>Label</key>
<key>ProgramArguments</key> <string>{{html .Name}}</string>
<array> <key>ProgramArguments</key>
<string>{{html .Path}}</string> <array>
{{range .Config.Arguments}} <string>{{html .Path}}</string>
<string>{{html .}}</string> {{range .Config.Arguments}}
{{end}} <string>{{html .}}</string>
</array> {{end}}
{{if .UserName}}<key>UserName</key><string>{{html .UserName}}</string>{{end}} </array>
{{if .ChRoot}}<key>RootDirectory</key><string>{{html .ChRoot}}</string>{{end}} {{if .UserName}}<key>UserName</key>
{{if .WorkingDirectory}}<key>WorkingDirectory</key><string>{{html .WorkingDirectory}}</string>{{end}} <string>{{html .UserName}}</string>{{end}}
<key>SessionCreate</key><{{bool .SessionCreate}}/> {{if .ChRoot}}<key>RootDirectory</key>
<key>KeepAlive</key><{{bool .KeepAlive}}/> <string>{{html .ChRoot}}</string>{{end}}
<key>RunAtLoad</key><{{bool .RunAtLoad}}/> {{if .WorkingDirectory}}<key>WorkingDirectory</key>
<key>Disabled</key><false/> <string>{{html .WorkingDirectory}}</string>{{end}}
</dict> <key>SessionCreate</key>
<{{bool .SessionCreate}}/>
<key>KeepAlive</key>
<{{bool .KeepAlive}}/>
<key>RunAtLoad</key>
<{{bool .RunAtLoad}}/>
<key>Disabled</key>
<false/>
<key>StandardOutPath</key>
<string>/usr/local/var/log/{{html .Name}}.out.log</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/{{html .Name}}.err.log</string>
</dict>
</plist> </plist>
` `