Now have a simple tester .exe that will do various start/stop/run patterns and then used that to sort out how to monitor the processes and keep them running. Next is to add process monitoring and a way to signal ozai to stop something.

master
Zed A. Shaw 3 days ago
parent 0c9bfe2f76
commit 1ba7fc14ff
  1. 12
      .ozai.json
  2. 5
      Makefile
  3. 1
      config/settings.go
  4. 2
      go.mod
  5. 2
      go.sum
  6. 36
      main.go
  7. 18
      tools/cmd/tester/main.go

@ -1,8 +1,14 @@
{ {
"Processes": { "Processes": {
"ssgod": { "tester1": {
"Name": "ssgod", "Name": "tester",
"Command": "ssgod" "Command": "tester",
"Args": ["-count", "2", "-id", "1"]
},
"tester2": {
"Name": "tester",
"Command": "tester",
"Args": ["-count", "5", "-id", "2"]
} }
} }
} }

@ -4,13 +4,16 @@ ifeq '$(OS)' 'Windows_NT'
GO_IS_STUPID_EXE=.exe GO_IS_STUPID_EXE=.exe
endif endif
build: build: build_tester
go build . go build .
test: test:
go test lcthw.dev/learn-code-the-hard-way/ozai/tests -c -o runtests$(GO_IS_STUPID_EXE) go test lcthw.dev/learn-code-the-hard-way/ozai/tests -c -o runtests$(GO_IS_STUPID_EXE)
./runtests$(GO_IS_STUPID_EXE) ./runtests$(GO_IS_STUPID_EXE)
build_tester:
go build -o tester$(GO_IS_STUPID_EXE) ./tools/cmd/tester/main.go
docs: docs:
go tool pkgsite --open go tool pkgsite --open

@ -10,6 +10,7 @@ import (
type command struct { type command struct {
Command string Command string
Args []string
} }
type config struct { type config struct {

@ -2,8 +2,6 @@ module lcthw.dev/learn-code-the-hard-way/ozai
go 1.24.2 go 1.24.2
require github.com/BurntSushi/toml v1.5.0
require ( require (
github.com/google/licensecheck v0.3.1 // indirect github.com/google/licensecheck v0.3.1 // indirect
github.com/google/safehtml v0.0.3-0.20211026203422-d6f0e11a5516 // indirect github.com/google/safehtml v0.0.3-0.20211026203422-d6f0e11a5516 // indirect

@ -1,5 +1,3 @@
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/licensecheck v0.3.1 h1:QoxgoDkaeC4nFrtGN1jV7IPmDCHFNIVh54e5hSt6sPs= github.com/google/licensecheck v0.3.1 h1:QoxgoDkaeC4nFrtGN1jV7IPmDCHFNIVh54e5hSt6sPs=

@ -5,6 +5,7 @@ import (
"os/exec" "os/exec"
"log" "log"
"errors" "errors"
"sync"
"lcthw.dev/learn-code-the-hard-way/ozai/config" "lcthw.dev/learn-code-the-hard-way/ozai/config"
) )
@ -13,18 +14,35 @@ 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
cmd := exec.Command(config.Settings.Processes["ssgod"].Command) for name, proc := range config.Settings.Processes {
if errors.Is(cmd.Err, exec.ErrDot) { fmt.Println("PROCESS:", name)
cmd.Err = nil wg.Add(1)
}
go func() {
defer wg.Done()
for {
fmt.Println("STARTING", name)
cmd := exec.Command(proc.Command, proc.Args...)
if errors.Is(cmd.Err, exec.ErrDot) {
cmd.Err = nil
}
out, err := cmd.CombinedOutput()
out, err := cmd.CombinedOutput() if err != nil {
fmt.Printf("%s\n", out)
log.Fatal(err)
}
if err != nil { fmt.Println("WAITING for", name)
fmt.Printf("%s\n", out) cmd.Wait()
log.Fatal(err) fmt.Println("PROC", name, "EXITED SEND QUIT")
}
}()
} }
cmd.Wait() wg.Wait()
} }

@ -0,0 +1,18 @@
package main
import (
"fmt"
"time"
"flag"
)
func main() {
count := flag.Int("count", 10, "Seconds to wait")
id := flag.Int("id", 1, "Tester ID to use.")
for i := 0; i < *count; i++ {
time.Sleep(1 * time.Second)
fmt.Println("TICK", *id)
}
}
Loading…
Cancel
Save