tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Tgstation.Server.Host.Server Class Referencesealed

More...

Inheritance diagram for Tgstation.Server.Host.Server:
Inheritance graph
[legend]
Collaboration diagram for Tgstation.Server.Host.Server:
Collaboration graph
[legend]

Public Member Functions

 Server (IIOManager ioManager, IHostBuilder hostBuilder, string? updatePath)
 Initializes a new instance of the Server class.
 
async ValueTask Run (CancellationToken cancellationToken)
 Runs the IServer.
Parameters
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
bool TryStartUpdate (IServerUpdateExecutor updateExecutor, Version newVersion)
 Attempt to update with a given updateExecutor .
Parameters
updateExecutorThe IServerUpdateExecutor to use for the update.
newVersionThe Version the IServerControl is updating to.
Returns
true if the update started successfully, false if there was another update in progress.

 
IRestartRegistration RegisterForRestart (IRestartHandler handler)
 Register a given handler to run before stopping the server for a restart.
Parameters
handlerThe IRestartHandler to register.
Returns
A new IRestartRegistration representing the scope of the registration.

 
ValueTask Restart ()
 Restarts the Host.
Returns
A ValueTask representing the running operation.

 
ValueTask GracefulShutdown (bool detach)
 Gracefully shutsdown the Host.
Parameters
detachIf the graceful shutdown should detach any running watchdog. If false the server will wait for the next TgsReboot() or world exit before shutting down.
Returns
A ValueTask representing the running operation.

 
ValueTask Die (Exception? exception)
 Kill the server with a fatal exception.
Parameters
exceptionThe Exception to propagate to the watchdog if any.
Returns
A Task representing the running operation.

 

Properties

bool RestartRequested [get, private set]
 If the IServer should restart.
 
bool UpdateInProgress [get, private set]
 Whether or not the server is currently updating.
 
bool WatchdogPresent [get]
 true if live updates are supported, false. TryStartUpdate(IServerUpdateExecutor, Version) and Restart will fail if this is false.
 
- Properties inherited from Tgstation.Server.Host.IServer
- Properties inherited from Tgstation.Server.Host.Core.IServerControl

Private Member Functions

async ValueTask< bool > DumpGraphQLSchemaIfRequested (IServiceProvider services, CancellationToken cancellationToken)
 Checks if InternalConfiguration.DumpGraphQLApiPath is set and dumps the GraphQL API Schema to it if so.
 
void CheckSanity (bool checkWatchdog)
 Throws an InvalidOperationException if the IServerControl cannot be used.
 
void CheckExceptionPropagation (Exception? otherException)
 Re-throw propagatedException if it exists.
 
async ValueTask RestartImpl (Version? newVersion, Exception? exception, bool requireWatchdog, bool completeAsap)
 Implements Restart().
 
async void WatchForShutdownFileCreation (object sender, FileSystemEventArgs eventArgs)
 Event handler for the updatePath's FileSystemWatcher. Triggers shutdown if requested by host watchdog.
 
void StopServerImmediate ()
 Fires off the cancellationTokenSource without any checks, shutting down everything.
 

Private Attributes

readonly IIOManager ioManager
 The IIOManager to use.
 
readonly IHostBuilder hostBuilder
 The IHostBuilder for the Server.
 
readonly List< IRestartHandlerrestartHandlers
 The IRestartHandlers to run when the Server restarts.
 
readonly? string updatePath
 The absolute path to install updates to.
 
readonly object restartLock
 lock object for certain restart related operations.
 
IOptionsMonitor< GeneralConfiguration >? generalConfigurationOptions
 The IOptionsMonitor<TOptions> of GeneralConfiguration for the Server.
 
ILogger< Server >? logger
 The ILogger for the Server.
 
CancellationTokenSource? cancellationTokenSource
 The cancellationTokenSource for the Server.
 
ExceptionpropagatedException
 The Exception to propagate when the server terminates.
 
Task? updateTask
 The Task that is used for asynchronously updating the server.
 
bool shutdownInProgress
 If the server is being shut down or restarted.
 
bool terminateIfUpdateFails
 If there is an update in progress and this flag is set, it should stop the server immediately if it fails.
 

Detailed Description

Definition at line 25 of file Server.cs.

Constructor & Destructor Documentation

◆ Server()

