Recreated plugin with new project template. Started implementing server system daemon
This commit is contained in:
69
MoonlightServers.Daemon/ServerSystem/Server.Restore.cs
Normal file
69
MoonlightServers.Daemon/ServerSystem/Server.Restore.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
namespace MoonlightServers.Daemon.ServerSystem;
|
||||
|
||||
public partial class Server
|
||||
{
|
||||
// Attempts to reattach to any running install or runtime environment that survived a daemon restart.
|
||||
// Returns the appropriate state based on what was found, or Offline if nothing is running.
|
||||
private async Task<ServerState> RestoreAsync()
|
||||
{
|
||||
// Install
|
||||
Logger.LogTrace("Checking for existing install environment");
|
||||
|
||||
InstallEnvironment = await InstallEnvironmentService.FindAsync(Uuid);
|
||||
InstallStorage = await InstallStorageService.FindAsync(Uuid);
|
||||
|
||||
if (InstallEnvironment != null)
|
||||
{
|
||||
var isRunning = await InstallEnvironment.IsRunningAsync();
|
||||
|
||||
if (isRunning)
|
||||
{
|
||||
Logger.LogTrace("Found running install environment, reattaching");
|
||||
|
||||
InstallEnvironment.Console.OnOutput += OnConsoleMessageAsync;
|
||||
InstallEnvironment.Statistics.OnStatisticsReceived += OnStatisticsReceivedAsync;
|
||||
InstallEnvironment.OnExited += OnInstallExitedAsync;
|
||||
|
||||
await InstallEnvironment.Console.AttachAsync();
|
||||
await InstallEnvironment.Statistics.AttachAsync();
|
||||
|
||||
return ServerState.Installing;
|
||||
}
|
||||
|
||||
Logger.LogTrace("Install environment exists but is not running, ignoring");
|
||||
}
|
||||
|
||||
// Runtime
|
||||
Logger.LogTrace("Checking for existing runtime environment");
|
||||
|
||||
RuntimeEnvironment = await RuntimeEnvironmentService.FindAsync(Uuid);
|
||||
RuntimeStorage = await RuntimeStorageService.FindAsync(Uuid);
|
||||
|
||||
if (RuntimeEnvironment != null)
|
||||
{
|
||||
var isRunning = await RuntimeEnvironment.IsRunningAsync();
|
||||
|
||||
if (isRunning)
|
||||
{
|
||||
Logger.LogTrace("Found running runtime environment, reattaching");
|
||||
|
||||
RuntimeEnvironment.Console.OnOutput += OnConsoleMessageAsync;
|
||||
RuntimeEnvironment.Statistics.OnStatisticsReceived += OnStatisticsReceivedAsync;
|
||||
RuntimeEnvironment.OnExited += OnRuntimeExitedAsync;
|
||||
|
||||
await RuntimeEnvironment.Console.AttachAsync();
|
||||
await RuntimeEnvironment.Statistics.AttachAsync();
|
||||
|
||||
// TODO: Use string online check here
|
||||
|
||||
return ServerState.Online;
|
||||
}
|
||||
|
||||
Logger.LogTrace("Runtime environment exists but is not running, ignoring");
|
||||
}
|
||||
|
||||
Logger.LogTrace("No running environments found");
|
||||
|
||||
return ServerState.Offline;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user