Now it waits on an http server and you can curl it to get a restart. This is a mostly working prototype.

master
Zed A. Shaw 2 days ago
parent 8a0f8ece61
commit 3a5937b19b
  1. 4
      .ozai.json
  2. 36
      main.go

@ -1,12 +1,12 @@
{ {
"Processes": { "Processes": {
"tester1": { "tester1": {
"Name": "tester1", "Name": "/tester1",
"Command": "tester", "Command": "tester",
"Args": ["-count", "100", "-id", "1"] "Args": ["-count", "100", "-id", "1"]
}, },
"tester2": { "tester2": {
"Name": "tester2", "Name": "/tester2",
"Command": "tester", "Command": "tester",
"Args": ["-count", "500", "-id", "2"] "Args": ["-count", "500", "-id", "2"]
} }

@ -5,11 +5,9 @@ import (
"os/exec" "os/exec"
"log" "log"
"io" "io"
"time" "net/http"
"math/rand"
"os" "os"
"errors" "errors"
"sync"
"lcthw.dev/go/ozai/config" "lcthw.dev/go/ozai/config"
) )
@ -23,9 +21,7 @@ func LaunchLogger(in io.Reader, out io.Writer, err error) {
}() }()
} }
func LaunchProcess(proc *config.Process, wg sync.WaitGroup) { func LaunchProcess(proc *config.Process) {
defer wg.Done()
for { for {
proc.ExecCmd = exec.Command(proc.Command, proc.Args...) proc.ExecCmd = exec.Command(proc.Command, proc.Args...)
if errors.Is(proc.ExecCmd.Err, exec.ErrDot) { if errors.Is(proc.ExecCmd.Err, exec.ErrDot) {
@ -55,30 +51,20 @@ func main() {
fmt.Println("CONFIG:", config.Settings.ConfigPath) fmt.Println("CONFIG:", config.Settings.ConfigPath)
fmt.Println("COMMANDs:", config.Settings.Processes) fmt.Println("COMMANDs:", config.Settings.Processes)
var wg sync.WaitGroup
for name, proc := range config.Settings.Processes { for name, proc := range config.Settings.Processes {
fmt.Println("PROCESS:", name) fmt.Println("PROCESS:", name)
wg.Add(1)
proc.Ready = make(chan string) proc.Ready = make(chan string)
go LaunchProcess(&proc, wg) go LaunchProcess(&proc)
go func() { http.HandleFunc(proc.Name, func(w http.ResponseWriter, r *http.Request) {
for { <-proc.Ready
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!! killer runs") fmt.Println("!!!!!!!!!!!!!!!!!!! TIME TO DIE!!!!!")
is_ready := <-proc.Ready err := proc.ExecCmd.Process.Kill()
if err != nil { log.Printf("killer says: %v", err) }
fmt.Println("is_ready returned", is_ready) })
sleep_for := rand.Int() % 10 + 1
time.Sleep(time.Duration(sleep_for) * time.Second)
fmt.Println("!!!!!!!!!!!!!!!!!!! TIME TO DIE!!!!!")
err := proc.ExecCmd.Process.Kill()
if err != nil { log.Printf("killer says: %v", err) }
}
}()
} }
wg.Wait() log.Fatal(http.ListenAndServe(":9999", nil))
} }

Loading…
Cancel
Save