From e4ed1e6d596656d0b959b2bbfb445851c88817ee Mon Sep 17 00:00:00 2001 From: Danie Roux Date: Fri, 18 Oct 2024 17:02:14 +0200 Subject: [PATCH 1/2] Add `--exit-with-highest-exit-code` which fails hivemind with the highest exit code of any processes This allows for process failures to bubble up to the shell. Example: ```console $ hivemind --exit-with-highest-exit-code - < exitCode { + exitCode = code + } + } + + return exitCode } diff --git a/main.go b/main.go index 7c2bf58..c53bea5 100644 --- a/main.go +++ b/main.go @@ -30,14 +30,15 @@ func main() { app.HideHelp = true app.Flags = []cli.Flag{ - cli.StringFlag{Name: "title, w", EnvVar: "HIVEMIND_TITLE", Usage: "Specify a title of the application", Destination: &conf.Title}, - cli.StringFlag{Name: "processes, l", EnvVar: "HIVEMIND_PROCESSES", Usage: "Specify process names to launch. Divide names with comma", Destination: &conf.ProcNames}, + cli.StringFlag{Name: "title, w", EnvVar: "HIVEMIND_TITLE", Usage: "specify a title of the application", Destination: &conf.Title}, + cli.StringFlag{Name: "processes, l", EnvVar: "HIVEMIND_PROCESSES", Usage: "specify process names to launch. Divide names with comma", Destination: &conf.ProcNames}, cli.IntFlag{Name: "port, p", EnvVar: "HIVEMIND_PORT,PORT", Usage: "specify a port to use as the base", Value: 5000, Destination: &conf.PortBase}, cli.IntFlag{Name: "port-step, P", EnvVar: "HIVEMIND_PORT_STEP", Usage: "specify a step to increase port number", Value: 100, Destination: &conf.PortStep}, cli.StringFlag{Name: "root, d", EnvVar: "HIVEMIND_ROOT", Usage: "specify a working directory of application. Default: directory containing the Procfile", Destination: &conf.Root}, cli.IntFlag{Name: "timeout, t", EnvVar: "HIVEMIND_TIMEOUT", Usage: "specify the amount of time (in seconds) processes have to shut down gracefully before being brutally killed", Value: 5, Destination: &conf.Timeout}, cli.BoolFlag{Name: "no-prefix", EnvVar: "HIVEMIND_NO_PREFIX", Usage: "process names will not be printed if the flag is specified", Destination: &conf.NoPrefix}, cli.BoolFlag{Name: "print-timestamps, T", EnvVar: "HIVEMIND_PRINT_TIMESTAMPS", Usage: "timestamps will be printed if the flag is specified", Destination: &conf.PrintTimestamps}, + cli.BoolFlag{Name: "exit-with-highest-exit-code, e", EnvVar: "HIVEMIND_EXIT_WITH_HIGHEST_EXIT_CODE", Usage: "exit hivemind with highest exit code from all processes", Destination: &conf.ExitWithHighest}, } app.Action = func(c *cli.Context) error { @@ -65,7 +66,10 @@ func main() { conf.Root, err = filepath.Abs(conf.Root) fatalOnErr(err) - newHivemind(conf).Run() + exitCode := newHivemind(conf).Run() + if exitCode > 0 && conf.ExitWithHighest { + return cli.NewExitError("At least one process failed", exitCode) + } return nil } From 8a9ee7e1b37aac5201ac571610e83821cda3498b Mon Sep 17 00:00:00 2001 From: Danie Roux Date: Fri, 18 Oct 2024 19:50:06 +0200 Subject: [PATCH 2/2] Add `--as-job-runner`: With this flag hivemind will let processes exit gracefully, and wait for all to complete See `test-as-job-runner.sh` and: Example: ```shellsession hivemind --as-job-runner --exit-with-highest-exit-code - <