From 4b90ec9c8d08e1a9e5b216335678f9952534f71d Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Wed, 27 Sep 2023 12:48:35 -0400 Subject: [PATCH] chore: Return 502 from health endpoint on shutdown On shutdown, there will be a file at `/tmp/vroom.down`. When this file exists, it's a sign that the pod will shutdown. So return 502 from the health endpoint. --- cmd/vroom/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/vroom/main.go b/cmd/vroom/main.go index 48b8f2b..4d21b74 100644 --- a/cmd/vroom/main.go +++ b/cmd/vroom/main.go @@ -225,7 +225,11 @@ func main() { } func (e *environment) getHealth(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(http.StatusNoContent) + if _, err := os.Stat("/tmp/vroom.down"); err == nil { + w.WriteHeader(http.StatusNoContent) + } else { + w.WriteHeader(http.StatusBadGateway) + } } type Filter struct {