Tgstation.Server.Host.Server.Server ( IIOManager  ioManager,
IHostBuilder  hostBuilder,
string?  updatePath 
)

Initializes a new instance of the Server class.

Parameters
ioManagerThe value of ioManager.
hostBuilderThe value of hostBuilder.
updatePathThe value of updatePath.

Definition at line 112 of file Server.cs.

113 {
114 this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
115 this.hostBuilder = hostBuilder ?? throw new ArgumentNullException(nameof(hostBuilder));
116 this.updatePath = updatePath;
117
118 hostBuilder.ConfigureServices(serviceCollection => serviceCollection.AddSingleton<IServerControl>(this));
119
120 restartHandlers = new List<IRestartHandler>();
121 restartLock = new object();
122 logger = null;
123 }
readonly List< IRestartHandler > restartHandlers
The IRestartHandlers to run when the Server restarts.
Definition Server.cs:59
readonly IIOManager ioManager
The IIOManager to use.
Definition Server.cs:49
readonly? string updatePath
The absolute path to install updates to.
Definition Server.cs:64
ILogger< Server >? logger
The ILogger for the Server.
Definition Server.cs:79
readonly IHostBuilder hostBuilder
The IHostBuilder for the Server.
Definition Server.cs:54
readonly object restartLock
lock object for certain restart related operations.
Definition Server.cs:69
Represents a service that may take an updated Host assembly and run it, stopping the current assembly...

References Tgstation.Server.Host.Server.hostBuilder, Tgstation.Server.Host.Server.ioManager, Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.Server.restartHandlers, Tgstation.Server.Host.Server.restartLock, and Tgstation.Server.Host.Server.updatePath.

Member Function Documentation

◆ CheckExceptionPropagation()

void Tgstation.Server.Host.Server.CheckExceptionPropagation ( Exception otherException)
private

Re-throw propagatedException if it exists.

Parameters
otherExceptionAn existing Exception that should be thrown as well, but not by itself.

Definition at line 338 of file Server.cs.

339 {
340 if (propagatedException == null)
341 return;
342
343 if (otherException != null)
344 throw new AggregateException(propagatedException, otherException);
345
347 }
Exception? propagatedException
The Exception to propagate when the server terminates.
Definition Server.cs:89

References Tgstation.Server.Host.Server.propagatedException.

Referenced by Tgstation.Server.Host.Server.Run().

Here is the caller graph for this function:

◆ CheckSanity()

void Tgstation.Server.Host.Server.CheckSanity ( bool  checkWatchdog)
private

Throws an InvalidOperationException if the IServerControl cannot be used.

Parameters
checkWatchdogIf WatchdogPresent should be checked.

Definition at line 325 of file Server.cs.

326 {
327 if (checkWatchdog && !WatchdogPresent && propagatedException == null)
328 throw new InvalidOperationException("Server restarts are not supported");
329
330 if (cancellationTokenSource == null || logger == null)
331 throw new InvalidOperationException("Tried to control a non-running Server!");
332 }
bool WatchdogPresent
true if live updates are supported, false. TryStartUpdate(IServerUpdateExecutor, Version) and Restart...
Definition Server.cs:34
CancellationTokenSource? cancellationTokenSource
The cancellationTokenSource for the Server.
Definition Server.cs:84

References Tgstation.Server.Host.Server.cancellationTokenSource, Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.Server.propagatedException, and Tgstation.Server.Host.Server.WatchdogPresent.

Referenced by Tgstation.Server.Host.Server.RegisterForRestart(), Tgstation.Server.Host.Server.RestartImpl(), and Tgstation.Server.Host.Server.TryStartUpdate().

Here is the caller graph for this function:

◆ Die()

ValueTask Tgstation.Server.Host.Server.Die ( Exception exception)

Kill the server with a fatal exception.

Parameters
exceptionThe Exception to propagate to the watchdog if any.
Returns
A Task representing the running operation.

Implements Tgstation.Server.Host.Core.IServerControl.

Definition at line 287 of file Server.cs.

288 {
289 if (exception != null)
290 return RestartImpl(null, exception, false, true);
291
293 return ValueTask.CompletedTask;
294 }
async ValueTask RestartImpl(Version? newVersion, Exception? exception, bool requireWatchdog, bool completeAsap)
Implements Restart().
Definition Server.cs:357
void StopServerImmediate()
Fires off the cancellationTokenSource without any checks, shutting down everything.
Definition Server.cs:456

