Skip to content

Commit ac97c44

Browse files
authored
Add optional --ready-server to :8123 (#411)
1 parent 3113681 commit ac97c44

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log"
88
"log/slog"
9+
"net/http"
910
"net/url"
1011
"os"
1112
"path/filepath"
@@ -56,6 +57,7 @@ var (
5657
contenderArgs []string
5758
contenderTarget string
5859
detached bool
60+
readyServer bool
5961
skipSetup bool
6062
prefundedAccounts []string
6163
followFlag bool
@@ -599,6 +601,7 @@ func main() {
599601
cmd.Flags().StringArrayVar(&contenderArgs, "contender.arg", []string{}, "add/override contender CLI flags")
600602
cmd.Flags().StringVar(&contenderTarget, "contender.target", "", "override the node that contender spams")
601603
cmd.Flags().BoolVar(&detached, "detached", false, "Detached mode: Run the recipes in the background")
604+
cmd.Flags().BoolVar(&readyServer, "ready-server", false, "Start an HTTP server on 0.0.0.0:8123 that returns 200 OK when all services are healthy")
602605
cmd.Flags().BoolVar(&skipSetup, "skip-setup", false, "Skip the setup commands defined in the YAML recipe")
603606
cmd.Flags().StringArrayVar(&prefundedAccounts, "prefunded-accounts", []string{}, "Fund this account in addition to static prefunded accounts")
604607
cmd.Flags().BoolVar(&k8sFlag, "k8s", false, "generate Kubernetes manifests (requires kompose) and helper files")
@@ -881,6 +884,21 @@ func runIt(recipe playground.Recipe) error {
881884

882885
slog.Info("All services are healthy! Ready to accept transactions. 🚀", "session-id", svcManager.ID)
883886

887+
if readyServer {
888+
mux := http.NewServeMux()
889+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
890+
w.WriteHeader(http.StatusOK)
891+
})
892+
srv := &http.Server{Addr: "0.0.0.0:8123", Handler: mux}
893+
defer srv.Close()
894+
go func() {
895+
slog.Info("Ready server listening", "addr", "0.0.0.0:8123")
896+
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
897+
slog.Error("Ready server failed", "err", err)
898+
}
899+
}()
900+
}
901+
884902
// get the output from the recipe
885903
output := recipe.Output(svcManager)
886904
if len(output) > 0 {

0 commit comments

Comments
 (0)