|
|
|
@ -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)) |
|
|
|
|
} |
|
|
|
|