diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs
index 2002597284..926d5239ba 100644
--- a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs
+++ b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs
@@ -26,11 +26,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
///
Models.CompileJob ActiveCompileJob { get; }
- ///
- /// The latest of the twin servers
- ///
- LaunchResult LastLaunchResult { get; }
-
///
/// The the active server is using
///
@@ -50,8 +45,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// Start the
///
/// The for the operation
- /// A resulting in the or if it was already running
- Task Launch(CancellationToken cancellationToken);
+ /// A representing the running operation
+ Task Launch(CancellationToken cancellationToken);
///
/// Changes the . If currently triggers a graceful restart
@@ -66,8 +61,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
///
/// If the restart will be delayed until a reboot is detected in the active server's DMAPI and this function will retrun immediately
/// The for the operation
- /// A resulting in the or if it was already running or is and is
- Task Restart(bool graceful, CancellationToken cancellationToken);
+ /// A representing the running operation
+ Task Restart(bool graceful, CancellationToken cancellationToken);
///
/// Stops the watchdog
diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs
index 9bbe5185ff..308760a9ec 100644
--- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs
+++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs
@@ -36,9 +36,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
///
public Models.CompileJob ActiveCompileJob => (AlphaIsActive ? alphaServer : bravoServer)?.Dmb.CompileJob;
- ///
- public LaunchResult LastLaunchResult { get; private set; }
-
///
public DreamDaemonLaunchParameters ActiveLaunchParameters { get; private set; }
@@ -109,7 +106,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
readonly Api.Models.Instance instance;
///
- /// If the should in
+ /// If the should in
///
readonly bool autoStart;
@@ -570,21 +567,29 @@ namespace Tgstation.Server.Host.Components.Watchdog
for (var retryAttempts = 1; monitorState.NextAction == MonitorAction.Restart; ++retryAttempts)
{
- WatchdogLaunchResult result;
+ Exception launchException = null;
using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false))
- {
- result = await LaunchNoLock(false, false, null, cancellationToken).ConfigureAwait(false);
- if (Running)
+ try
{
- logger.LogDebug("Relaunch successful, resetting monitor state...");
- monitorState = new MonitorState(); //clean the slate
+ await LaunchNoLock(false, false, null, cancellationToken).ConfigureAwait(false);
+ if (Running)
+ {
+ logger.LogDebug("Relaunch successful, resetting monitor state...");
+ monitorState = new MonitorState(); //clean the slate
+ }
+ }
+ catch (Exception e)
+ {
+ launchException = e;
}
- }
await chatTask.ConfigureAwait(false);
if (!Running)
{
- logger.LogWarning("Failed to automatically restart the watchdog! Alpha: {0}; Bravo: {1}", result.Alpha.ToString(), result.Bravo.ToString());
+ if (launchException == null)
+ logger.LogWarning("Failed to automatically restart the watchdog!");
+ else
+ logger.LogWarning("Failed to automatically restart the watchdog! Exception: {0}", launchException);
var retryDelay = Math.Min(Math.Pow(2, retryAttempts), 3600); //max of one hour
chatTask = chat.SendWatchdogMessage(String.Format(CultureInfo.InvariantCulture, "Failed to restart watchdog (Attempt: {0}), retrying in {1} seconds...", retryAttempts, retryDelay), cancellationToken);
await Task.WhenAll(Task.Delay((int)retryDelay, cancellationToken), chatTask).ConfigureAwait(false);
@@ -633,16 +638,13 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
}
- async Task LaunchNoLock(bool startMonitor, bool announce, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken)
+ async Task LaunchNoLock(bool startMonitor, bool announce, WatchdogReattachInformation reattachInfo, CancellationToken cancellationToken)
{
logger.LogTrace("Begin LaunchNoLock");
using (var alphaStartCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
{
if (Running)
- {
- logger.LogTrace("Aborted due to already running!");
- return null;
- }
+ throw new JobException("Watchdog already running!");
Task chatTask;
//this is necessary, the monitor could be in it's sleep loop trying to restart
@@ -716,7 +718,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
//both servers are now running, alpha is the active server(unless reattach), huzzah
AlphaIsActive = reattachInfo?.AlphaIsActive ?? true;
- LastLaunchResult = alphaLrt.Result;
var activeServer = AlphaIsActive ? alphaServer : bravoServer;
activeServer.EnableCustomChatCommands();
@@ -730,11 +731,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
monitorCts = new CancellationTokenSource();
monitorTask = MonitorLifetimes(monitorCts.Token);
}
- return new WatchdogLaunchResult
- {
- Alpha = alphaLrt.Result,
- Bravo = bravoLrt.Result
- };
}
catch
{
@@ -771,10 +767,10 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
///
- public async Task Launch(CancellationToken cancellationToken)
+ public async Task Launch(CancellationToken cancellationToken)
{
using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false))
- return await LaunchNoLock(true, true, null, cancellationToken).ConfigureAwait(false);
+ await LaunchNoLock(true, true, null, cancellationToken).ConfigureAwait(false);
}
///
@@ -791,7 +787,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
///
- public async Task Restart(bool graceful, CancellationToken cancellationToken)
+ public async Task Restart(bool graceful, CancellationToken cancellationToken)
{
logger.LogTrace("Begin Restart. Graceful: {0}", graceful);
using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false))
@@ -806,9 +802,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
else
chatTask = Task.CompletedTask;
- var result = await LaunchNoLock(true, !Running, null, cancellationToken).ConfigureAwait(false);
+ await LaunchNoLock(true, !Running, null, cancellationToken).ConfigureAwait(false);
await chatTask.ConfigureAwait(false);
- return result;
}
var toReboot = AlphaIsActive ? alphaServer : bravoServer;
if (toReboot != null)
@@ -816,7 +811,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
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/Components/Watchdog/WatchdogLaunchResult.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogLaunchResult.cs
deleted file mode 100644
index 0532326e78..0000000000
--- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogLaunchResult.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-
-namespace Tgstation.Server.Host.Components.Watchdog
-{
- ///
- /// Launch results for a
- ///
- public sealed class WatchdogLaunchResult
- {
- ///
- /// The for the alpha process
- ///
- public LaunchResult Alpha { get; set; }
-
- ///
- /// The for the bravo process
- ///
- public LaunchResult Bravo { get; set; }
- }
-}
diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs
index af3bb8cc15..ed43af0cf2 100644
--- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs
+++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs
@@ -66,14 +66,7 @@ namespace Tgstation.Server.Host.Controllers
Instance = Instance,
StartedBy = AuthenticationContext.User
};
- await jobManager.RegisterOperation(job,
- async (paramJob, databaseContext, progressHandler, innerCt) =>
- {
- var result = await instance.Watchdog.Launch(innerCt).ConfigureAwait(false);
- if (result == null)
- throw new JobException("Watchdog already running!");
- },
- cancellationToken).ConfigureAwait(false);
+ await jobManager.RegisterOperation(job, (paramJob, databaseContext, progressHandler, innerCt) => instance.Watchdog.Launch(innerCt), cancellationToken).ConfigureAwait(false);
return Accepted(job.ToApi());
}