From 7ba93b9a27a82b79ff1852b7c0bcd00f79bb02d3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 6 Aug 2022 16:55:51 -0500 Subject: listen for signals and ctrl+c --- src/slskd/Application.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 221f77da..1c7bef18 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -86,6 +86,21 @@ namespace slskd IHubContext applicationHub, IHubContext logHub) { + Console.CancelKeyPress += (_, args) => + { + ShuttingDown = true; + Log.Warning("Received SIGINT"); + }; + + foreach (var signal in new[] { PosixSignal.SIGINT, PosixSignal.SIGQUIT, PosixSignal.SIGTERM }) + { + PosixSignalRegistration.Create(signal, context => + { + ShuttingDown = true; + Log.Fatal("Received {Signal}", signal); + }); + } + OptionsAtStartup = optionsAtStartup; OptionsMonitor = optionsMonitor; -- cgit v1.2.3