Implemented more life cycle handling. Added support for rootless environments
This commit is contained in:
@@ -3,6 +3,7 @@ using Docker.DotNet.Models;
|
||||
using MoonCore.Helpers;
|
||||
using MoonlightServers.Daemon.Configuration;
|
||||
using MoonlightServers.Daemon.Models;
|
||||
using MoonlightServers.DaemonShared.Enums;
|
||||
|
||||
namespace MoonlightServers.Daemon.Helpers;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Docker.DotNet.Models;
|
||||
using Mono.Unix.Native;
|
||||
using MoonCore.Helpers;
|
||||
using MoonlightServers.Daemon.Configuration;
|
||||
using MoonlightServers.Daemon.Models.Cache;
|
||||
@@ -42,8 +43,20 @@ public static class ServerConfigurationHelper
|
||||
parameters.WorkingDir = "/home/container";
|
||||
|
||||
// - User
|
||||
//TODO: use config
|
||||
parameters.User = $"998:998";
|
||||
var userId = Syscall.getuid();
|
||||
|
||||
if (userId == 0)
|
||||
{
|
||||
// We are running as root, so we need to run the container as another user and chown the files when we make changes
|
||||
parameters.User = $"998:998";
|
||||
}
|
||||
else
|
||||
{
|
||||
// We are not running as root, so we start the container as the same user,
|
||||
// as we are not able to chown the container content to a different user
|
||||
parameters.User = $"{userId}:{userId}";
|
||||
}
|
||||
|
||||
|
||||
// -- Mounts
|
||||
parameters.HostConfig.Mounts = new List<Mount>();
|
||||
|
||||
@@ -14,7 +14,7 @@ public class StateMachine<T> where T : struct, Enum
|
||||
CurrentState = initialState;
|
||||
}
|
||||
|
||||
public void AddTransition(T from, T to, T? onError, Func<Task> fun)
|
||||
public void AddTransition(T from, T to, T? onError, Func<Task>? fun)
|
||||
{
|
||||
Transitions.Add(new()
|
||||
{
|
||||
@@ -26,6 +26,7 @@ public class StateMachine<T> where T : struct, Enum
|
||||
}
|
||||
|
||||
public void AddTransition(T from, T to, Func<Task> fun) => AddTransition(from, to, null, fun);
|
||||
public void AddTransition(T from, T to) => AddTransition(from, to, null, null);
|
||||
|
||||
public async Task TransitionTo(T to)
|
||||
{
|
||||
@@ -41,7 +42,11 @@ public class StateMachine<T> where T : struct, Enum
|
||||
|
||||
try
|
||||
{
|
||||
transition.OnTransitioning.Invoke().Wait();
|
||||
if(transition.OnTransitioning != null)
|
||||
transition.OnTransitioning.Invoke().Wait();
|
||||
|
||||
// Successfully executed => update state
|
||||
CurrentState = transition.To;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -64,6 +69,6 @@ public class StateMachine<T> where T : struct, Enum
|
||||
public T From { get; set; }
|
||||
public T To { get; set; }
|
||||
public T? OnError { get; set; }
|
||||
public Func<Task> OnTransitioning { get; set; }
|
||||
public Func<Task>? OnTransitioning { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user