forked from IceWhaleTech/CasaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.go
45 lines (35 loc) · 864 Bytes
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package service
import (
"github.com/IceWhaleTech/CasaOS-Common/utils/port"
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
)
type HealthService interface {
Services() (map[bool]*[]string, error)
Ports() ([]int, []int, error)
}
type service struct{}
func (s *service) Services() (map[bool]*[]string, error) {
services, err := systemctl.ListServices("casaos*")
if err != nil {
return nil, err
}
var running, notRunning []string
for _, service := range services {
if service.Running {
running = append(running, service.Name)
} else {
notRunning = append(notRunning, service.Name)
}
}
result := map[bool]*[]string{
true: &running,
false: ¬Running,
}
return result, nil
}
func (s *service) Ports() ([]int, []int, error) {
return port.ListPortsInUse()
}
func NewHealthService() HealthService {
return &service{}
}