Add support for retrieving service status (#143)

* update command execution to support returing error codes, and stdout

add function to service interface to support returning service status

clean up places where strings were being converted to strings

* Spelling fix

* Simply service Status method

Add stopped detection to launchd
Switch to case statements
Return ErrNotInstalled in situations where we should
This commit is contained in:
SteelPhase
2018-08-22 14:05:01 -04:00
committed by Daniel Theophanes
parent 4cdeddd6f4
commit 45244176fc
7 changed files with 198 additions and 15 deletions
+17
View File
@@ -9,6 +9,7 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"text/template"
"time"
@@ -143,6 +144,22 @@ func (s *sysv) Run() (err error) {
return s.i.Stop(s)
}
func (s *sysv) Status() (Status, error) {
_, out, err := runWithOutput("service", s.Name, "status")
if err != nil {
return StatusUnknown, err
}
switch {
case strings.HasPrefix(out, "Running"):
return StatusRunning, nil
case strings.HasPrefix(out, "Stopped"):
return StatusStopped, nil
default:
return StatusUnknown, ErrNotInstalled
}
}
func (s *sysv) Start() error {
return run("service", s.Name, "start")
}