diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs index 21a45d3e60..6c8b65b05f 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs @@ -76,5 +76,12 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the operation /// A representing the running operation Task Terminate(bool graceful, CancellationToken cancellationToken); + + /// + /// Cancels pending graceful actions + /// + /// The for the operation + /// A representing the running operation + Task ResetRebootState(CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs index e51e28e9a2..bbd159f5a4 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs @@ -764,6 +764,19 @@ namespace Tgstation.Server.Host.Components.Watchdog return await LaunchNoLock(true, true, false, cancellationToken).ConfigureAwait(false); } + /// + public async Task ResetRebootState(CancellationToken cancellationToken) + { + using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false)) + { + if (!Running) + return; + var toClear = AlphaIsActive ? alphaServer : bravoServer; + if (toClear != null) + toClear.ResetRebootState(); + } + } + /// public async Task Restart(bool graceful, CancellationToken cancellationToken) { @@ -784,12 +797,10 @@ namespace Tgstation.Server.Host.Components.Watchdog return result; } var toReboot = AlphaIsActive ? alphaServer : bravoServer; - var other = AlphaIsActive ? bravoServer : alphaServer; if (toReboot != null) { if (!await toReboot.SetRebootState(Components.Watchdog.RebootState.Restart, cancellationToken).ConfigureAwait(false)) logger.LogWarning("Unable to send reboot state change event!"); - } return null; } diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 1100022216..e7cd7ac52e 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -192,13 +192,13 @@ namespace Tgstation.Server.Host.Controllers //run these in parallel because they are equally as important await Task.WhenAll(DatabaseContext.Save(cancellationToken), wd.ChangeSettings(current, cancellationToken)).ConfigureAwait(false); - - //soft shutdown/restart can't be cancelled because of how many things rely on them - //They can be alternated though + if (!oldSoftRestart.Value && current.SoftRestart.Value) await wd.Restart(true, cancellationToken).ConfigureAwait(false); else if (!oldSoftShutdown.Value && current.SoftShutdown.Value) await wd.Terminate(true, cancellationToken).ConfigureAwait(false); + else if ((oldSoftRestart.Value && !current.SoftRestart.Value) || (oldSoftShutdown.Value && !current.SoftShutdown.Value)) + await wd.ResetRebootState(cancellationToken).ConfigureAwait(false); return await ReadImpl(current, cancellationToken).ConfigureAwait(false); }