- New option: `HEALTH_ICMP_TARGET_IP` defaults to `0.0.0.0` meaning use the VPN server public IP address. - Options removed: `HEALTH_VPN_INITIAL_DURATION` and `HEALTH_VPN_ADDITIONAL_DURATION` - times and retries are handpicked and hardcoded. - Less aggressive checks and less false positive detection
39 lines
922 B
Go
39 lines
922 B
Go
package healthcheck
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func (s *Server) Run(ctx context.Context, done chan<- struct{}) {
|
|
defer close(done)
|
|
|
|
server := http.Server{
|
|
Addr: s.config.ServerAddress,
|
|
Handler: s.handler,
|
|
ReadHeaderTimeout: s.config.ReadHeaderTimeout,
|
|
ReadTimeout: s.config.ReadTimeout,
|
|
}
|
|
serverDone := make(chan struct{})
|
|
go func() {
|
|
defer close(serverDone)
|
|
<-ctx.Done()
|
|
const shutdownGraceDuration = 2 * time.Second
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), shutdownGraceDuration)
|
|
defer cancel()
|
|
if err := server.Shutdown(shutdownCtx); err != nil {
|
|
s.logger.Error("failed shutting down: " + err.Error())
|
|
}
|
|
}()
|
|
|
|
s.logger.Info("listening on " + s.config.ServerAddress)
|
|
err := server.ListenAndServe()
|
|
if err != nil && !errors.Is(ctx.Err(), context.Canceled) {
|
|
s.logger.Error(err.Error())
|
|
}
|
|
|
|
<-serverDone
|
|
}
|