using Fleet.Core; using Fleet.Hosting; using MoShiro.Agent; TimeProvider time = TimeProvider.System; INodeLog log = new BufferedNodeLog(new ConsoleNodeLog(time), time); if (PlatformCheck.VerifyCrypto() is { } problem) { log.Error("startup failed", ("err", problem)); return 1; } string configPath = "/etc/moshiro/agent.json"; for (int i = 0; i < args.Length - 1; i++) { if (args[i] == "--config") { configPath = args[i + 1]; } } AgentConfig config; LoadedNodeIdentity identity; RestartController restart; try { config = NodeConfig.Load(configPath, AgentConfigContext.Default.AgentConfig); restart = new RestartController(RestartSchedule.Resolve(config.RestartAt)); identity = LoadedNodeIdentity.Load(config.Fleet.IdentityDir); if (!OwnerGuard.Check(config.Fleet.IdentityDir, config.Fleet.RequireOwner, log)) { identity.Dispose(); return 1; } } catch (Exception ex) when (ex is IOException or InvalidDataException or InvalidOperationException or System.Text.Json.JsonException or System.Security.Cryptography.CryptographicException) { log.Error("startup failed", ("err", ex.Message)); return 1; } using var restartScope = restart; using (identity) { await using var app = new AgentApp(config, identity, Path.GetDirectoryName(Path.GetFullPath(configPath))!, time, log, restart); await ServiceShell.RunAsync(app.RunAsync, log, restart, time); } return 0;