feat: add signal handling (SIGTERM, SIGUSR2, SIGHUP) and CLI stubs

This commit is contained in:
Joseph Doherty
2026-02-22 23:52:49 -05:00
parent e57605f090
commit df39ebdc58
2 changed files with 68 additions and 4 deletions

View File

@@ -32,6 +32,15 @@ for (int i = 0; i < args.Length; i++)
case "--https_port" when i + 1 < args.Length:
options.MonitorHttpsPort = int.Parse(args[++i]);
break;
case "-c" when i + 1 < args.Length:
options.ConfigFile = args[++i];
break;
case "--pid" when i + 1 < args.Length:
options.PidFile = args[++i];
break;
case "--ports_file_dir" when i + 1 < args.Length:
options.PortsFileDir = args[++i];
break;
case "--tls":
break;
case "--tlscert" when i + 1 < args.Length:
@@ -50,18 +59,24 @@ for (int i = 0; i < args.Length; i++)
}
using var loggerFactory = new Serilog.Extensions.Logging.SerilogLoggerFactory(Log.Logger);
var server = new NatsServer(options, loggerFactory);
using var server = new NatsServer(options, loggerFactory);
var cts = new CancellationTokenSource();
// Register signal handlers
server.HandleSignals();
// Ctrl+C triggers graceful shutdown
Console.CancelKeyPress += (_, e) =>
{
e.Cancel = true;
cts.Cancel();
Log.Information("Trapped SIGINT signal");
_ = Task.Run(async () => await server.ShutdownAsync());
};
try
{
await server.StartAsync(cts.Token);
_ = server.StartAsync(CancellationToken.None);
await server.WaitForReadyAsync();
server.WaitForShutdown();
}
catch (OperationCanceledException)
{