43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using Fleet.Core;
|
|
using Fleet.Hosting;
|
|
using Monitor.Agent;
|
|
|
|
TimeProvider time = TimeProvider.System;
|
|
INodeLog log = new ConsoleNodeLog(time);
|
|
|
|
if (PlatformCheck.VerifyCrypto() is { } problem)
|
|
{
|
|
log.Error("startup failed", ("err", problem));
|
|
return 1;
|
|
}
|
|
|
|
string configPath = "/etc/monitor/agent.json";
|
|
for (int i = 0; i < args.Length - 1; i++)
|
|
{
|
|
if (args[i] == "--config")
|
|
{
|
|
configPath = args[i + 1];
|
|
}
|
|
}
|
|
|
|
AgentConfig config;
|
|
LoadedNodeIdentity identity;
|
|
try
|
|
{
|
|
config = NodeConfig.Load(configPath, AgentConfigContext.Default.AgentConfig);
|
|
identity = LoadedNodeIdentity.Load(config.Fleet.IdentityDir);
|
|
}
|
|
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 (identity)
|
|
{
|
|
using var app = new AgentApp(config, identity, time, log);
|
|
await ServiceShell.RunAsync(app.RunAsync, log);
|
|
}
|
|
|
|
return 0;
|