diff --git a/chasquid.go b/chasquid.go
index 32491ba..00bb2a7 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -93,7 +93,7 @@ func main() {
go signalHandler()
if conf.MonitoringAddress != "" {
- launchMonitoringServer(conf)
+ go launchMonitoringServer(conf)
}
s := smtpsrv.NewServer()
diff --git a/monitoring.go b/monitoring.go
index 1009bce..6f6aab3 100644
--- a/monitoring.go
+++ b/monitoring.go
@@ -1,6 +1,7 @@
package main
import (
+ "context"
"flag"
"fmt"
"html/template"
@@ -49,11 +50,16 @@ func launchMonitoringServer(conf *config.Config) {
}
})
+ srv := &http.Server{Addr: conf.MonitoringAddress}
+
+ http.HandleFunc("/exit", exitHandler(srv))
http.HandleFunc("/metrics", expvarom.MetricsHandler)
http.HandleFunc("/debug/flags", debugFlagsHandler)
http.HandleFunc("/debug/config", debugConfigHandler(conf))
- go http.ListenAndServe(conf.MonitoringAddress, nil)
+ if err := srv.ListenAndServe(); err != http.ErrServerClosed {
+ log.Fatalf("Monitoring server failed: %v", err)
+ }
}
// Functions available inside the templates.
@@ -123,6 +129,28 @@ os hostname {{.Hostname}}