41 internal static async Task<int> Main(
string[] args)
43 System.Console.Title = $
"{Constants.CanonicalPackageName} Host Watchdog v{Assembly.GetExecutingAssembly().GetName().Version?.Semver()}";
45 var arguments =
new List<string>(args);
46 var trace = arguments.Remove(
"--trace-host-watchdog");
47 var debug = arguments.Remove(
"--debug-host-watchdog");
49 const string SystemDArg =
"--Internal:UsingSystemD=true";
50 if (!arguments.Any(arg => arg.Equals(SystemDArg, StringComparison.OrdinalIgnoreCase))
51 && SystemdHelpers.IsSystemdService())
52 arguments.Add(SystemDArg);
54 using var loggerFactory = LoggerFactory.Create(builder =>
57 builder.SetMinimumLevel(LogLevel.Trace);
59 builder.SetMinimumLevel(LogLevel.Debug);
64 var logger = loggerFactory.CreateLogger(nameof(
Program));
69 logger.LogCritical(
"Please specify only 1 of --trace-host-watchdog or --debug-host-watchdog!");
73 using var cts =
new CancellationTokenSource();
74 void AppDomainHandler(
object? a, EventArgs b) => cts.Cancel();
75 AppDomain.CurrentDomain.ProcessExit += AppDomainHandler;
78 System.Console.CancelKeyPress += (a, b) =>
85 RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
87 : new PosixSignalChecker(
88 loggerFactory.CreateLogger<PosixSignalChecker>()),
91 return await watchdog.
RunAsync(
false, arguments.ToArray(), cts.Token)
97 AppDomain.CurrentDomain.ProcessExit -= AppDomainHandler;
102 logger.LogCritical(ex,
"Failed to run!");