Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect logs to std for mac #196

Merged
merged 6 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type Config struct {
// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return.
// - ReloadSignal string () [USR1, ...] - Signal to send on reaload.
// - 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.
// - SuccessExitStatus string () - The list of exit status that shall be considered as successful,
// in addition to the default ones.
Expand Down
53 changes: 35 additions & 18 deletions service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func (s *darwinLaunchdService) Install() error {

KeepAlive, RunAtLoad bool
SessionCreate bool
StandardOut bool
StandardError bool

}{
Config: s.Config,
Path: path,
Expand All @@ -184,7 +187,7 @@ func (s *darwinLaunchdService) Uninstall() error {
func (s *darwinLaunchdService) Status() (Status, error) {
exitCode, out, err := runWithOutput("launchctl", "list", s.Name)
if exitCode == 0 && err != nil {
if !strings.Contains(err.Error(), "failed with stderr") {
if !strings.Contains(err.Error(), "failed with StandardError") {
return StatusUnknown, err
}
}
Expand Down Expand Up @@ -261,22 +264,36 @@ 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>
<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/>
</dict>
<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/>

<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>
`