Merge pull request #1192 from tgstation/aa/reboot-event-script

[READY] Adds an event script for triggering events when DD is ended with TgsEndProcess()
This commit is contained in:
Jordan Brown
2021-01-10 14:59:38 -05:00
committed by GitHub
5 changed files with 24 additions and 12 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
<TgsConfigVersion>2.2.0</TgsConfigVersion>
<TgsApiVersion>8.2.0</TgsApiVersion>
<TgsClientVersion>9.1.1</TgsClientVersion>
<TgsDmapiVersion>5.2.10</TgsDmapiVersion>
<TgsDmapiVersion>5.2.11</TgsDmapiVersion>
<TgsHostWatchdogVersion>1.1.0</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.0</TgsContainerScriptVersion>
</PropertyGroup>
+3 -1
View File
@@ -1,6 +1,6 @@
// tgstation-server DMAPI
#define TGS_DMAPI_VERSION "5.2.10"
#define TGS_DMAPI_VERSION "5.2.11"
// All functions and datums outside this document are subject to change with any version and should not be relied on.
@@ -97,6 +97,8 @@
#define TGS_EVENT_WATCHDOG_DETACH 16
// We don't actually implement this value as the DMAPI can never receive it
// #define TGS_EVENT_WATCHDOG_LAUNCH 17
// Same here. We don't actually implement this value as the DMAPI can never receive it
// #define TGS_EVENT_WORLD_END_PROCESS 18
// OTHER ENUMS
@@ -111,6 +111,12 @@ namespace Tgstation.Server.Host.Components.Events
/// Before the watchdog launches. No parameters.
/// </summary>
[EventScript("WatchdogLaunch")]
WatchdogLaunch
WatchdogLaunch,
/// <summary>
/// In between DD restarts if the process has been force-ended by the DMAPI (TgsEndProcess())
/// </summary>
[EventScript("WorldEndProcess")]
WorldEndProcess,
}
}
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models.Internal;
@@ -91,6 +92,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
switch (reason)
{
case MonitorActivationReason.ActiveServerCrashed:
if (Server.TerminationWasRequested)
await EventConsumer.HandleEvent(EventType.WorldEndProcess, Enumerable.Empty<string>(), cancellationToken).ConfigureAwait(false);
string exitWord = Server.TerminationWasRequested ? "exited" : "crashed";
if (Server.RebootState == Session.RebootState.Shutdown)
{
@@ -83,6 +83,11 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// </summary>
protected IAsyncDelayer AsyncDelayer { get; }
/// <summary>
/// The <see cref="IEventConsumer"/> that is not the <see cref="WatchdogBase"/>
/// </summary>
protected IEventConsumer EventConsumer { get; }
/// <summary>
/// The <see cref="Api.Models.Instance"/> for the <see cref="WatchdogBase"/>.
/// </summary>
@@ -118,11 +123,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// </summary>
readonly IIOManager diagnosticsIOManager;
/// <summary>
/// The <see cref="IEventConsumer"/> that is not the <see cref="WatchdogBase"/>
/// </summary>
readonly IEventConsumer eventConsumer;
/// <summary>
/// The <see cref="IRemoteDeploymentManagerFactory"/> for the <see cref="WatchdogBase"/>.
/// </summary>
@@ -179,7 +179,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="serverControl">The <see cref="IServerControl"/> to populate <see cref="restartRegistration"/> with</param>
/// <param name="asyncDelayer">The value of <see cref="AsyncDelayer"/>.</param>
/// <param name="diagnosticsIOManager">The value of <see cref="diagnosticsIOManager"/>.</param>
/// <param name="eventConsumer">The value of <see cref="eventConsumer"/>.</param>
/// <param name="eventConsumer">The value of <see cref="EventConsumer"/>.</param>
/// <param name="remoteDeploymentManagerFactory">The value of <see cref="remoteDeploymentManagerFactory"/>.</param>
/// <param name="logger">The value of <see cref="Logger"/></param>
/// <param name="initialLaunchParameters">The initial value of <see cref="ActiveLaunchParameters"/>. May be modified</param>
@@ -208,7 +208,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));
EventConsumer = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer));
this.remoteDeploymentManagerFactory = remoteDeploymentManagerFactory ?? throw new ArgumentNullException(nameof(remoteDeploymentManagerFactory));
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
ActiveLaunchParameters = initialLaunchParameters ?? throw new ArgumentNullException(nameof(initialLaunchParameters));
@@ -267,7 +267,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
return;
if (!graceful)
{
var eventTask = eventConsumer.HandleEvent(releaseServers ? EventType.WatchdogDetach : EventType.WatchdogShutdown, null, cancellationToken);
var eventTask = EventConsumer.HandleEvent(releaseServers ? EventType.WatchdogDetach : EventType.WatchdogShutdown, null, cancellationToken);
var chatTask = announce ? Chat.QueueWatchdogMessage("Shutting down...", cancellationToken) : Task.CompletedTask;
@@ -378,7 +378,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
cancellationToken); // simple announce
if (reattachInfo == null)
announceTask = Task.WhenAll(
eventConsumer.HandleEvent(EventType.WatchdogLaunch, Enumerable.Empty<string>(), cancellationToken),
EventConsumer.HandleEvent(EventType.WatchdogLaunch, Enumerable.Empty<string>(), cancellationToken),
announceTask);
}
else