2021-07-18 03:17:48 +00:00
|
|
|
package healthcheck
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
2021-08-18 22:01:04 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/vpn"
|
2021-07-18 03:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
2021-08-18 22:01:04 +00:00
|
|
|
type vpnHealth struct {
|
|
|
|
|
looper vpn.Looper
|
2021-07-23 19:22:41 +00:00
|
|
|
healthyWait time.Duration
|
|
|
|
|
healthyTimer *time.Timer
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 21:04:21 +00:00
|
|
|
func (s *Server) onUnhealthyVPN(ctx context.Context) {
|
2021-07-18 03:17:48 +00:00
|
|
|
s.logger.Info("program has been unhealthy for " +
|
2021-09-11 21:04:21 +00:00
|
|
|
s.vpn.healthyWait.String() + ": restarting VPN")
|
2021-08-18 22:01:04 +00:00
|
|
|
_, _ = s.vpn.looper.ApplyStatus(ctx, constants.Stopped)
|
|
|
|
|
_, _ = s.vpn.looper.ApplyStatus(ctx, constants.Running)
|
2021-09-11 21:04:21 +00:00
|
|
|
s.vpn.healthyWait += s.config.VPN.Addition
|
2021-08-18 22:01:04 +00:00
|
|
|
s.vpn.healthyTimer = time.NewTimer(s.vpn.healthyWait)
|
2021-07-18 03:17:48 +00:00
|
|
|
}
|