diff --git a/Dockerfile b/Dockerfile index 9708ce4..9977511 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,5 +13,4 @@ RUN export CGO_ENABLED=0 \ FROM alpine AS goircd COPY --from=goircd-builder /go/bin/goircd /bin/goircd -ENTRYPOINT ["sh","-c"] -CMD ["exec goircd"] \ No newline at end of file +ENTRYPOINT ["goircd"] diff --git a/goircd.go b/goircd.go index 128dcf3..e30db55 100644 --- a/goircd.go +++ b/goircd.go @@ -29,6 +29,7 @@ import ( "strings" "time" + healthchecking "github.com/heptiolabs/healthcheck" "github.com/namsral/flag" proxyproto "github.com/Freeaqingme/go-proxyproto" @@ -37,7 +38,8 @@ import ( ) const ( - PROXY_TIMEOUT = 5 + PROXY_TIMEOUT = 5 + HEALTCHECK_PORT = 8080 ) var ( @@ -54,6 +56,7 @@ var ( proxyTimeout = flag.Uint("proxytimeout", PROXY_TIMEOUT, "Timeout when using proxy protocol") metrics = flag.Bool("metrics", false, "Enable metrics export") verbose = flag.Bool("v", false, "Enable verbose logging.") + healtcheck = flag.Bool("healthcheck", false, "Enable healthcheck endpoint.") clients_tls_total = prometheus.NewCounter( prometheus.CounterOpts{ @@ -190,10 +193,23 @@ func Run() { if *metrics { go prom_export() } + if *healtcheck { + go health_endpoint() + } Processor(events, make(chan struct{})) } +func health_endpoint() { + var ( + health_bind = "0.0.0.0:8086" + ) + health := healthchecking.NewHandler() + health.AddLivenessCheck("goroutine-threshold", healthchecking.GoroutineCountCheck(100)) + log.Printf("Healthcheck listening on http://%s", health_bind) + http.ListenAndServe(health_bind, health) +} + func prom_export() { prometheus.MustRegister(clients_tls_total) prometheus.MustRegister(clients_irc_total)