Skip to content

Commit

Permalink
Re-introduce SIGTERM signal handling
Browse files Browse the repository at this point in the history
According to the .NET 6/8 docs, this is handled on Windows as well
  • Loading branch information
lickx committed Nov 2, 2024
1 parent 23abc64 commit 68bb990
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions OpenSim/Region/Application/OpenSim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using System.Text.RegularExpressions;
using System.Timers;
using System.Net;
using System.Runtime.InteropServices;
using log4net;
using NDesk.Options;
using Nini.Config;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class OpenSim : OpenSimBase
private string m_timedScript = "disabled";
private int m_timeInterval = 1200;
private System.Timers.Timer m_scriptTimer;
private PosixSignalRegistration m_signalReg;

public OpenSim(IConfigSource configSource) : base(configSource)
{
Expand Down Expand Up @@ -132,6 +134,12 @@ protected override void ReadExtraConfigSettings()
m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod);

m_log.InfoFormat("[OPENSIM MAIN] Running GC in {0} mode", GCSettings.IsServerGC ? "server":"workstation");

m_signalReg = PosixSignalRegistration.Create(PosixSignal.SIGTERM, context =>
{
m_log.Info("Received SIGTERM, shutting down");
MainConsole.Instance.RunCommand("shutdown");
});
}

/// <summary>
Expand Down Expand Up @@ -1516,5 +1524,7 @@ private static string CombineParams(string[] commandParams, int pos)
result = result.TrimEnd(' ');
return result;
}

}

}
11 changes: 10 additions & 1 deletion OpenSim/Server/ServerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.IO;
using System.Net;
using System.Net.Security;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Generic;
using OpenSim.Framework;
Expand All @@ -50,6 +51,7 @@ public class OpenSimServer
protected static List<IServiceConnector> m_ServiceConnectors = new();

protected static PluginLoader loader;
private static PosixSignalRegistration m_signalReg;
private static bool m_NoVerifyCertChain = false;
private static bool m_NoVerifyCertHostname = false;

Expand Down Expand Up @@ -95,13 +97,20 @@ public static int Main(string[] args)
Culture.SetCurrentCulture();
Culture.SetDefaultCurrentCulture();

m_signalReg = PosixSignalRegistration.Create(PosixSignal.SIGTERM, context =>
{
m_log.Info("Received SIGTERM, shutting down");
m_Server?.Shutdown();
Util.StopThreadPool();
});

ServicePointManager.DefaultConnectionLimit = 64;
ServicePointManager.MaxServicePointIdleTime = 30000;

ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;

m_Server = new HttpServerBase("R.O.B.U.S.T.", args);

string registryLocation;
Expand Down

0 comments on commit 68bb990

Please sign in to comment.