diff --git a/core/api.go b/core/api.go index 559c7914..9994e4a4 100644 --- a/core/api.go +++ b/core/api.go @@ -68,8 +68,6 @@ func shutdown(_ *api.Request) (msg string, err error) { func restart(_ *api.Request) (msg string, err error) { log.Info("core: user requested restart via action") - // Trigger restart event instead of shutdown event. - restarting.Set() // Let the updates module handle restarting. updates.RestartNow() diff --git a/core/core.go b/core/core.go index 1ed8e73e..23a48946 100644 --- a/core/core.go +++ b/core/core.go @@ -7,13 +7,12 @@ import ( "github.com/safing/portbase/modules" "github.com/safing/portbase/modules/subsystems" - "github.com/tevino/abool" + "github.com/safing/portmaster/updates" // module dependencies _ "github.com/safing/portmaster/netenv" _ "github.com/safing/portmaster/status" _ "github.com/safing/portmaster/ui" - _ "github.com/safing/portmaster/updates" ) const ( @@ -24,7 +23,6 @@ const ( var ( module *modules.Module - restarting = abool.New() disableShutdownEvent bool ) @@ -82,7 +80,7 @@ func registerEvents() { func shutdownHook() { // Notify everyone of the restart/shutdown. - if restarting.IsNotSet() { + if !updates.IsRestarting() { // Only trigger shutdown event if not disabled. if !disableShutdownEvent { module.TriggerEvent(eventShutdown, nil) diff --git a/updates/restart.go b/updates/restart.go index d70486ec..8d6d98eb 100644 --- a/updates/restart.go +++ b/updates/restart.go @@ -20,6 +20,11 @@ var ( restartTriggered = abool.New() ) +// IsRestarting returns whether a restart is pending or currently in progress. +func IsRestarting() bool { + return restartPending.IsSet() +} + // DelayedRestart triggers a restart of the application by shutting down the // module system gracefully and returning with RestartExitCode. The restart // may be further delayed by up to 10 minutes by the internal task scheduling @@ -52,6 +57,10 @@ func RestartNow() { func automaticRestart(_ context.Context, _ *modules.Task) error { if restartTriggered.SetToIf(false, true) { log.Info("updates: initiating (automatic) restart") + + // Set restart pending to ensure IsRestarting() returns true. + restartPending.Set() + // Set restart exit code. modules.SetExitStatusCode(RestartExitCode) // Do not use a worker, as this would block itself here. go modules.Shutdown() //nolint:errcheck