diff --git a/Dockerfile b/Dockerfile index a2e1d5a..e100c01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,5 @@ COPY --from=builder /app/etc/apiary/apiary.toml /app/apiary.toml COPY --from=builder /app/bin/apiary /app/apiary EXPOSE 8080 EXPOSE 2222 -CMD ["/app/apiary", "serve"] \ No newline at end of file +HEALTHCHECK --interval=1m --timeout=10s --start-period=5s --retries=3 CMD curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/api/health || exit 1 +CMD ["/app/apiary", "serve"] diff --git a/web/server.go b/web/server.go index f844074..2d35157 100644 --- a/web/server.go +++ b/web/server.go @@ -96,6 +96,7 @@ func NewServer(cfg config.FrontendConfig, hs *ssh.HoneypotServer, store store.Lo r.Get("/stats", s.HandlerStats) r.Get("/stream", s.HandlerAttemptStream) r.Get("/query", s.HandlerQuery) + r.Get("/health", s.HandlerHealth) }) }) s.Handler = r @@ -273,6 +274,15 @@ func (s *Server) HandlerQuery(w http.ResponseWriter, r *http.Request) { } } +func (s *Server) HandlerHealth(w http.ResponseWriter, r *http.Request) { + err := s.store.IsHealthy() + if err != nil { + s.WriteAPIError(w, r, http.StatusInternalServerError, fmt.Sprintf("Health error: %s", err)) + return + } + w.Write([]byte(`{}`)) +} + type APIErrorResponse struct { Error string `json:"error"` }