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