Skip to content

Commit

Permalink
Working healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Mar 13, 2022
1 parent 661c449 commit 4e61f1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ RUN pip3 install --upgrade nsz && apt-get update && apt-get install -y curl &&
COPY --from=build /bin/switchhost ./switchhost

# Run healthcheck against the web ui
HEALTHCHECK CMD curl --fail http://localhost:8080 || exit 1
HEALTHCHECK CMD curl --fail http://localhost:8080/healthcheck || exit 1

ENTRYPOINT ["/switchhost/switchhost", "--config","/data/config.json","--keys","/data/prod.keys","--noCUI"]
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ services:
tty: true
build:
context: .
ports:
- 8080:8080
- 2121:2121
volumes:
- ./:/switchhost/src/:Z
- ./config.json:/data/config.json
Expand Down
12 changes: 9 additions & 3 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,19 @@ func (server *Server) checkSettingsEdit(req *http.Request) bool {
return match
}
func (server *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) {

var head string
head, req.URL.Path = ShiftPath(req.URL.Path)
//Healthcheck does not require auth so chcek it first
if head == "healthcheck" {
res.WriteHeader(http.StatusOK)
return
}
//Check auth
if !server.checkAuth(req) {
res.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
http.Error(res, "Auth required", http.StatusUnauthorized)
return
}
var head string
head, req.URL.Path = ShiftPath(req.URL.Path)

switch head {
case "vfile":
Expand All @@ -217,6 +221,8 @@ func (server *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) {
server.httpHandleIndex(res, req)
case "config":
server.httpHandleConfig(res, req)
default:
res.WriteHeader(http.StatusNotFound)
}
}

Expand Down
2 changes: 1 addition & 1 deletion start_docker.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/sh

docker-compose run --rm switchhost
docker-compose run --rm --service-ports switchhost

0 comments on commit 4e61f1c

Please sign in to comment.