CasaOS/service/health.go
Tiger Wang 0bb138e39e
add API for checking casaos-* service status (#852)
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-01-30 17:01:47 -05:00

39 lines
698 B
Go

package service
import (
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
)
type HealthService interface {
Services() (map[bool]*[]string, 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: &notRunning,
}
return result, nil
}
func NewHealthService() HealthService {
return &service{}
}