diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs index 8bdda299f0..89d35076f3 100644 --- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs +++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs @@ -61,8 +61,6 @@ namespace OpenSim.Framework.Servers /// server. /// private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); - - protected string m_pidFile = String.Empty; /// /// Random uuid for private data @@ -293,23 +291,6 @@ namespace OpenSim.Framework.Servers MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId); } - protected void CreatePIDFile(string path) - { - try - { - string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); - FileStream fs = File.Create(path); - - Byte[] buf = Encoding.ASCII.GetBytes(pidstring); - fs.Write(buf, 0, buf.Length); - fs.Close(); - m_pidFile = path; - } - catch (Exception) - { - } - } - public string osSecret { // Secret uuid for the simulator get { return m_osSecret; } @@ -327,20 +308,5 @@ namespace OpenSim.Framework.Servers return StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version); } } - - protected void RemovePIDFile() - { - if (m_pidFile != String.Empty) - { - try - { - File.Delete(m_pidFile); - m_pidFile = String.Empty; - } - catch (Exception) - { - } - } - } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index 9973a2d626..645b43aed0 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs @@ -55,6 +55,8 @@ namespace OpenSim.Framework.Servers protected DateTime m_startuptime; protected string m_startupDirectory = Environment.CurrentDirectory; + protected string m_pidFile = String.Empty; + /// /// Server version information. Usually VersionInfo + information about git commit, operating system, etc. /// @@ -67,6 +69,45 @@ namespace OpenSim.Framework.Servers EnhanceVersionInformation(); } + protected void CreatePIDFile(string path) + { + try + { + string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); + + using (FileStream fs = File.Create(path)) + { + Byte[] buf = Encoding.ASCII.GetBytes(pidstring); + fs.Write(buf, 0, buf.Length); + } + + m_pidFile = path; + + m_log.InfoFormat("[SERVER BASE]: Created pid file {0}", m_pidFile); + } + catch (Exception e) + { + m_log.Warn(string.Format("[SERVER BASE]: Could not create PID file at {0} ", path), e); + } + } + + protected void RemovePIDFile() + { + if (m_pidFile != String.Empty) + { + try + { + File.Delete(m_pidFile); + } + catch (Exception e) + { + m_log.Error(string.Format("[SERVER BASE]: Error whilst removing {0} ", m_pidFile), e); + } + + m_pidFile = String.Empty; + } + } + public void RegisterCommonAppenders(IConfig startupConfig) { ILoggerRepository repository = LogManager.GetRepository(); @@ -109,7 +150,7 @@ namespace OpenSim.Framework.Servers m_logFileAppender.ActivateOptions(); } - m_log.InfoFormat("[LOGGING]: Logging started to file {0}", m_logFileAppender.File); + m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File); } } @@ -243,26 +284,26 @@ namespace OpenSim.Framework.Servers } else if (File.Exists(gitRefPointerPath)) { -// m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath); +// m_log.DebugFormat("[SERVER BASE]: Found {0}", gitRefPointerPath); string rawPointer = ""; using (StreamReader pointerFile = File.OpenText(gitRefPointerPath)) rawPointer = pointerFile.ReadLine(); -// m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer); +// m_log.DebugFormat("[SERVER BASE]: rawPointer [{0}]", rawPointer); Match m = Regex.Match(rawPointer, "^ref: (.+)$"); if (m.Success) { -// m_log.DebugFormat("[OPENSIM]: Matched [{0}]", m.Groups[1].Value); +// m_log.DebugFormat("[SERVER BASE]: Matched [{0}]", m.Groups[1].Value); string gitRef = m.Groups[1].Value; string gitRefPath = gitDir + gitRef; if (File.Exists(gitRefPath)) { -// m_log.DebugFormat("[OPENSIM]: Found gitRefPath [{0}]", gitRefPath); +// m_log.DebugFormat("[SERVER BASE]: Found gitRefPath [{0}]", gitRefPath); using (StreamReader refFile = File.OpenText(gitRefPath)) { diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 4eed7d5755..ade4babdfa 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs @@ -69,10 +69,6 @@ namespace OpenSim.Server.Base // private bool m_Running = true; - // PID file - // - private string m_pidFile = String.Empty; - // Handle all the automagical stuff // public ServicesServerBase(string prompt, string[] args) : base() @@ -240,8 +236,8 @@ namespace OpenSim.Server.Base } } - if (m_pidFile != String.Empty) - File.Delete(m_pidFile); + RemovePIDFile(); + return 0; } @@ -249,6 +245,7 @@ namespace OpenSim.Server.Base { m_Running = false; m_log.Info("[CONSOLE] Quitting"); + } protected virtual void HandleScript(string module, string[] parms) @@ -292,21 +289,5 @@ namespace OpenSim.Server.Base protected virtual void Initialise() { } - - protected void CreatePIDFile(string path) - { - try - { - string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); - FileStream fs = File.Create(path); - Byte[] buf = Encoding.ASCII.GetBytes(pidstring); - fs.Write(buf, 0, buf.Length); - fs.Close(); - m_pidFile = path; - } - catch (Exception) - { - } - } } } \ No newline at end of file