Re-implemented server state machine. Cleaned up code

TODO: Handle trigger errors
This commit is contained in:
2025-02-12 23:02:00 +01:00
parent 4088bfaef5
commit f45699f300
44 changed files with 913 additions and 831 deletions

View File

@@ -0,0 +1,37 @@
using Docker.DotNet;
using MoonlightServers.Daemon.Extensions;
using MoonlightServers.Daemon.Services;
namespace MoonlightServers.Daemon.Abstractions;
public partial class Server
{
private async Task Create()
{
var dockerImageService = ServiceProvider.GetRequiredService<DockerImageService>();
// We call an external service for that, as we want to have a central management point of images
// for analytics and automatic deletion
await dockerImageService.Ensure(Configuration.DockerImage, async message => { await LogToConsole(message); });
var hostPath = await EnsureRuntimeVolume();
await LogToConsole("Creating container");
var dockerClient = ServiceProvider.GetRequiredService<DockerClient>();
var parameters = Configuration.ToRuntimeCreateParameters(
hostPath: hostPath,
containerName: RuntimeContainerName
);
var container = await dockerClient.Containers.CreateContainerAsync(parameters);
RuntimeContainerId = container.ID;
}
private async Task ReCreate()
{
await Destroy();
await Create();
}
}