Skip to content

Commit

Permalink
systemd: Fallback on sysv if systemd service is not found (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
aelsabbahy authored Jul 22, 2016
1 parent 6982df6 commit 390a2d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion resource/gomega.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func matcherToGomegaMatcher(matcher interface{}) (types.GomegaMatcher, error) {
if err != nil {
return nil, err
}
fmt.Print(subMatcher)
return gomega.ContainElement(subMatcher), nil
case "not":
subMatcher, err := matcherToGomegaMatcher(value)
Expand Down
15 changes: 15 additions & 0 deletions system/service_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (s *ServiceSystemd) Exists() (bool, error) {
if strings.Contains(cmd.Stdout.String(), fmt.Sprintf("%s.service", s.service)) {
return true, cmd.Err
}
// Fallback on sysv
sysv := &ServiceInit{service: s.service}
if e, err := sysv.Exists(); e && err == nil {
return true, nil
}
return false, nil
}

Expand All @@ -36,6 +41,11 @@ func (s *ServiceSystemd) Enabled() (bool, error) {
if cmd.Status == 0 {
return true, cmd.Err
}
// Fallback on sysv
sysv := &ServiceInit{service: s.service}
if en, err := sysv.Enabled(); en && err == nil {
return true, nil
}
return false, nil
}

Expand All @@ -45,5 +55,10 @@ func (s *ServiceSystemd) Running() (bool, error) {
if cmd.Status == 0 {
return true, cmd.Err
}
// Fallback on sysv
sysv := &ServiceInit{service: s.service}
if r, err := sysv.Running(); r && err == nil {
return true, nil
}
return false, nil
}
17 changes: 8 additions & 9 deletions system/service_upstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func (s *ServiceUpstart) Service() string {
func (s *ServiceUpstart) Exists() (bool, error) {
// upstart
if _, err := os.Stat(fmt.Sprintf("/etc/init/%s.conf", s.service)); err == nil {
return true, err
return true, nil
}

// initv
if _, err := os.Stat(fmt.Sprintf("/etc/init.d/%s", s.service)); err == nil {
return true, err
// Fallback on sysv
sysv := &ServiceInit{service: s.service}
if e, err := sysv.Exists(); e && err == nil {
return true, nil
}
return false, nil
}
Expand All @@ -47,12 +47,11 @@ func (s *ServiceUpstart) Enabled() (bool, error) {
}
}
}

// Fall back on initv
if en, _ := initServiceEnabled(s.service, 3); en {
// Fallback on sysv
sysv := &ServiceInit{service: s.service}
if en, err := sysv.Enabled(); en && err == nil {
return true, nil
}

return false, nil
}

Expand Down

0 comments on commit 390a2d7

Please sign in to comment.