diff --git a/.ozai.json b/.ozai.json index ef72948..a2b136d 100644 --- a/.ozai.json +++ b/.ozai.json @@ -1,12 +1,12 @@ { "Processes": { "tester1": { - "Name": "tester1", + "Name": "/tester1", "Command": "tester", "Args": ["-count", "100", "-id", "1"] }, "tester2": { - "Name": "tester2", + "Name": "/tester2", "Command": "tester", "Args": ["-count", "500", "-id", "2"] } diff --git a/main.go b/main.go index 7df4589..fba9a97 100644 --- a/main.go +++ b/main.go @@ -5,11 +5,9 @@ import ( "os/exec" "log" "io" - "time" - "math/rand" + "net/http" "os" "errors" - "sync" "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) { - defer wg.Done() - +func LaunchProcess(proc *config.Process) { for { proc.ExecCmd = exec.Command(proc.Command, proc.Args...) if errors.Is(proc.ExecCmd.Err, exec.ErrDot) { @@ -55,30 +51,20 @@ func main() { fmt.Println("CONFIG:", config.Settings.ConfigPath) fmt.Println("COMMANDs:", config.Settings.Processes) - var wg sync.WaitGroup for name, proc := range config.Settings.Processes { fmt.Println("PROCESS:", name) - wg.Add(1) proc.Ready = make(chan string) - go LaunchProcess(&proc, wg) - - go func() { - for { - fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!! killer runs") - is_ready := <-proc.Ready - - 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) } - } - }() + go LaunchProcess(&proc) + + http.HandleFunc(proc.Name, func(w http.ResponseWriter, r *http.Request) { + <-proc.Ready + 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)) }