From b3d7454a5f7b9f0cdcae7ef668391580f2153169 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 28 Dec 2020 13:14:44 -0500 Subject: [PATCH] Add UpdateInProgress to ServerInformation --- .../Models/ServerInformation.cs | 5 +++++ .../Controllers/HomeController.cs | 11 ++++++++++- .../Core/IServerControl.cs | 5 +++++ src/Tgstation.Server.Host/Server.cs | 18 ++++++++---------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Tgstation.Server.Api/Models/ServerInformation.cs b/src/Tgstation.Server.Api/Models/ServerInformation.cs index 23f7f4cfa6..16b7ea0732 100644 --- a/src/Tgstation.Server.Api/Models/ServerInformation.cs +++ b/src/Tgstation.Server.Api/Models/ServerInformation.cs @@ -28,6 +28,11 @@ namespace Tgstation.Server.Api.Models /// public bool WindowsHost { get; set; } + /// + /// If there is a server update in progress. + /// + public bool UpdateInProgress { get; set; } + /// /// A of connected s. /// diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index ec9bb367eb..23a539405e 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -73,6 +73,11 @@ namespace Tgstation.Server.Host.Controllers /// readonly ISwarmService swarmService; + /// + /// The for the . + /// + readonly IServerControl serverControl; + /// /// The for the /// @@ -102,6 +107,7 @@ namespace Tgstation.Server.Host.Controllers /// The value of . /// The value of /// The value of . + /// The value of . /// The containing the value of . /// The containing the value of /// The for the @@ -117,6 +123,7 @@ namespace Tgstation.Server.Host.Controllers IPlatformIdentifier platformIdentifier, IBrowserResolver browserResolver, ISwarmService swarmService, + IServerControl serverControl, IOptions generalConfigurationOptions, IOptions controlPanelConfigurationOptions, ILogger logger) @@ -135,6 +142,7 @@ namespace Tgstation.Server.Host.Controllers this.oAuthProviders = oAuthProviders ?? throw new ArgumentNullException(nameof(oAuthProviders)); this.browserResolver = browserResolver ?? throw new ArgumentNullException(nameof(browserResolver)); this.swarmService = swarmService ?? throw new ArgumentNullException(nameof(swarmService)); + this.serverControl = serverControl ?? throw new ArgumentNullException(nameof(serverControl)); generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); controlPanelConfiguration = controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions)); } @@ -186,7 +194,8 @@ namespace Tgstation.Server.Host.Controllers ValidInstancePaths = generalConfiguration.ValidInstancePaths, WindowsHost = platformIdentifier.IsWindows, SwarmServers = swarmService.GetSwarmServers(), - OAuthProviderInfos = await oAuthProviders.ProviderInfos(cancellationToken).ConfigureAwait(false) + OAuthProviderInfos = await oAuthProviders.ProviderInfos(cancellationToken).ConfigureAwait(false), + UpdateInProgress = serverControl.UpdateInProgress, }); } #pragma warning restore CA1506 diff --git a/src/Tgstation.Server.Host/Core/IServerControl.cs b/src/Tgstation.Server.Host/Core/IServerControl.cs index 97a60b263b..a7ca77c1b5 100644 --- a/src/Tgstation.Server.Host/Core/IServerControl.cs +++ b/src/Tgstation.Server.Host/Core/IServerControl.cs @@ -15,6 +15,11 @@ namespace Tgstation.Server.Host.Core /// bool WatchdogPresent { get; } + /// + /// Whether or not the server is currently updating + /// + bool UpdateInProgress { get; } + /// /// Run a new assembly and stop the current one. This will likely trigger all active s /// diff --git a/src/Tgstation.Server.Host/Server.cs b/src/Tgstation.Server.Host/Server.cs index f8f9c91a73..3f98fbe38a 100644 --- a/src/Tgstation.Server.Host/Server.cs +++ b/src/Tgstation.Server.Host/Server.cs @@ -21,6 +21,9 @@ namespace Tgstation.Server.Host /// public bool RestartRequested { get; private set; } + /// + public bool UpdateInProgress { get; private set; } + /// public bool WatchdogPresent => #if WATCHDOG_FREE_RESTART @@ -74,11 +77,6 @@ namespace Tgstation.Server.Host /// Exception propagatedException; - /// - /// If a server update has been or is being applied - /// - bool updating; - /// /// Construct a /// @@ -181,13 +179,13 @@ namespace Tgstation.Server.Host lock (restartLock) { - if (updating || RestartRequested) + if (UpdateInProgress || RestartRequested) { logger.LogTrace("Aborted due to concurrency conflict!"); return false; } - updating = true; + UpdateInProgress = true; } async void RunUpdate() @@ -244,7 +242,7 @@ namespace Tgstation.Server.Host } catch (Exception e) { - updating = false; + UpdateInProgress = false; try { // important to not leave this directory around if possible @@ -271,7 +269,7 @@ namespace Tgstation.Server.Host } finally { - updating = false; + UpdateInProgress = false; } } @@ -321,7 +319,7 @@ namespace Tgstation.Server.Host lock (restartLock) { - if ((updating && newVersion == null) || RestartRequested) + if ((UpdateInProgress && newVersion == null) || RestartRequested) { logger.LogTrace("Aborted due to concurrency conflict!"); return;