Implemented restorer, runtime and dummy statistics. Added service registering and fixed server factory. Moved logger to server context

This commit is contained in:
2025-09-07 23:15:48 +02:00
parent 282096595d
commit b90100d250
18 changed files with 385 additions and 65 deletions

View File

@@ -0,0 +1,59 @@
using Docker.DotNet;
using MoonlightServers.Daemon.ServerSystem.Interfaces;
using MoonlightServers.Daemon.ServerSystem.Models;
namespace MoonlightServers.Daemon.ServerSystem.Docker;
public class DockerRestorer : IRestorer
{
private readonly DockerClient DockerClient;
private readonly ServerContext Context;
public DockerRestorer(DockerClient dockerClient, ServerContext context)
{
DockerClient = dockerClient;
Context = context;
}
public Task InitializeAsync()
=> Task.CompletedTask;
public async Task<bool> HandleRuntimeAsync()
{
var containerName = string.Format(DockerConstants.RuntimeNameTemplate, Context.Configuration.Id);
try
{
var container = await DockerClient.Containers.InspectContainerAsync(
containerName
);
return container.State.Running;
}
catch (DockerContainerNotFoundException)
{
return false;
}
}
public async Task<bool> HandleInstallationAsync()
{
var containerName = string.Format(DockerConstants.InstallationNameTemplate, Context.Configuration.Id);
try
{
var container = await DockerClient.Containers.InspectContainerAsync(
containerName
);
return container.State.Running;
}
catch (DockerContainerNotFoundException)
{
return false;
}
}
public ValueTask DisposeAsync()
=> ValueTask.CompletedTask;
}