From 9f1f0ffe548dc5a473ed2b5bd021189f208d0799 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 15 Jun 2020 11:34:07 -0400 Subject: [PATCH] Add event for watchdog launches - Fix events triggered by the watchdog not executing their script --- .../Components/Events/EventType.cs | 6 ++++++ .../Components/InstanceFactory.cs | 1 + .../Components/Watchdog/BasicWatchdog.cs | 4 ++++ .../Components/Watchdog/ExperimentalWatchdog.cs | 4 ++++ .../Components/Watchdog/IWatchdogFactory.cs | 3 +++ .../Components/Watchdog/WatchdogBase.cs | 17 +++++++++++++++-- .../Components/Watchdog/WatchdogFactory.cs | 7 +++++++ .../Components/Watchdog/WindowsWatchdog.cs | 4 ++++ .../Watchdog/WindowsWatchdogFactory.cs | 3 +++ 9 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Events/EventType.cs b/src/Tgstation.Server.Host/Components/Events/EventType.cs index 419fb9ec3b..9b648382c9 100644 --- a/src/Tgstation.Server.Host/Components/Events/EventType.cs +++ b/src/Tgstation.Server.Host/Components/Events/EventType.cs @@ -106,5 +106,11 @@ /// [EventScript("WatchdogDetach")] WatchdogDetach, + + /// + /// Before the watchdog launches. No parameters. + /// + [EventScript("WatchdogLaunch")] + WatchdogLaunch } } diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 15876d33cd..cad5c38fa7 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -250,6 +250,7 @@ namespace Tgstation.Server.Host.Components sessionControllerFactory, gameIoManager, diagnosticsIOManager, + eventConsumer, metadata.CloneMetadata(), metadata.DreamDaemonSettings); eventConsumer.SetWatchdog(watchdog); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs index 73d7a74d22..63cdb20557 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Events; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; @@ -51,6 +52,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . + /// The for the . /// The for the . /// The for the . /// The for the . @@ -65,6 +67,7 @@ namespace Tgstation.Server.Host.Components.Watchdog IServerControl serverControl, IAsyncDelayer asyncDelayer, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, ILogger logger, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, @@ -79,6 +82,7 @@ namespace Tgstation.Server.Host.Components.Watchdog serverControl, asyncDelayer, diagnosticsIOManager, + eventConsumer, logger, initialLaunchParameters, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs index 0addffef36..95d2fc12b2 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Events; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; @@ -62,6 +63,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . + /// The for the . /// The for the . /// The for the . /// The for the . @@ -76,6 +78,7 @@ namespace Tgstation.Server.Host.Components.Watchdog IServerControl serverControl, IAsyncDelayer asyncDelayer, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, ILogger logger, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, bool autoStart) @@ -89,6 +92,7 @@ namespace Tgstation.Server.Host.Components.Watchdog serverControl, asyncDelayer, diagnosticsIOManager, + eventConsumer, logger, initialLaunchParameters, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs index 63f30ec362..134628b460 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/IWatchdogFactory.cs @@ -1,6 +1,7 @@ using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Events; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.IO; @@ -20,6 +21,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the /// The pointing to the Game directory for the . /// The pointing to the Diagnostics directory for the . + /// The for the . /// The for the /// The initial for the /// A new @@ -30,6 +32,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ISessionControllerFactory sessionControllerFactory, IIOManager gameIOManager, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, Api.Models.Instance instance, DreamDaemonSettings settings); } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs index d8e6139afa..ee3fe60946 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs @@ -120,6 +120,11 @@ namespace Tgstation.Server.Host.Components.Watchdog /// readonly IIOManager diagnosticsIOManager; + /// + /// The that is not the + /// + readonly IEventConsumer eventConsumer; + /// /// used for . /// @@ -177,6 +182,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The to populate with /// The value of . /// The value of . + /// The value of . /// The value of /// The initial value of . May be modified /// The value of @@ -191,6 +197,7 @@ namespace Tgstation.Server.Host.Components.Watchdog IServerControl serverControl, IAsyncDelayer asyncDelayer, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, ILogger logger, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, @@ -204,6 +211,7 @@ namespace Tgstation.Server.Host.Components.Watchdog this.jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager)); AsyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); this.diagnosticsIOManager = diagnosticsIOManager ?? throw new ArgumentNullException(nameof(diagnosticsIOManager)); + this.eventConsumer = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); ActiveLaunchParameters = initialLaunchParameters ?? throw new ArgumentNullException(nameof(initialLaunchParameters)); this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); @@ -255,7 +263,7 @@ namespace Tgstation.Server.Host.Components.Watchdog return; if (!graceful) { - var eventTask = HandleEvent(releaseServers ? EventType.WatchdogDetach : EventType.WatchdogShutdown, null, cancellationToken); + var eventTask = eventConsumer.HandleEvent(releaseServers ? EventType.WatchdogDetach : EventType.WatchdogShutdown, null, cancellationToken); var chatTask = announce ? Chat.SendWatchdogMessage("Shutting down...", false, cancellationToken) : Task.CompletedTask; @@ -357,7 +365,11 @@ namespace Tgstation.Server.Host.Components.Watchdog if (startMonitor && await StopMonitor().ConfigureAwait(false)) chatTask = Chat.SendWatchdogMessage("Automatic retry sequence cancelled by manual launch. Restarting...", false, cancellationToken); else if (announce) + { chatTask = Chat.SendWatchdogMessage(reattachInfo == null ? "Launching..." : "Reattaching...", false, cancellationToken); // simple announce + if (reattachInfo == null) + await eventConsumer.HandleEvent(EventType.WatchdogLaunch, Enumerable.Empty(), cancellationToken).ConfigureAwait(false); + } else chatTask = Task.CompletedTask; // no announce @@ -751,8 +763,9 @@ namespace Tgstation.Server.Host.Components.Watchdog } /// - public async Task HandleEvent(EventType eventType, IEnumerable parameters, CancellationToken cancellationToken) + async Task IEventConsumer.HandleEvent(EventType eventType, IEnumerable parameters, CancellationToken cancellationToken) { + // Method explicitly implemented to prevent accidental calls when this.eventConsumer should be used. var activeServer = GetActiveController(); // Server may have ended diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs index b7fcaaa3bd..abbe180c96 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs @@ -4,6 +4,7 @@ using System; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Events; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; @@ -79,6 +80,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ISessionControllerFactory sessionControllerFactory, IIOManager gameIOManager, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, Api.Models.Instance instance, DreamDaemonSettings settings) { @@ -93,6 +95,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ServerControl, AsyncDelayer, diagnosticsIOManager, + eventConsumer, LoggerFactory.CreateLogger(), settings, instance, @@ -105,6 +108,7 @@ namespace Tgstation.Server.Host.Components.Watchdog sessionControllerFactory, gameIOManager, diagnosticsIOManager, + eventConsumer, instance, settings); } @@ -118,6 +122,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the /// The pointing to the Game directory for the . /// The pointing to the Diagnostics directory for the . + /// The for the . /// The for the /// The initial for the /// A new @@ -128,6 +133,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ISessionControllerFactory sessionControllerFactory, IIOManager gameIOManager, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, Api.Models.Instance instance, DreamDaemonSettings settings) => new BasicWatchdog( @@ -140,6 +146,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ServerControl, AsyncDelayer, diagnosticsIOManager, + eventConsumer, LoggerFactory.CreateLogger(), settings, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs index 206995886c..aa59fc3d35 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Events; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; @@ -55,6 +56,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . + /// The for the . /// The value of . /// The value of . /// The for the . @@ -71,6 +73,7 @@ namespace Tgstation.Server.Host.Components.Watchdog IServerControl serverControl, IAsyncDelayer asyncDelayer, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, IIOManager gameIOManager, ISymlinkFactory symlinkFactory, ILogger logger, @@ -86,6 +89,7 @@ namespace Tgstation.Server.Host.Components.Watchdog serverControl, asyncDelayer, diagnosticsIOManager, + eventConsumer, logger, initialLaunchParameters, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs index d8c4314280..f1f23e22f6 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs @@ -4,6 +4,7 @@ using System; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Deployment; +using Tgstation.Server.Host.Components.Events; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; @@ -60,6 +61,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ISessionControllerFactory sessionControllerFactory, IIOManager gameIOManager, IIOManager diagnosticsIOManager, + IEventConsumer eventConsumer, Api.Models.Instance instance, DreamDaemonSettings settings) => new WindowsWatchdog( @@ -72,6 +74,7 @@ namespace Tgstation.Server.Host.Components.Watchdog ServerControl, AsyncDelayer, diagnosticsIOManager, + eventConsumer, gameIOManager, symlinkFactory, LoggerFactory.CreateLogger(),