6using System.Threading.Tasks;
8using Microsoft.Extensions.Hosting;
9using Microsoft.Extensions.Logging;
10using Microsoft.Extensions.Options;
36 readonly ILogger<CommandPipeManager>
logger;
53 IOptions<InternalConfiguration> internalConfigurationOptions,
54 ILogger<CommandPipeManager>
logger)
58 internalConfiguration = internalConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(internalConfigurationOptions));
59 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
63 protected override async Task
ExecuteAsync(CancellationToken cancellationToken)
65 logger.LogTrace(
"Starting...");
69 var supportsPipeCommands = !String.IsNullOrWhiteSpace(commandPipe);
70 await
using var commandPipeClient = supportsPipeCommands
71 ?
new AnonymousPipeClientStream(
76 if (!supportsPipeCommands)
77 logger.LogDebug(
"No command pipe name specified in configuration");
80 var supportsReadyNotification = !String.IsNullOrWhiteSpace(readyPipe);
81 if (supportsReadyNotification)
83 await
using var readyPipeClient =
new AnonymousPipeClientStream(
87 logger.LogTrace(
"Waiting to send ready notification...");
90 using var streamWriter =
new StreamWriter(readyPipeClient, Encoding.UTF8, leaveOpen:
true);
94 logger.LogDebug(
"No ready pipe name specified in configuration");
96 if (!supportsPipeCommands)
101 using var streamReader =
new StreamReader(commandPipeClient!, Encoding.UTF8, leaveOpen:
true);
102 while (!cancellationToken.IsCancellationRequested)
104 logger.LogTrace(
"Waiting to read command line...");
105 var line = await streamReader.ReadLineAsync(cancellationToken);
107 logger.LogInformation(
"Received pipe command: {command}", line);
120 logger.LogError(
"Read null from pipe!");
123 logger.LogWarning(
"Unrecognized pipe command: {command}", line);
128 catch (OperationCanceledException ex)
130 logger.LogTrace(ex,
"Command read task cancelled!");
134 logger.LogError(ex,
"Command read task errored!");
138 logger.LogTrace(
"Command read task exiting...");
Values able to be passed via the update file path.
const string CommandDetachingShutdown
Stops the server ASAP, detaching the watchdog for any running instances.
const string CommandStop
Stops the server ASAP, shutting down any running instances.
const string CommandGracefulShutdown
Stops the server eventually, waiting for the games in any running instances to reboot.
const string CommandStartupComplete
Indicates that the host has finished initializing.
Unstable configuration options used internally by TGS.
string? CommandPipe
The name of the pipe opened by the host watchdog for sending commands, if any.
string? ReadyPipe
The name of the pipe opened by the host watchdog for receiving commands, if any.
Reads from the command pipe opened by the host watchdog.
CommandPipeManager(IServerControl serverControl, IInstanceManager instanceManager, IOptions< InternalConfiguration > internalConfigurationOptions, ILogger< CommandPipeManager > logger)
Initializes a new instance of the CommandPipeManager class.
readonly InternalConfiguration internalConfiguration
The InternalConfiguration for the CommandPipeManager.
readonly IInstanceManager instanceManager
The IInstanceManager for the CommandPipeManager.
readonly ILogger< CommandPipeManager > logger
The ILogger for the CommandPipeManager.
override async Task ExecuteAsync(CancellationToken cancellationToken)
readonly IServerControl serverControl
The IServerControl for the CommandPipeManager.
Task Ready
Task that completes when the IInstanceManager finishes initializing.
Represents a service that may take an updated Host assembly and run it, stopping the current assembly...
ValueTask GracefulShutdown(bool detach)
Gracefully shutsdown the Host.
ValueTask Die(Exception? exception)
Kill the server with a fatal exception.