2023-01-30 22:01:47 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2023-05-09 21:02:59 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/utils/port"
|
2023-01-30 22:01:47 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HealthService interface {
|
|
|
|
Services() (map[bool]*[]string, error)
|
2023-04-24 20:10:15 +00:00
|
|
|
Ports() ([]int, []int, error)
|
2023-01-30 22:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-04-24 20:10:15 +00:00
|
|
|
func (s *service) Ports() ([]int, []int, error) {
|
2023-05-09 21:02:59 +00:00
|
|
|
return port.ListPortsInUse()
|
2023-04-24 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:01:47 +00:00
|
|
|
func NewHealthService() HealthService {
|
|
|
|
return &service{}
|
|
|
|
}
|