References Tgstation.Server.Host.Server.RestartImpl(), and Tgstation.Server.Host.Server.StopServerImmediate().

Here is the call graph for this function:

◆ DumpGraphQLSchemaIfRequested()

async ValueTask< bool > Tgstation.Server.Host.Server.DumpGraphQLSchemaIfRequested ( IServiceProvider  services,
CancellationToken  cancellationToken 
)
private

Checks if InternalConfiguration.DumpGraphQLApiPath is set and dumps the GraphQL API Schema to it if so.

Parameters
servicesThe IServiceProvider to resolve services from.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in true if the GraphQL API was dumped, false otherwise.

Definition at line 302 of file Server.cs.

303 {
304 var internalConfigurationOptions = services.GetRequiredService<IOptions<InternalConfiguration>>();
305 var apiDumpPath = internalConfigurationOptions.Value.DumpGraphQLApiPath;
306 if (String.IsNullOrWhiteSpace(apiDumpPath))
307 return false;
308
309 logger!.LogInformation("Dumping GraphQL API spec to {path} and exiting...", apiDumpPath);
310
311 // https://github.com/ChilliCream/graphql-platform/discussions/5885
312 var resolver = services.GetRequiredService<IRequestExecutorResolver>();
313 var executor = await resolver.GetRequestExecutorAsync(cancellationToken: cancellationToken);
314 var sdl = executor.Schema.Print();
315
316 var ioManager = services.GetRequiredService<IIOManager>();
317 await ioManager.WriteAllBytes(apiDumpPath, Encoding.UTF8.GetBytes(sdl), cancellationToken);
318 return true;
319 }
Interface for using filesystems.
Definition IIOManager.cs:14
ValueTask WriteAllBytes(string path, byte[] contents, CancellationToken cancellationToken)
Writes some contents to a file at path overwriting previous content.

References Tgstation.Server.Host.Server.ioManager, Tgstation.Server.Host.Server.logger, and Tgstation.Server.Host.IO.IIOManager.WriteAllBytes().

Referenced by Tgstation.Server.Host.Server.Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GracefulShutdown()

ValueTask Tgstation.Server.Host.Server.GracefulShutdown ( bool  detach)

Gracefully shutsdown the Host.

Parameters
detachIf the graceful shutdown should detach any running watchdog. If false the server will wait for the next TgsReboot() or world exit before shutting down.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Host.Core.IServerControl.

◆ RegisterForRestart()

IRestartRegistration Tgstation.Server.Host.Server.RegisterForRestart ( IRestartHandler  handler)

Register a given handler to run before stopping the server for a restart.

Parameters
handlerThe IRestartHandler to register.
Returns
A new IRestartRegistration representing the scope of the registration.

Implements Tgstation.Server.Host.Core.IServerControl.

Definition at line 255 of file Server.cs.

256 {
257 ArgumentNullException.ThrowIfNull(handler);
258
259 CheckSanity(false);
260
261 var logger = this.logger!;
262 lock (restartLock)
264 {
265 logger.LogTrace("Registering restart handler {handlerImplementationName}...", handler);
266 restartHandlers.Add(handler);
267 return new RestartRegistration(
268 new DisposeInvoker(() =>
269 {
270 lock (restartLock)
272 restartHandlers.Remove(handler);
273 }));
274 }
275
276 logger.LogWarning("Restart handler {handlerImplementationName} register after a shutdown had begun!", handler);
277 return new RestartRegistration(null);
278 }
void CheckSanity(bool checkWatchdog)
Throws an InvalidOperationException if the IServerControl cannot be used.
Definition Server.cs:325
bool shutdownInProgress
If the server is being shut down or restarted.
Definition Server.cs:99
Runs a given disposeAction on Dispose.

References Tgstation.Server.Host.Server.CheckSanity(), Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.Server.restartHandlers, Tgstation.Server.Host.Server.restartLock, and Tgstation.Server.Host.Server.shutdownInProgress.

Here is the call graph for this function:

◆ Restart()

ValueTask Tgstation.Server.Host.Server.Restart ( )

Restarts the Host.

Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Host.Core.IServerControl.

