diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs
index 664b776be8..29f6b1e1eb 100644
--- a/src/Tgstation.Server.Host/Components/Instance.cs
+++ b/src/Tgstation.Server.Host/Components/Instance.cs
@@ -3,6 +3,7 @@ using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Tgstation.Server.Host.Components.Chat;
using Tgstation.Server.Host.Components.Watchdog;
using Tgstation.Server.Host.Core;
diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs
index b7ee4ce2fd..85e6594d9f 100644
--- a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs
+++ b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdog.cs
@@ -6,6 +6,9 @@ using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Components.Watchdog
{
+ ///
+ /// Runs and monitors the twin server controllers
+ ///
public interface IWatchdog : IHostedService, IDisposable
{
///
diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs
index 1a3f05fcf2..b03163fbc0 100644
--- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs
+++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs
@@ -177,6 +177,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
{
logger.LogInformation("Monitor activation. Reason: {0}", activationReason);
await Task.Yield();
+ throw new NotImplementedException();
}
///
diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs
index 356e52fb9d..18aab9a9fe 100644
--- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs
+++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs
@@ -20,7 +20,7 @@ namespace Tgstation.Server.Host.Controllers
///
/// for managing
///
- [Route("/" + nameof(Api.Models.DreamDaemon))]
+ [Route("/" + nameof(DreamDaemon))]
public sealed class DreamDaemonController : ModelController
{
///
@@ -47,7 +47,7 @@ namespace Tgstation.Server.Host.Controllers
///
[TgsAuthorize(DreamDaemonRights.Start)]
- public override async Task Create([FromBody] Api.Models.DreamDaemon model, CancellationToken cancellationToken)
+ public override async Task Create([FromBody] DreamDaemon model, CancellationToken cancellationToken)
{
var instance = instanceManager.GetInstance(Instance);
@@ -125,7 +125,7 @@ namespace Tgstation.Server.Host.Controllers
}
///
- [TgsAuthorize(DreamDaemonRights.SetAutoStart | DreamDaemonRights.SetPorts | DreamDaemonRights.SetSecurity | DreamDaemonRights.SetWebClient | DreamDaemonRights.SoftRestart | DreamDaemonRights.SoftShutdown | DreamDaemonRights.Start)]
+ [TgsAuthorize(DreamDaemonRights.SetAutoStart | DreamDaemonRights.SetPorts | DreamDaemonRights.SetSecurity | DreamDaemonRights.SetWebClient | DreamDaemonRights.SoftRestart | DreamDaemonRights.SoftShutdown | DreamDaemonRights.Start | DreamDaemonRights.SetStartupTimeout)]
public override async Task Update([FromBody] DreamDaemon model, CancellationToken cancellationToken)
{
var current = await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).Select(x => x.DreamDaemonSettings).FirstAsync(cancellationToken).ConfigureAwait(false);
@@ -147,23 +147,29 @@ namespace Tgstation.Server.Host.Controllers
return false;
};
+ var oldSoftRestart = current.SoftRestart;
+ var oldSoftShutdown = current.SoftShutdown;
+
if (!CheckModified(x => x.AllowWebClient, DreamDaemonRights.SetWebClient)
|| !CheckModified(x => x.AutoStart, DreamDaemonRights.SetAutoStart)
|| !CheckModified(x => x.PrimaryPort, DreamDaemonRights.SetPorts)
|| !CheckModified(x => x.SecondaryPort, DreamDaemonRights.SetPorts)
|| !CheckModified(x => x.SecurityLevel, DreamDaemonRights.SetSecurity)
- || !CheckModified(x => x.SoftRestart, DreamDaemonRights.SoftRestart))
+ || !CheckModified(x => x.SoftRestart, DreamDaemonRights.SoftRestart)
+ || !CheckModified(x => x.SoftShutdown, DreamDaemonRights.SoftShutdown)
+ || !CheckModified(x => x.StartupTimeout, DreamDaemonRights.SetStartupTimeout))
return Forbid();
+
+ var wd = instanceManager.GetInstance(Instance).Watchdog;
+ await wd.ChangeSettings(current, cancellationToken).ConfigureAwait(false);
- //interaction with soft stop is a bit different
- if (model.SoftShutdown.HasValue)
- {
- if (current.SoftShutdown != model.SoftShutdown && ((!current.SoftShutdown.Value && !userRights.HasFlag(DreamDaemonRights.SoftShutdown)) || (current.SoftShutdown.Value && !userRights.HasFlag(DreamDaemonRights.Start))))
- return Forbid();
- current.SoftShutdown = model.SoftShutdown;
- }
+ //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);
- await instanceManager.GetInstance(Instance).Watchdog.ChangeSettings(current, cancellationToken).ConfigureAwait(false);
await DatabaseContext.Save(default).ConfigureAwait(false);
return Ok();