Skip to content

Commit 505e58e

Browse files
committed
Add support for posix signals for exiting the inengine.exe
1 parent afccae6 commit 505e58e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/InEngine/InEngine.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<ItemGroup>
3131
<Reference Include="System.ServiceProcess" />
3232
<Reference Include="System.Configuration.Install" />
33+
<Reference Include="Mono.Posix" />
3334
</ItemGroup>
3435
<ItemGroup>
3536
<None Update="Install.ps1">

src/InEngine/Program.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.IO;
33
using System.ServiceProcess;
4+
using Mono.Unix;
5+
using Mono.Unix.Native;
46

57
namespace InEngine
68
{
@@ -20,7 +22,19 @@ static void Main(string[] args)
2022
public static void RunScheduler()
2123
{
2224
var isRunningUnderMono = Type.GetType("Mono.Runtime") != null;
23-
if (!Environment.UserInteractive && !isRunningUnderMono)
25+
26+
if (isRunningUnderMono) {
27+
var serverHost = new ServerHost();
28+
serverHost.Start();
29+
Console.WriteLine("CTRL+C to exit.");
30+
UnixSignal.WaitAny(new[] {
31+
new UnixSignal(Signum.SIGINT),
32+
new UnixSignal(Signum.SIGTERM),
33+
new UnixSignal(Signum.SIGQUIT),
34+
new UnixSignal(Signum.SIGHUP)
35+
});
36+
}
37+
else if (!Environment.UserInteractive && !isRunningUnderMono)
2438
{
2539
// Set current working directory as services use the system directory by default.
2640
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

0 commit comments

Comments
 (0)