Merge branch 'master' into connector_plugin

Conflicts:
	OpenSim/Server/Base/ServicesServerBase.cs
This commit is contained in:
BlueWall
2012-11-25 17:03:14 -05:00
453 changed files with 13672 additions and 8935 deletions

View File

@@ -34,6 +34,7 @@ using System.Text;
using System.Xml;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
using log4net;
using log4net.Config;
using log4net.Appender;
@@ -43,7 +44,7 @@ using Nini.Config;
namespace OpenSim.Server.Base
{
public class ServicesServerBase
public class ServicesServerBase : ServerBase
{
// Logger
//
@@ -55,15 +56,6 @@ namespace OpenSim.Server.Base
//
protected string[] m_Arguments;
// Configuration
//
protected IConfigSource m_Config = null;
public IConfigSource Config
{
get { return m_Config; }
}
public string ConfigDirectory
{
get;
@@ -74,21 +66,10 @@ namespace OpenSim.Server.Base
//
private bool m_Running = true;
// PID file
//
private string m_pidFile = String.Empty;
/// <summary>
/// Time at which this server was started
/// </summary>
protected DateTime m_startuptime;
// Handle all the automagical stuff
//
public ServicesServerBase(string prompt, string[] args)
public ServicesServerBase(string prompt, string[] args) : base()
{
m_startuptime = DateTime.Now;
// Save raw arguments
//
m_Arguments = args;
@@ -134,11 +115,11 @@ namespace OpenSim.Server.Base
configUri.Scheme == Uri.UriSchemeHttp)
{
XmlReader r = XmlReader.Create(iniFile);
m_Config = new XmlConfigSource(r);
Config = new XmlConfigSource(r);
}
else
{
m_Config = new IniConfigSource(iniFile);
Config = new IniConfigSource(iniFile);
}
}
catch (Exception e)
@@ -150,13 +131,13 @@ namespace OpenSim.Server.Base
// Merge the configuration from the command line into the
// loaded file
//
m_Config.Merge(argvConfig);
Config.Merge(argvConfig);
// Refresh the startupConfig post merge
//
if (m_Config.Configs["Startup"] != null)
if (Config.Configs["Startup"] != null)
{
startupConfig = m_Config.Configs["Startup"];
startupConfig = Config.Configs["Startup"];
}
ConfigDirectory = startupConfig.GetString("ConfigDirectory", ".");
@@ -188,6 +169,8 @@ namespace OpenSim.Server.Base
MainConsole.Instance = new LocalConsole(prompt);
}
m_console = MainConsole.Instance;
// Configure the appenders for log4net
//
OpenSimAppender consoleAppender = null;
@@ -203,54 +186,15 @@ namespace OpenSim.Server.Base
XmlConfigurator.Configure();
}
ILoggerRepository repository = LogManager.GetRepository();
IAppender[] appenders = repository.GetAppenders();
foreach (IAppender appender in appenders)
{
if (appender.Name == "Console")
{
consoleAppender = (OpenSimAppender)appender;
}
if (appender.Name == "LogFileAppender")
{
fileAppender = (FileAppender)appender;
}
}
if (consoleAppender == null)
{
System.Console.WriteLine("No console appender found. Server can't start");
Thread.CurrentThread.Abort();
}
else
{
consoleAppender.Console = (ConsoleBase)MainConsole.Instance;
if (null == consoleAppender.Threshold)
consoleAppender.Threshold = Level.All;
}
// Set log file
//
if (fileAppender != null)
{
if (startupConfig != null)
{
string cfgFileName = startupConfig.GetString("logfile", null);
if (cfgFileName != null)
{
fileAppender.File = cfgFileName;
fileAppender.ActivateOptions();
}
}
}
RegisterCommonAppenders(startupConfig);
if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
{
CreatePIDFile(startupConfig.GetString("PIDFile"));
}
RegisterCommonCommands();
// Register the quit command
//
MainConsole.Instance.Commands.AddCommand("General", false, "quit",
@@ -260,16 +204,6 @@ namespace OpenSim.Server.Base
MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
"shutdown",
"Quit the application", HandleQuit);
// Register a command to read other commands from a file
MainConsole.Instance.Commands.AddCommand("General", false, "command-script",
"command-script <script>",
"Run a command script from file", HandleScript);
MainConsole.Instance.Commands.AddCommand("General", false, "show uptime",
"show uptime",
"Show server uptime", HandleShow);
// Allow derived classes to perform initialization that
// needs to be done after the console has opened
@@ -296,8 +230,8 @@ namespace OpenSim.Server.Base
}
}
if (m_pidFile != String.Empty)
File.Delete(m_pidFile);
RemovePIDFile();
return 0;
}
@@ -305,43 +239,9 @@ namespace OpenSim.Server.Base
{
m_Running = false;
m_log.Info("[CONSOLE] Quitting");
}
protected virtual void HandleScript(string module, string[] parms)
{
if (parms.Length != 2)
{
return;
}
RunCommandScript(parms[1]);
}
/// <summary>
/// Run an optional startup list of commands
/// </summary>
/// <param name="fileName"></param>
private void RunCommandScript(string fileName)
{
if (File.Exists(fileName))
{
m_log.Info("[COMMANDFILE]: Running " + fileName);
using (StreamReader readFile = File.OpenText(fileName))
{
string currentCommand;
while ((currentCommand = readFile.ReadLine()) != null)
{
if (currentCommand != String.Empty)
{
m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
MainConsole.Instance.RunCommand(currentCommand);
}
}
}
}
}
protected virtual void ReadConfig()
{
}
@@ -349,50 +249,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)
{
}
}
public virtual void HandleShow(string module, string[] cmd)
{
List<string> args = new List<string>(cmd);
args.RemoveAt(0);
string[] showParams = args.ToArray();
switch (showParams[0])
{
case "uptime":
MainConsole.Instance.Output(GetUptimeReport());
break;
}
}
/// <summary>
/// Return a report about the uptime of this server
/// </summary>
/// <returns></returns>
protected string GetUptimeReport()
{
StringBuilder sb = new StringBuilder(String.Format("Time now is {0}\n", DateTime.Now));
sb.Append(String.Format("Server has been running since {0}, {1}\n", m_startuptime.DayOfWeek, m_startuptime));
sb.Append(String.Format("That is an elapsed time of {0}\n", DateTime.Now - m_startuptime));
return sb.ToString();
}
}
}