Skip to content

Commit a3c883f

Browse files
authored
Merge pull request #101 from fly-apps/bounce_haproxy
Add endpoint to bounce haproxy
2 parents bdf0827 + 0c628c6 commit a3c883f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/commands/admin.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,24 @@ func handleDisableReadonly(w http.ResponseWriter, r *http.Request) {
288288

289289
render.JSON(w, resp, http.StatusOK)
290290
}
291+
292+
func handleRestartHaproxy(w http.ResponseWriter, r *http.Request) {
293+
args := []string{"root", "pkill", "haproxy"}
294+
295+
cmd := exec.Command("gosu", args...)
296+
297+
if err := cmd.Run(); err != nil {
298+
render.Err(w, err)
299+
return
300+
}
301+
302+
if cmd.ProcessState.ExitCode() != 0 {
303+
err := fmt.Errorf(cmd.ProcessState.String())
304+
render.Err(w, err)
305+
return
306+
}
307+
308+
resp := &Response{Result: true}
309+
310+
render.JSON(w, resp, http.StatusOK)
311+
}

pkg/commands/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func Handler() http.Handler {
3636
r.Post("/readonly/enable", handleEnableReadonly)
3737
r.Post("/readonly/disable", handleDisableReadonly)
3838
r.Get("/dbuid", handleStolonDBUid)
39+
r.Post("/haproxy/restart", handleRestartHaproxy)
3940
r.Post("/settings/update", handleUpdateSettings)
4041
})
4142

0 commit comments

Comments
 (0)