diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index bb01427b96..868a6963ad 100755 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -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; @@ -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) { @@ -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"); + }); } /// @@ -1516,5 +1524,7 @@ private static string CombineParams(string[] commandParams, int pos) result = result.TrimEnd(' '); return result; } + } + } diff --git a/OpenSim/Server/ServerMain.cs b/OpenSim/Server/ServerMain.cs index 1e5874ecec..8f56a0a66d 100644 --- a/OpenSim/Server/ServerMain.cs +++ b/OpenSim/Server/ServerMain.cs @@ -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; @@ -50,6 +51,7 @@ public class OpenSimServer protected static List m_ServiceConnectors = new(); protected static PluginLoader loader; + private static PosixSignalRegistration m_signalReg; private static bool m_NoVerifyCertChain = false; private static bool m_NoVerifyCertHostname = false; @@ -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;