Referenced by Tgstation.Server.Host.Components.Watchdog.AdvancedWatchdog.HandleNormalReboot().

Here is the caller graph for this function:

◆ RestartImpl()

async ValueTask Tgstation.Server.Host.Server.RestartImpl ( Version?  newVersion,
Exception exception,
bool  requireWatchdog,
bool  completeAsap 
)
private

Implements Restart().

Parameters
newVersionThe Version of any potential updates being applied.
exceptionThe potential value of propagatedException.
requireWatchdogIf the host watchdog is required for this "restart".
completeAsapIf the restart should wait for extremely long running tasks to complete (Like the current DreamDaemon world).
Returns
A ValueTask representing the running operation.

Definition at line 357 of file Server.cs.

358 {
359 CheckSanity(requireWatchdog);
360
361 // if the watchdog isn't required and there's no issue, this is just a graceful shutdown
362 bool isGracefulShutdown = !requireWatchdog && exception == null;
363 var logger = this.logger!;
364 logger.LogTrace(
365 "Begin {restartType}...",
366 isGracefulShutdown
367 ? completeAsap
368 ? "semi-graceful shutdown"
369 : "graceful shutdown"
370 : "restart");
371
372 lock (restartLock)
373 {
374 if ((UpdateInProgress && newVersion == null) || shutdownInProgress)
375 {
376 logger.LogTrace("Aborted restart due to concurrency conflict!");
377 return;
378 }
379
380 RestartRequested = !isGracefulShutdown;
381 propagatedException ??= exception;
382 }
383
384 if (exception == null)
385 {
386 var giveHandlersTimeToWaitAround = isGracefulShutdown && !completeAsap;
387 logger.LogInformation("Stopping server...");
388 using var cts = new CancellationTokenSource(
389 TimeSpan.FromMinutes(
390 giveHandlersTimeToWaitAround
391 ? generalConfigurationOptions!.CurrentValue.ShutdownTimeoutMinutes
392 : generalConfigurationOptions!.CurrentValue.RestartTimeoutMinutes));
393 var cancellationToken = cts.Token;
394 try
395 {
396 ValueTask eventsTask;
397 lock (restartLock)
398 eventsTask = ValueTaskExtensions.WhenAll(
400 .Select(
401 x => x.HandleRestart(newVersion, giveHandlersTimeToWaitAround, cancellationToken))
402 .ToList());
403
404 logger.LogTrace("Joining restart handlers...");
405 await eventsTask;
406 }
407 catch (OperationCanceledException ex)
408 {
409 if (isGracefulShutdown)
410 logger.LogWarning(ex, "Graceful shutdown timeout hit! Existing DreamDaemon processes will be terminated!");
411 else
412 logger.LogError(
413 ex,
414 "Restart timeout hit! Existing DreamDaemon processes will be lost and must be killed manually before being restarted with TGS!");
415 }
416 catch (Exception e)
417 {
418 logger.LogError(e, "Restart handlers error!");
419 }
420 }
421
423 }
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
bool UpdateInProgress
Whether or not the server is currently updating.
Definition Server.cs:31
IOptionsMonitor< GeneralConfiguration >? generalConfigurationOptions
The IOptionsMonitor<TOptions> of GeneralConfiguration for the Server.
Definition Server.cs:74
bool RestartRequested
If the IServer should restart.
Definition Server.cs:28

References Tgstation.Server.Host.Server.CheckSanity(), Tgstation.Server.Host.Server.generalConfigurationOptions, Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.Server.propagatedException, Tgstation.Server.Host.Server.restartHandlers, Tgstation.Server.Host.Server.restartLock, Tgstation.Server.Host.Server.RestartRequested, Tgstation.Server.Host.Server.shutdownInProgress, Tgstation.Server.Host.Server.StopServerImmediate(), Tgstation.Server.Host.Server.UpdateInProgress, and Tgstation.Server.Common.Extensions.ValueTaskExtensions.WhenAll().

Referenced by Tgstation.Server.Host.Server.Die(), and Tgstation.Server.Host.Server.TryStartUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Run()

async ValueTask Tgstation.Server.Host.Server.Run ( CancellationToken  cancellationToken)

Runs the IServer.

Parameters
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Host.IServer.

Definition at line 126 of file Server.cs.

127 {
128 var updateDirectory = updatePath != null ? ioManager.GetDirectoryName(updatePath) : null;
129 using (cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
130 using (var fsWatcher = updateDirectory != null ? new FileSystemWatcher(updateDirectory) : null)
131 {
132 if (fsWatcher != null)
133 {
134 // If ever there is a NECESSARY update to the Host Watchdog, change this to use a pipe
135 // I don't know why I'm only realizing this in 2023 when this is 2019 code
136 // As it stands, FSWatchers use async I/O on Windows and block a new thread on Linux
137 // That's an acceptable, if saddening, resource loss for now
138 fsWatcher.Created += WatchForShutdownFileCreation;
139 fsWatcher.EnableRaisingEvents = true;
140 }
141
142 try
143 {
144 using (Host = hostBuilder.Build())
145 {
146 logger = Host.Services.GetRequiredService<ILogger<Server>>();
147 try
148 {
149 using (cancellationToken.Register(() => logger.LogInformation("Server termination requested!")))
150 {
151 if (await DumpGraphQLSchemaIfRequested(Host.Services, cancellationToken))
152 return;
153
154 generalConfigurationOptions = Host.Services.GetRequiredService<IOptionsMonitor<GeneralConfiguration>>();
155 await Host.RunAsync(cancellationTokenSource.Token);
156 }
157
158 if (updateTask != null)
159 await updateTask;
160 }
161 catch (OperationCanceledException ex)
162 {
163 logger.LogDebug(ex, "Server run cancelled!");
164 }
165 catch (Exception ex)
166 {
168 throw;
169 }
170 finally
171 {
172 logger = null;
173 }
174 }
175 }
176 finally
177 {
178 Host = null;
179 }
180 }
181
183 }
Task? updateTask
The Task that is used for asynchronously updating the server.
Definition Server.cs:94
async void WatchForShutdownFileCreation(object sender, FileSystemEventArgs eventArgs)
Event handler for the updatePath's FileSystemWatcher. Triggers shutdown if requested by host watchdog...
Definition Server.cs:430
async ValueTask< bool > DumpGraphQLSchemaIfRequested(IServiceProvider services, CancellationToken cancellationToken)
Checks if InternalConfiguration.DumpGraphQLApiPath is set and dumps the GraphQL API Schema to it if s...
Definition Server.cs:302
void CheckExceptionPropagation(Exception? otherException)
Re-throw propagatedException if it exists.
Definition Server.cs:338
string GetDirectoryName(string path)
Gets the directory portion of a given path .

References Tgstation.Server.Host.Server.cancellationTokenSource, Tgstation.Server.Host.Server.CheckExceptionPropagation(), Tgstation.Server.Host.Server.DumpGraphQLSchemaIfRequested(), Tgstation.Server.Host.Server.generalConfigurationOptions, Tgstation.Server.Host.IO.IIOManager.GetDirectoryName(), Tgstation.Server.Host.Server.hostBuilder, Tgstation.Server.Host.Server.ioManager, Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.Server.updatePath, Tgstation.Server.Host.Server.updateTask, and Tgstation.Server.Host.Server.WatchForShutdownFileCreation().

Here is the call graph for this function:

◆ StopServerImmediate()

void Tgstation.Server.Host.Server.StopServerImmediate ( )
private

Fires off the cancellationTokenSource without any checks, shutting down everything.

Definition at line 456 of file Server.cs.

457 {
458 shutdownInProgress = true;
459 logger!.LogDebug("Stopping host...");
460 cancellationTokenSource!.Cancel();
461 }

References Tgstation.Server.Host.Server.cancellationTokenSource, Tgstation.Server.Host.Server.logger, and Tgstation.Server.Host.Server.shutdownInProgress.

Referenced by Tgstation.Server.Host.Server.Die(), Tgstation.Server.Host.Server.RestartImpl(), and Tgstation.Server.Host.Server.WatchForShutdownFileCreation().

Here is the caller graph for this function:

◆ TryStartUpdate()

bool Tgstation.Server.Host.Server.TryStartUpdate ( IServerUpdateExecutor  updateExecutor,
Version  newVersion 
)

Attempt to update with a given updateExecutor .

Parameters
updateExecutorThe IServerUpdateExecutor to use for the update.
newVersionThe Version the IServerControl is updating to.
Returns
true if the update started successfully, false if there was another update in progress.

Implements Tgstation.Server.Host.Core.IServerControl.

Definition at line 186 of file Server.cs.

187 {
188 ArgumentNullException.ThrowIfNull(updateExecutor);
189 ArgumentNullException.ThrowIfNull(newVersion);
190
191 CheckSanity(true);
192
193 if (updatePath == null)
194 throw new InvalidOperationException("Tried to start update when server was initialized without an updatePath set!");
195
196 var logger = this.logger!;
197 logger.LogTrace("Begin ApplyUpdate...");
198
199 CancellationToken criticalCancellationToken;
200 lock (restartLock)
201 {
203 {
204 logger.LogDebug("Aborted update due to concurrency conflict!");
205 return false;
206 }
207
208 if (cancellationTokenSource == null)
209 throw new InvalidOperationException("Tried to update a non-running Server!");
210
211 criticalCancellationToken = cancellationTokenSource.Token;
212 UpdateInProgress = true;
213 }
214
215 async Task RunUpdate()
216 {
217 var updateExecutedSuccessfully = false;
218 try
219 {
220 updateExecutedSuccessfully = await updateExecutor.ExecuteUpdate(updatePath, criticalCancellationToken, criticalCancellationToken);
221 }
222 catch (OperationCanceledException ex)
223 {
224 logger.LogDebug(ex, "Update cancelled!");
225 UpdateInProgress = false;
226 }
227 catch (Exception ex)
228 {
229 logger.LogError(ex, "Update errored!");
230 UpdateInProgress = false;
231 }
232
233 if (updateExecutedSuccessfully)
234 {
235 logger.LogTrace("Update complete!");
236 await RestartImpl(newVersion, null, true, true);
237 }
238 else if (terminateIfUpdateFails)
239 {
240 logger.LogTrace("Stopping host due to termination request...");
242 }
243 else
244 {
245 logger.LogTrace("Update failed!");
246 UpdateInProgress = false;
247 }
248 }
249
250 updateTask = RunUpdate();
251 return true;
252 }
bool terminateIfUpdateFails
If there is an update in progress and this flag is set, it should stop the server immediately if it f...
Definition Server.cs:104
ValueTask< bool > ExecuteUpdate(string updatePath, CancellationToken cancellationToken, CancellationToken criticalCancellationToken)
Executes a pending server update by extracting the new server to a given updatePath .

References Tgstation.Server.Host.Server.cancellationTokenSource, Tgstation.Server.Host.Server.CheckSanity(), Tgstation.Server.Host.Core.IServerUpdateExecutor.ExecuteUpdate(), Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.Server.RestartImpl(), Tgstation.Server.Host.Server.restartLock, Tgstation.Server.Host.Server.shutdownInProgress, Tgstation.Server.Host.Server.terminateIfUpdateFails, Tgstation.Server.Host.Server.UpdateInProgress, Tgstation.Server.Host.Server.updatePath, and Tgstation.Server.Host.Server.updateTask.

Here is the call graph for this function:

◆ WatchForShutdownFileCreation()

async void Tgstation.Server.Host.Server.WatchForShutdownFileCreation ( object  sender,
FileSystemEventArgs  eventArgs 
)
private

Event handler for the updatePath's FileSystemWatcher. Triggers shutdown if requested by host watchdog.

Parameters
senderThe object that sent the event.
eventArgsThe FileSystemEventArgs.

Definition at line 430 of file Server.cs.

431 {
432 logger?.LogTrace("FileSystemWatcher triggered.");
433
434 // DCT: None available
435 if (eventArgs.FullPath == ioManager.ResolvePath(updatePath!) && await ioManager.FileExists(eventArgs.FullPath, CancellationToken.None))
436 {
437 logger?.LogInformation("Host watchdog appears to be requesting server termination!");
438 lock (restartLock)
439 {
440 if (!UpdateInProgress)
441 {
443 return;
444 }
445
447 }
448
449 logger?.LogInformation("An update is in progress, we will wait for that to complete...");
450 }
451 }
string ResolvePath()
Retrieve the full path of the current working directory.
Task< bool > FileExists(string path, CancellationToken cancellationToken)
Check that the file at path exists.

References Tgstation.Server.Host.IO.IIOManager.FileExists(), Tgstation.Server.Host.Server.ioManager, Tgstation.Server.Host.Server.logger, Tgstation.Server.Host.IO.IIOManager.ResolvePath(), Tgstation.Server.Host.Server.restartLock, Tgstation.Server.Host.Server.StopServerImmediate(), Tgstation.Server.Host.Server.terminateIfUpdateFails, Tgstation.Server.Host.Server.UpdateInProgress, and Tgstation.Server.Host.Server.updatePath.

Referenced by Tgstation.Server.Host.Server.Run().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cancellationTokenSource

CancellationTokenSource? Tgstation.Server.Host.Server.cancellationTokenSource
private

◆ generalConfigurationOptions

IOptionsMonitor<GeneralConfiguration>? Tgstation.Server.Host.Server.generalConfigurationOptions
private

The IOptionsMonitor<TOptions> of GeneralConfiguration for the Server.

Definition at line 74 of file Server.cs.

Referenced by Tgstation.Server.Host.Server.RestartImpl(), and Tgstation.Server.Host.Server.Run().

◆ hostBuilder

readonly IHostBuilder Tgstation.Server.Host.Server.hostBuilder
private

The IHostBuilder for the Server.

Definition at line 54 of file Server.cs.

Referenced by Tgstation.Server.Host.Server.Run(), and Tgstation.Server.Host.Server.Server().

◆ ioManager

readonly IIOManager Tgstation.Server.Host.Server.ioManager
private

◆ logger

ILogger<Server>? Tgstation.Server.Host.Server.logger
private

◆ propagatedException

Exception? Tgstation.Server.Host.Server.propagatedException
private

◆ restartHandlers

readonly List<IRestartHandler> Tgstation.Server.Host.Server.restartHandlers
private

The IRestartHandlers to run when the Server restarts.

Definition at line 59 of file Server.cs.

Referenced by Tgstation.Server.Host.Server.RegisterForRestart(), Tgstation.Server.Host.Server.RestartImpl(), and Tgstation.Server.Host.Server.Server().

◆ restartLock

readonly object Tgstation.Server.Host.Server.restartLock
private

◆ shutdownInProgress

bool Tgstation.Server.Host.Server.shutdownInProgress
private

◆ terminateIfUpdateFails

bool Tgstation.Server.Host.Server.terminateIfUpdateFails
private

If there is an update in progress and this flag is set, it should stop the server immediately if it fails.

Definition at line 104 of file Server.cs.

Referenced by Tgstation.Server.Host.Server.TryStartUpdate(), and Tgstation.Server.Host.Server.WatchForShutdownFileCreation().

◆ updatePath

readonly? string Tgstation.Server.Host.Server.updatePath
private

◆ updateTask

Task? Tgstation.Server.Host.Server.updateTask
private

The Task that is used for asynchronously updating the server.

Definition at line 94 of file Server.cs.

Referenced by Tgstation.Server.Host.Server.Run(), and Tgstation.Server.Host.Server.TryStartUpdate().

Property Documentation

◆ RestartRequested

bool Tgstation.Server.Host.Server.RestartRequested
getprivate set

If the IServer should restart.

Implements Tgstation.Server.Host.IServer.

Definition at line 28 of file Server.cs.

28{ get; private set; }

Referenced by Tgstation.Server.Host.Server.RestartImpl().

◆ UpdateInProgress

bool Tgstation.Server.Host.Server.UpdateInProgress
getprivate set

Whether or not the server is currently updating.

Implements Tgstation.Server.Host.Core.IServerControl.

Definition at line 31 of file Server.cs.

31{ get; private set; }

Referenced by Tgstation.Server.Host.Server.RestartImpl(), Tgstation.Server.Host.Server.TryStartUpdate(), and Tgstation.Server.Host.Server.WatchForShutdownFileCreation().

◆ WatchdogPresent

bool Tgstation.Server.Host.Server.WatchdogPresent
get

true if live updates are supported, false. TryStartUpdate(IServerUpdateExecutor, Version) and Restart will fail if this is false.

Implements Tgstation.Server.Host.Core.IServerControl.

Definition at line 34 of file Server.cs.

Referenced by Tgstation.Server.Host.Server.CheckSanity().


The documentation for this class was generated from the following file: