Factor out common pid file creation and removal code.
Log path at which pid file is created or reason for failure to create.connector_plugin
parent
42e87a6582
commit
8269d2b893
|
@ -62,8 +62,6 @@ namespace OpenSim.Framework.Servers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
|
private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
|
||||||
|
|
||||||
protected string m_pidFile = String.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Random uuid for private data
|
/// Random uuid for private data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -293,23 +291,6 @@ namespace OpenSim.Framework.Servers
|
||||||
MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId);
|
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 {
|
public string osSecret {
|
||||||
// Secret uuid for the simulator
|
// Secret uuid for the simulator
|
||||||
get { return m_osSecret; }
|
get { return m_osSecret; }
|
||||||
|
@ -327,20 +308,5 @@ namespace OpenSim.Framework.Servers
|
||||||
return StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version);
|
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -55,6 +55,8 @@ namespace OpenSim.Framework.Servers
|
||||||
protected DateTime m_startuptime;
|
protected DateTime m_startuptime;
|
||||||
protected string m_startupDirectory = Environment.CurrentDirectory;
|
protected string m_startupDirectory = Environment.CurrentDirectory;
|
||||||
|
|
||||||
|
protected string m_pidFile = String.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
|
/// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -67,6 +69,45 @@ namespace OpenSim.Framework.Servers
|
||||||
EnhanceVersionInformation();
|
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)
|
public void RegisterCommonAppenders(IConfig startupConfig)
|
||||||
{
|
{
|
||||||
ILoggerRepository repository = LogManager.GetRepository();
|
ILoggerRepository repository = LogManager.GetRepository();
|
||||||
|
@ -109,7 +150,7 @@ namespace OpenSim.Framework.Servers
|
||||||
m_logFileAppender.ActivateOptions();
|
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))
|
else if (File.Exists(gitRefPointerPath))
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath);
|
// m_log.DebugFormat("[SERVER BASE]: Found {0}", gitRefPointerPath);
|
||||||
|
|
||||||
string rawPointer = "";
|
string rawPointer = "";
|
||||||
|
|
||||||
using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
|
using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
|
||||||
rawPointer = pointerFile.ReadLine();
|
rawPointer = pointerFile.ReadLine();
|
||||||
|
|
||||||
// m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer);
|
// m_log.DebugFormat("[SERVER BASE]: rawPointer [{0}]", rawPointer);
|
||||||
|
|
||||||
Match m = Regex.Match(rawPointer, "^ref: (.+)$");
|
Match m = Regex.Match(rawPointer, "^ref: (.+)$");
|
||||||
|
|
||||||
if (m.Success)
|
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 gitRef = m.Groups[1].Value;
|
||||||
string gitRefPath = gitDir + gitRef;
|
string gitRefPath = gitDir + gitRef;
|
||||||
if (File.Exists(gitRefPath))
|
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))
|
using (StreamReader refFile = File.OpenText(gitRefPath))
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,10 +69,6 @@ namespace OpenSim.Server.Base
|
||||||
//
|
//
|
||||||
private bool m_Running = true;
|
private bool m_Running = true;
|
||||||
|
|
||||||
// PID file
|
|
||||||
//
|
|
||||||
private string m_pidFile = String.Empty;
|
|
||||||
|
|
||||||
// Handle all the automagical stuff
|
// Handle all the automagical stuff
|
||||||
//
|
//
|
||||||
public ServicesServerBase(string prompt, string[] args) : base()
|
public ServicesServerBase(string prompt, string[] args) : base()
|
||||||
|
@ -240,8 +236,8 @@ namespace OpenSim.Server.Base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pidFile != String.Empty)
|
RemovePIDFile();
|
||||||
File.Delete(m_pidFile);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +245,7 @@ namespace OpenSim.Server.Base
|
||||||
{
|
{
|
||||||
m_Running = false;
|
m_Running = false;
|
||||||
m_log.Info("[CONSOLE] Quitting");
|
m_log.Info("[CONSOLE] Quitting");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void HandleScript(string module, string[] parms)
|
protected virtual void HandleScript(string module, string[] parms)
|
||||||
|
@ -292,21 +289,5 @@ namespace OpenSim.Server.Base
|
||||||
protected virtual void Initialise()
|
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue