Skip to content

Commit

Permalink
Merge pull request #101 from fly-apps/bounce_haproxy
Browse files Browse the repository at this point in the history
Add endpoint to bounce haproxy
  • Loading branch information
DAlperin authored Apr 7, 2023
2 parents bdf0827 + 0c628c6 commit a3c883f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/commands/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,24 @@ func handleDisableReadonly(w http.ResponseWriter, r *http.Request) {

render.JSON(w, resp, http.StatusOK)
}

func handleRestartHaproxy(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)
}
1 change: 1 addition & 0 deletions pkg/commands/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/restart", handleRestartHaproxy)
r.Post("/settings/update", handleUpdateSettings)
})

Expand Down

0 comments on commit a3c883f

Please sign in to comment.