From ad73a027f338658496e9d6007a69edd6e3ad6de7 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Wed, 8 Jul 2020 22:47:12 +0000 Subject: [PATCH] Gets public IP every hour --- cmd/gluetun/main.go | 1 + internal/publicip/loop.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index 39bcf938..25370239 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -223,6 +223,7 @@ func _main(background context.Context, args []string) int { publicIPLooper := publicip.NewLooper(client, logger, fileManager, allSettings.System.IPStatusFilepath, uid, gid) go publicIPLooper.Run(ctx, restartPublicIP) + go publicIPLooper.RunRestartTicker(ctx, restartPublicIP) go func() { first := true diff --git a/internal/publicip/loop.go b/internal/publicip/loop.go index 46e76dfc..cecb1031 100644 --- a/internal/publicip/loop.go +++ b/internal/publicip/loop.go @@ -12,6 +12,7 @@ import ( type Looper interface { Run(ctx context.Context, restart <-chan struct{}) + RunRestartTicker(ctx context.Context, restart chan<- struct{}) } type looper struct { @@ -71,3 +72,16 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}) { } } } + +func (l *looper) RunRestartTicker(ctx context.Context, restart chan<- struct{}) { + ticker := time.NewTicker(time.Hour) + for { + select { + case <-ctx.Done(): + ticker.Stop() + return + case <-ticker.C: + restart <- struct{}{} + } + } +}