os.Exec() plugins to test if they will actually work

This commit is contained in:
Jeff Carr 2025-08-17 13:37:29 -05:00
parent dda5629688
commit 80fa693ba4
4 changed files with 23 additions and 7 deletions

View File

@ -21,7 +21,8 @@ gocui: build
./zookeeper --gui gocui ./zookeeper --gui gocui
gocui-debugging: build gocui-debugging: build
./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1 ./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so
# ./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1
build: goimports vet build: goimports vet
GO111MODULE=off go build -v -x \ GO111MODULE=off go build -v -x \

View File

@ -18,6 +18,7 @@ type args struct {
Verbose bool `arg:"--verbose" default:"false" help:"talk more"` Verbose bool `arg:"--verbose" default:"false" help:"talk more"`
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
Port int `arg:"--port" default:"8080" help:"port to run on"` Port int `arg:"--port" default:"8080" help:"port to run on"`
NoPort bool `arg:"--no-port" help:"don't open socket"`
} }
func (args) Version() string { func (args) Version() string {

View File

@ -75,7 +75,7 @@ func startHTTP() {
http.HandleFunc("/", okHandler) http.HandleFunc("/", okHandler)
p := fmt.Sprintf(":%d", argv.Port) p := fmt.Sprintf(":%d", argv.Port)
log.Println("Running on port", p) log.Println("zookeeper main startHTTP() Running on port", p)
err := http.ListenAndServe(p, nil) err := http.ListenAndServe(p, nil)
if err != nil { if err != nil {

24
main.go
View File

@ -21,15 +21,27 @@ var BUILDTIME string
var resources embed.FS var resources embed.FS
func main() { func main() {
log.Warn("zookeeper PID:", os.Getpid(), os.Args)
var pp *arg.Parser var pp *arg.Parser
gui.InitArg() gui.InitArg() // include the 'gui' package command line arguements
pp = arg.MustParse(&argv) pp = arg.MustParse(&argv) // parse the command line
if pp == nil { if pp == nil {
pp.WriteHelp(os.Stdout) pp.WriteHelp(os.Stdout)
os.Exit(0) os.Exit(0)
} }
// check if the binary is being called to test
// if the plugin can actually loaded. This is a hack
// around needing a Test() plugin load function in GO
if gui.IsGoPluginTestHack() {
argv.NoPort = true
gui.CheckPlugin()
os.Exit(0)
// if argv.GuiCheck != "" {
// }
}
if argv.Daemon { if argv.Daemon {
// turn off timestamps for STDOUT (systemd adds them) // turn off timestamps for STDOUT (systemd adds them)
log.DaemonMode(true) log.DaemonMode(true)
@ -45,9 +57,11 @@ func main() {
} }
// me.upgrade = make(map[string]bool) // used to trigger upgrade attempts // me.upgrade = make(map[string]bool) // used to trigger upgrade attempts
// log.Sleep(3)
go NewWatchdog() go NewWatchdog()
if !argv.NoPort {
go startHTTP() go startHTTP()
}
doGui() doGui()
} }