mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
cmd/cli: workaround incorrect status data when not root
This commit is contained in:
+19
-1
@@ -28,6 +28,9 @@ func newService(i service.Interface, c *service.Config) (service.Service, error)
|
|||||||
return &sysV{s}, nil
|
return &sysV{s}, nil
|
||||||
case s.Platform() == "linux-systemd":
|
case s.Platform() == "linux-systemd":
|
||||||
return &systemd{s}, nil
|
return &systemd{s}, nil
|
||||||
|
case s.Platform() == "darwin-launchd":
|
||||||
|
return &launchd{s}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,7 @@ func (s *procd) Status() (service.Status, error) {
|
|||||||
return service.StatusRunning, nil
|
return service.StatusRunning, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// procd wraps a service.Service, and provide status command to
|
// systemd wraps a service.Service, and provide status command to
|
||||||
// report the status correctly.
|
// report the status correctly.
|
||||||
type systemd struct {
|
type systemd struct {
|
||||||
service.Service
|
service.Service
|
||||||
@@ -127,6 +130,21 @@ func (s *systemd) Status() (service.Status, error) {
|
|||||||
return s.Service.Status()
|
return s.Service.Status()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// launchd wraps a service.Service, and provide status command to
|
||||||
|
// report the status correctly when not running as root on Darwin.
|
||||||
|
//
|
||||||
|
// TODO: remove this wrapper once https://github.com/kardianos/service/issues/400 fixed.
|
||||||
|
type launchd struct {
|
||||||
|
service.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *launchd) Status() (service.Status, error) {
|
||||||
|
if os.Geteuid() != 0 {
|
||||||
|
return service.StatusUnknown, errors.New("permission denied")
|
||||||
|
}
|
||||||
|
return l.Service.Status()
|
||||||
|
}
|
||||||
|
|
||||||
type task struct {
|
type task struct {
|
||||||
f func() error
|
f func() error
|
||||||
abortOnError bool
|
abortOnError bool
|
||||||
|
|||||||
Reference in New Issue
Block a user