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

[OpenRC] Try to resolve the service before calling status #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions service_openrc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ func (s *openrc) Run() (err error) {
}

func (s *openrc) Status() (Status, error) {
// rc-service uses the errno library for its exit codes:
// errno 0 = service started
// errno 1 = EPERM 1 Operation not permitted
// errno 2 = ENOENT 2 No such file or directory
// errno 3 = ESRCH 3 No such process
// for more info, see https://man7.org/linux/man-pages/man3/errno.3.html
// On OpenRC, rc-service returns the following exit codes:
// 0 - service status successful
// 1 - service status failed, can be various reasons (not installed, etc)
// 3 - service is stopped
// see https://github.com/OpenRC/openrc/blob/master/src/rc-service/rc-service.c#L153-L157

// To be able to detect whether a service is installed or not, we need to try to resolve the service
err := run("rc-service", "--resolve", s.Name)
if err != nil {
return StatusUnknown, ErrNotInstalled
}

_, out, err := runWithOutput("rc-service", s.Name, "status")
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
Expand All @@ -180,8 +186,6 @@ func (s *openrc) Status() (Status, error) {
switch {
case exitCode == 1:
return StatusUnknown, err
case exitCode == 2:
return StatusUnknown, ErrNotInstalled
case exitCode == 3:
return StatusStopped, nil
default:
Expand Down