ipn/ipnlocal: periodically run auto-updates when "offline" (#12118)
When the client is disconnected from control for any reason (typically just turned off), we should still attempt to update if auto-updates are enabled. This may help users who turn tailscale on infrequently for accessing resources. RELNOTE: Apply auto-updates even if the node is down or disconnected from the coordination server. Updates #12117 Signed-off-by: Andrew Lytvynov <awly@tailscale.com>main
parent
2f2f588c80
commit
bc4c8b65c7
@ -0,0 +1,60 @@ |
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build linux || windows
|
||||
|
||||
package ipnlocal |
||||
|
||||
import ( |
||||
"context" |
||||
"time" |
||||
|
||||
"tailscale.com/clientupdate" |
||||
"tailscale.com/ipn" |
||||
) |
||||
|
||||
func (b *LocalBackend) stopOfflineAutoUpdate() { |
||||
if b.offlineAutoUpdateCancel != nil { |
||||
b.logf("offline auto-update: stopping update checks") |
||||
b.offlineAutoUpdateCancel() |
||||
b.offlineAutoUpdateCancel = nil |
||||
} |
||||
} |
||||
|
||||
func (b *LocalBackend) maybeStartOfflineAutoUpdate(prefs ipn.PrefsView) { |
||||
if !prefs.AutoUpdate().Apply.EqualBool(true) { |
||||
return |
||||
} |
||||
// AutoUpdate.Apply field in prefs can only be true for platforms that
|
||||
// support auto-updates. But check it here again, just in case.
|
||||
if !clientupdate.CanAutoUpdate() { |
||||
return |
||||
} |
||||
|
||||
if b.offlineAutoUpdateCancel != nil { |
||||
// Already running.
|
||||
return |
||||
} |
||||
ctx, cancel := context.WithCancel(context.Background()) |
||||
b.offlineAutoUpdateCancel = cancel |
||||
|
||||
b.logf("offline auto-update: starting update checks") |
||||
go b.offlineAutoUpdate(ctx) |
||||
} |
||||
|
||||
const offlineAutoUpdateCheckPeriod = time.Hour |
||||
|
||||
func (b *LocalBackend) offlineAutoUpdate(ctx context.Context) { |
||||
t := time.NewTicker(offlineAutoUpdateCheckPeriod) |
||||
defer t.Stop() |
||||
for { |
||||
select { |
||||
case <-ctx.Done(): |
||||
return |
||||
case <-t.C: |
||||
} |
||||
if err := b.startAutoUpdate("offline auto-update"); err != nil { |
||||
b.logf("offline auto-update: failed: %v", err) |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !(linux || windows)
|
||||
|
||||
package ipnlocal |
||||
|
||||
import ( |
||||
"tailscale.com/ipn" |
||||
) |
||||
|
||||
func (b *LocalBackend) stopOfflineAutoUpdate() { |
||||
// Not supported on this platform.
|
||||
} |
||||
|
||||
func (b *LocalBackend) maybeStartOfflineAutoUpdate(prefs ipn.PrefsView) { |
||||
// Not supported on this platform.
|
||||
} |
||||
Loading…
Reference in new issue