more abstraction and simple dashboard for processes
All checks were successful
Build Process Supervisor / build (amd64, .exe, windows) (push) Successful in 2m24s
Build Process Supervisor / build (amd64, , linux) (push) Successful in 2m36s
Build Process Supervisor / build (arm, 6, , linux) (push) Successful in 2m19s
Build Process Supervisor / build (arm64, , linux) (push) Successful in 2m14s
All checks were successful
Build Process Supervisor / build (amd64, .exe, windows) (push) Successful in 2m24s
Build Process Supervisor / build (amd64, , linux) (push) Successful in 2m36s
Build Process Supervisor / build (arm, 6, , linux) (push) Successful in 2m19s
Build Process Supervisor / build (arm64, , linux) (push) Successful in 2m14s
This commit is contained in:
58
supervisor/supervisor.go
Normal file
58
supervisor/supervisor.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package supervisor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type Supervisor struct {
|
||||
Processes []*Process `json:"processes"`
|
||||
}
|
||||
|
||||
func ReadTemplate(path string) (supervisor Supervisor, err error) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(content, &supervisor)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Supervisor) StartProcesses() error {
|
||||
sort.Slice(s.Processes, func(i, j int) bool {
|
||||
return s.Processes[i].Priority < s.Processes[j].Priority
|
||||
})
|
||||
|
||||
for _, p := range s.Processes {
|
||||
p.Start()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Supervisor) GetProcesses() (processes []Process) {
|
||||
for _, p := range s.Processes {
|
||||
processes = append(processes, *p)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Supervisor) StartProcessByName(name string) error {
|
||||
for _, p := range s.Processes {
|
||||
if p.Name == name {
|
||||
return p.Start()
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("process %s not found", name)
|
||||
}
|
||||
|
||||
func (s *Supervisor) StopProcessByName(name string) error {
|
||||
for _, p := range s.Processes {
|
||||
if p.Name == name {
|
||||
return p.Stop()
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("process %s not found", name)
|
||||
}
|
Reference in New Issue
Block a user