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. 28
      main.go

@ -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"]
}

@ -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
go LaunchProcess(&proc)
fmt.Println("is_ready returned", is_ready)
sleep_for := rand.Int() % 10 + 1
time.Sleep(time.Duration(sleep_for) * time.Second)
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))
}

Loading…
Cancel
Save