From 76ca0963847d75d2d7233ad965c74e50a09d6dce Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Wed, 1 Apr 2009 12:13:42 +0000 Subject: Add a PIDFile in [Startup], which the PID will be written to --- OpenSim/Framework/Servers/BaseOpenSimServer.cs | 36 ++++++++++++++++++++++++++ OpenSim/Region/Application/OpenSimBase.cs | 10 ++++++- bin/OpenSim.ini.example | 3 +++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs index 8ede8f5..9794a10 100644 --- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs +++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs @@ -73,6 +73,8 @@ namespace OpenSim.Framework.Servers /// protected string m_version; + protected string m_pidFile = String.Empty; + protected BaseHttpServer m_httpServer; public BaseHttpServer HttpServer { @@ -278,6 +280,7 @@ namespace OpenSim.Framework.Servers ShutdownSpecific(); m_log.Info("[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); + RemovePIDFile(); Environment.Exit(0); } @@ -433,5 +436,38 @@ namespace OpenSim.Framework.Servers m_version += string.IsNullOrEmpty(buildVersion) ? " " : ("." + buildVersion + " ").Substring(0, 6); } + + protected void CreatePIDFile(string path) + { + try + { + string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); + FileStream fs = File.Create(path); + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + Byte[] buf = enc.GetBytes(pidstring); + fs.Write(buf, 0, buf.Length); + fs.Close(); + m_pidFile = path; + } + catch (Exception) + { + } + } + + + protected void RemovePIDFile() + { + if (m_pidFile != String.Empty) + { + try + { + File.Delete(m_pidFile); + m_pidFile = String.Empty; + } + catch (Exception) + { + } + } + } } } diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index ffabdd8..4cdb074 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -188,6 +188,14 @@ namespace OpenSim /// protected override void StartupSpecific() { + IConfig startupConfig = m_config.Source.Configs["Startup"]; + if (startupConfig != null) + { + string pidFile = startupConfig.GetString("PIDFile", String.Empty); + if (pidFile != String.Empty) + CreatePIDFile(pidFile); + } + base.StartupSpecific(); m_stats = StatsManager.StartCollectingSimExtraStats(); @@ -857,4 +865,4 @@ namespace OpenSim } } } -} \ No newline at end of file +} diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 9937cb9..7b2d370 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -7,6 +7,9 @@ ; (eg default is /opensimdir/crashes/*.txt or C:\opensim\crashes\*.txt) crash_dir = "crashes" + ; Place to create a PID file + ; PIDFile = "/tmp/my.pid" + ; Http proxy support for llHTTPRequest and dynamic texture loading ; Set HttpProxy to the URL for your proxy server if you would like ; to proxy llHTTPRequests through a firewall -- cgit v1.1