From 6b12d3c4ccfa5c7d925c7fe2ca718fff1e93c69a Mon Sep 17 00:00:00 2001 From: Dov Alperin Date: Fri, 7 Apr 2023 12:24:25 -0400 Subject: [PATCH 1/2] Add endpoint to bounce haproxy --- pkg/commands/admin.go | 21 +++++++++++++++++++++ pkg/commands/handler.go | 1 + 2 files changed, 22 insertions(+) diff --git a/pkg/commands/admin.go b/pkg/commands/admin.go index 90449dd..4718902 100644 --- a/pkg/commands/admin.go +++ b/pkg/commands/admin.go @@ -288,3 +288,24 @@ func handleDisableReadonly(w http.ResponseWriter, r *http.Request) { render.JSON(w, resp, http.StatusOK) } + +func handleBounceHaproxy(w http.ResponseWriter, r *http.Request) { + args := []string{"root", "pkill", "haproxy"} + + cmd := exec.Command("gosu", args...) + + if err := cmd.Run(); err != nil { + render.Err(w, err) + return + } + + if cmd.ProcessState.ExitCode() != 0 { + err := fmt.Errorf(cmd.ProcessState.String()) + render.Err(w, err) + return + } + + resp := &Response{Result: true} + + render.JSON(w, resp, http.StatusOK) +} diff --git a/pkg/commands/handler.go b/pkg/commands/handler.go index 68c6d3a..f293abe 100644 --- a/pkg/commands/handler.go +++ b/pkg/commands/handler.go @@ -36,6 +36,7 @@ func Handler() http.Handler { r.Post("/readonly/enable", handleEnableReadonly) r.Post("/readonly/disable", handleDisableReadonly) r.Get("/dbuid", handleStolonDBUid) + r.Post("/haproxy/bounce", handleBounceHaproxy) r.Post("/settings/update", handleUpdateSettings) }) From 0c628c6c115471973af77eca78f2fabdbaea875a Mon Sep 17 00:00:00 2001 From: Dov Alperin Date: Fri, 7 Apr 2023 13:13:45 -0400 Subject: [PATCH 2/2] No bounce ;) --- pkg/commands/admin.go | 2 +- pkg/commands/handler.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/admin.go b/pkg/commands/admin.go index 4718902..33c850d 100644 --- a/pkg/commands/admin.go +++ b/pkg/commands/admin.go @@ -289,7 +289,7 @@ func handleDisableReadonly(w http.ResponseWriter, r *http.Request) { render.JSON(w, resp, http.StatusOK) } -func handleBounceHaproxy(w http.ResponseWriter, r *http.Request) { +func handleRestartHaproxy(w http.ResponseWriter, r *http.Request) { args := []string{"root", "pkill", "haproxy"} cmd := exec.Command("gosu", args...) diff --git a/pkg/commands/handler.go b/pkg/commands/handler.go index f293abe..bbe2dd6 100644 --- a/pkg/commands/handler.go +++ b/pkg/commands/handler.go @@ -36,7 +36,7 @@ func Handler() http.Handler { r.Post("/readonly/enable", handleEnableReadonly) r.Post("/readonly/disable", handleDisableReadonly) r.Get("/dbuid", handleStolonDBUid) - r.Post("/haproxy/bounce", handleBounceHaproxy) + r.Post("/haproxy/restart", handleRestartHaproxy) r.Post("/settings/update", handleUpdateSettings) })