diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index bd23d1cb62..d1e29b485e 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -711,7 +711,7 @@ namespace OpenSim.Framework.Console
///
public void Prompt()
{
- string line = ReadLine(m_defaultPrompt + "# ", true, true);
+ string line = ReadLine(DefaultPrompt + "# ", true, true);
if (line != String.Empty)
Output("Invalid command");
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 4b375d9963..2d8e723af2 100755
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
public object ConsoleScene { get; set; }
- ///
- /// The default prompt text.
- ///
- public string DefaultPrompt
- {
- set { m_defaultPrompt = value; }
- get { return m_defaultPrompt; }
- }
- protected string m_defaultPrompt;
+ public string DefaultPrompt { get; set; }
public ConsoleBase(string defaultPrompt)
{
diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs
index b489f93b69..8ba58e4cc6 100644
--- a/OpenSim/Framework/Console/MockConsole.cs
+++ b/OpenSim/Framework/Console/MockConsole.cs
@@ -46,13 +46,18 @@ namespace OpenSim.Framework.Console
public ICommands Commands { get { return m_commands; } }
+ public string DefaultPrompt { get; set; }
+
public void Prompt() {}
public void RunCommand(string cmd) {}
public string ReadLine(string p, bool isCommand, bool e) { return ""; }
- public object ConsoleScene { get { return null; } }
+ public object ConsoleScene {
+ get { return null; }
+ set {}
+ }
public void Output(string text, string level) {}
public void Output(string text) {}
diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs
index 8cd20da4ee..a6573f8843 100644
--- a/OpenSim/Framework/ICommandConsole.cs
+++ b/OpenSim/Framework/ICommandConsole.cs
@@ -82,6 +82,11 @@ namespace OpenSim.Framework
ICommands Commands { get; }
+ ///
+ /// The default prompt text.
+ ///
+ string DefaultPrompt { get; set; }
+
///
/// Display a command prompt on the console and wait for user input
///
diff --git a/OpenSim/Framework/IConsole.cs b/OpenSim/Framework/IConsole.cs
index 33024b2076..79560d805b 100644
--- a/OpenSim/Framework/IConsole.cs
+++ b/OpenSim/Framework/IConsole.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Framework
{
public interface IConsole
{
- object ConsoleScene { get; }
+ object ConsoleScene { get; set; }
void Output(string text, string level);
void Output(string text);
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index e6ca38032a..2c21800bbd 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -61,22 +61,6 @@ namespace OpenSim.Framework.Servers
/// server.
///
private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
-
- protected CommandConsole m_console;
- protected OpenSimAppender m_consoleAppender;
- protected IAppender m_logFileAppender = null;
-
- ///
- /// Record the initial startup directory for info purposes
- ///
- protected string m_startupDirectory = Environment.CurrentDirectory;
-
- ///
- /// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
- ///
- protected string m_version;
-
- protected string m_pidFile = String.Empty;
///
/// Random uuid for private data
@@ -91,27 +75,11 @@ namespace OpenSim.Framework.Servers
public BaseOpenSimServer() : base()
{
- m_version = VersionInfo.Version;
-
// Random uuid for private data
m_osSecret = UUID.Random().ToString();
m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
m_periodicDiagnosticsTimer.Enabled = true;
-
- // This thread will go on to become the console listening thread
- Thread.CurrentThread.Name = "ConsoleThread";
-
- ILoggerRepository repository = LogManager.GetRepository();
- IAppender[] appenders = repository.GetAppenders();
-
- foreach (IAppender appender in appenders)
- {
- if (appender.Name == "LogFileAppender")
- {
- m_logFileAppender = appender;
- }
- }
}
///
@@ -119,77 +87,40 @@ namespace OpenSim.Framework.Servers
///
protected virtual void StartupSpecific()
{
- if (m_console != null)
- {
- ILoggerRepository repository = LogManager.GetRepository();
- IAppender[] appenders = repository.GetAppenders();
+ if (m_console == null)
+ return;
- foreach (IAppender appender in appenders)
- {
- if (appender.Name == "Console")
- {
- m_consoleAppender = (OpenSimAppender)appender;
- break;
- }
- }
+ RegisterCommonCommands();
+
+ m_console.Commands.AddCommand("General", false, "quit",
+ "quit",
+ "Quit the application", HandleQuit);
- if (null == m_consoleAppender)
- {
- Notice("No appender named Console found (see the log4net config file for this executable)!");
- }
- else
- {
- m_consoleAppender.Console = m_console;
-
- // If there is no threshold set then the threshold is effectively everything.
- if (null == m_consoleAppender.Threshold)
- m_consoleAppender.Threshold = Level.All;
-
- Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
- }
-
- m_console.Commands.AddCommand("General", false, "quit",
- "quit",
- "Quit the application", HandleQuit);
+ m_console.Commands.AddCommand("General", false, "shutdown",
+ "shutdown",
+ "Quit the application", HandleQuit);
- m_console.Commands.AddCommand("General", false, "shutdown",
- "shutdown",
- "Quit the application", HandleQuit);
+ m_console.Commands.AddCommand("General", false, "show threads",
+ "show threads",
+ "Show thread status", HandleShow);
- m_console.Commands.AddCommand("General", false, "set log level",
- "set log level ",
- "Set the console logging level", HandleLogLevel);
+ m_console.Commands.AddCommand("General", false, "show version",
+ "show version",
+ "Show server version", HandleShow);
- m_console.Commands.AddCommand("General", false, "show info",
- "show info",
- "Show general information about the server", HandleShow);
+ m_console.Commands.AddCommand("General", false, "threads abort",
+ "threads abort ",
+ "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
- m_console.Commands.AddCommand("General", false, "show threads",
- "show threads",
- "Show thread status", HandleShow);
+ m_console.Commands.AddCommand("General", false, "threads show",
+ "threads show",
+ "Show thread status. Synonym for \"show threads\"",
+ (string module, string[] args) => Notice(GetThreadsReport()));
- m_console.Commands.AddCommand("General", false, "show uptime",
- "show uptime",
- "Show server uptime", HandleShow);
-
- m_console.Commands.AddCommand("General", false, "show version",
- "show version",
- "Show server version", HandleShow);
-
- m_console.Commands.AddCommand("General", false, "threads abort",
- "threads abort ",
- "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
-
- m_console.Commands.AddCommand("General", false, "threads show",
- "threads show",
- "Show thread status. Synonym for \"show threads\"",
- (string module, string[] args) => Notice(GetThreadsReport()));
-
- m_console.Commands.AddCommand("General", false, "force gc",
- "force gc",
- "Manually invoke runtime garbage collection. For debugging purposes",
- HandleForceGc);
- }
+ m_console.Commands.AddCommand("General", false, "force gc",
+ "force gc",
+ "Manually invoke runtime garbage collection. For debugging purposes",
+ HandleForceGc);
}
private void HandleForceGc(string module, string[] args)
@@ -281,8 +212,6 @@ namespace OpenSim.Framework.Servers
public virtual void Startup()
{
m_log.Info("[STARTUP]: Beginning startup processing");
-
- EnhanceVersionInformation();
m_log.Info("[STARTUP]: Careminster version: " + m_version + Environment.NewLine);
// clr version potentially is more confusing than helpful, since it doesn't tell us if we're running under Mono/MS .NET and
@@ -319,56 +248,10 @@ namespace OpenSim.Framework.Servers
Shutdown();
}
- private void HandleLogLevel(string module, string[] cmd)
+ public override void HandleShow(string module, string[] cmd)
{
- if (null == m_consoleAppender)
- {
- Notice("No appender named Console found (see the log4net config file for this executable)!");
- return;
- }
-
- if (cmd.Length > 3)
- {
- string rawLevel = cmd[3];
-
- ILoggerRepository repository = LogManager.GetRepository();
- Level consoleLevel = repository.LevelMap[rawLevel];
-
- if (consoleLevel != null)
- m_consoleAppender.Threshold = consoleLevel;
- else
- Notice(
- String.Format(
- "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF",
- rawLevel));
- }
+ base.HandleShow(module, cmd);
- Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
- }
-
- ///
- /// Show help information
- ///
- ///
- protected virtual void ShowHelp(string[] helpArgs)
- {
- Notice("");
-
- if (helpArgs.Length == 0)
- {
- Notice("set log level [level] - change the console logging level only. For example, off or debug.");
- Notice("show info - show server information (e.g. startup path).");
- Notice("show threads - list tracked threads");
- Notice("show uptime - show server startup time and uptime.");
- Notice("show version - show server version.");
- Notice("");
-
- return;
- }
- }
-
- public virtual void HandleShow(string module, string[] cmd)
- {
List args = new List(cmd);
args.RemoveAt(0);
@@ -377,18 +260,10 @@ namespace OpenSim.Framework.Servers
switch (showParams[0])
{
- case "info":
- ShowInfo();
- break;
-
case "threads":
Notice(GetThreadsReport());
break;
- case "uptime":
- Notice(GetUptimeReport());
- break;
-
case "version":
Notice(GetVersionText());
break;
@@ -414,160 +289,7 @@ namespace OpenSim.Framework.Servers
MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId);
else
MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId);
- }
-
- protected void ShowInfo()
- {
- Notice(GetVersionText());
- Notice("Startup directory: " + m_startupDirectory);
- if (null != m_consoleAppender)
- Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold));
- }
-
- protected string GetVersionText()
- {
- return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
- }
-
- ///
- /// Console output is only possible if a console has been established.
- /// That is something that cannot be determined within this class. So
- /// all attempts to use the console MUST be verified.
- ///
- ///
- protected void Notice(string msg)
- {
- if (m_console != null)
- {
- m_console.Output(msg);
- }
- }
-
- ///
- /// Console output is only possible if a console has been established.
- /// That is something that cannot be determined within this class. So
- /// all attempts to use the console MUST be verified.
- ///
- ///
- ///
- protected void Notice(string format, params string[] components)
- {
- if (m_console != null)
- m_console.OutputFormat(format, components);
- }
-
- ///
- /// Enhance the version string with extra information if it's available.
- ///
- protected void EnhanceVersionInformation()
- {
- string buildVersion = string.Empty;
-
- // The subversion information is deprecated and will be removed at a later date
- // Add subversion revision information if available
- // Try file "svn_revision" in the current directory first, then the .svn info.
- // This allows to make the revision available in simulators not running from the source tree.
- // FIXME: Making an assumption about the directory we're currently in - we do this all over the place
- // elsewhere as well
- string gitDir = "../.git/";
- string gitRefPointerPath = gitDir + "HEAD";
-
- string svnRevisionFileName = "svn_revision";
- string svnFileName = ".svn/entries";
- string manualVersionFileName = ".version";
- string inputLine;
- int strcmp;
-
- if (File.Exists(manualVersionFileName))
- {
- using (StreamReader CommitFile = File.OpenText(manualVersionFileName))
- buildVersion = CommitFile.ReadLine();
-
- m_version += buildVersion ?? "";
- }
- else if (File.Exists(gitRefPointerPath))
- {
-// m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath);
-
- string rawPointer = "";
-
- using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
- rawPointer = pointerFile.ReadLine();
-
-// m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer);
-
- Match m = Regex.Match(rawPointer, "^ref: (.+)$");
-
- if (m.Success)
- {
-// m_log.DebugFormat("[OPENSIM]: 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);
-
- using (StreamReader refFile = File.OpenText(gitRefPath))
- {
- string gitHash = refFile.ReadLine();
- m_version += gitHash.Substring(0, 7);
- }
- }
- }
- }
- else
- {
- // Remove the else logic when subversion mirror is no longer used
- if (File.Exists(svnRevisionFileName))
- {
- StreamReader RevisionFile = File.OpenText(svnRevisionFileName);
- buildVersion = RevisionFile.ReadLine();
- buildVersion.Trim();
- RevisionFile.Close();
- }
-
- if (string.IsNullOrEmpty(buildVersion) && File.Exists(svnFileName))
- {
- StreamReader EntriesFile = File.OpenText(svnFileName);
- inputLine = EntriesFile.ReadLine();
- while (inputLine != null)
- {
- // using the dir svn revision at the top of entries file
- strcmp = String.Compare(inputLine, "dir");
- if (strcmp == 0)
- {
- buildVersion = EntriesFile.ReadLine();
- break;
- }
- else
- {
- inputLine = EntriesFile.ReadLine();
- }
- }
- EntriesFile.Close();
- }
-
- 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);
-
- 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
@@ -586,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 d19234b8d7..c182a3abca 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -26,20 +26,392 @@
*/
using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
using System.Text;
+using System.Text.RegularExpressions;
+using log4net;
+using log4net.Appender;
+using log4net.Core;
+using log4net.Repository;
+using Nini.Config;
+using OpenSim.Framework.Console;
namespace OpenSim.Framework.Servers
{
public class ServerBase
{
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ public IConfigSource Config { get; protected set; }
+
///
- /// Time at which this server was started
+ /// Console to be used for any command line output. Can be null, in which case there should be no output.
///
+ protected ICommandConsole m_console;
+
+ protected OpenSimAppender m_consoleAppender;
+ protected FileAppender m_logFileAppender;
+
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.
+ ///
+ protected string m_version;
public ServerBase()
{
m_startuptime = DateTime.Now;
+ m_version = VersionInfo.Version;
+ 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();
+ IAppender[] appenders = repository.GetAppenders();
+
+ foreach (IAppender appender in appenders)
+ {
+ if (appender.Name == "Console")
+ {
+ m_consoleAppender = (OpenSimAppender)appender;
+ }
+ else if (appender.Name == "LogFileAppender")
+ {
+ m_logFileAppender = (FileAppender)appender;
+ }
+ }
+
+ if (null == m_consoleAppender)
+ {
+ Notice("No appender named Console found (see the log4net config file for this executable)!");
+ }
+ else
+ {
+ // FIXME: This should be done through an interface rather than casting.
+ m_consoleAppender.Console = (ConsoleBase)m_console;
+
+ // If there is no threshold set then the threshold is effectively everything.
+ if (null == m_consoleAppender.Threshold)
+ m_consoleAppender.Threshold = Level.All;
+
+ Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
+ }
+
+ if (m_logFileAppender != null && startupConfig != null)
+ {
+ string cfgFileName = startupConfig.GetString("LogFile", null);
+ if (cfgFileName != null)
+ {
+ m_logFileAppender.File = cfgFileName;
+ m_logFileAppender.ActivateOptions();
+ }
+
+ m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File);
+ }
+ }
+
+ ///
+ /// Register common commands once m_console has been set if it is going to be set
+ ///
+ public void RegisterCommonCommands()
+ {
+ if (m_console == null)
+ return;
+
+ m_console.Commands.AddCommand(
+ "General", false, "show info", "show info", "Show general information about the server", HandleShow);
+
+ m_console.Commands.AddCommand(
+ "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow);
+
+ m_console.Commands.AddCommand(
+ "General", false, "get log level", "get log level", "Get the current console logging level",
+ (mod, cmd) => ShowLogLevel());
+
+ m_console.Commands.AddCommand(
+ "General", false, "set log level", "set log level ",
+ "Set the console logging level for this session.", HandleSetLogLevel);
+
+ m_console.Commands.AddCommand(
+ "General", false, "config set",
+ "config set ",
+ "Set a config option. In most cases this is not useful since changed parameters are not dynamically reloaded. Neither do changed parameters persist - you will have to change a config file manually and restart.", HandleConfig);
+
+ m_console.Commands.AddCommand(
+ "General", false, "config get",
+ "config get [] []",
+ "Synonym for config show",
+ HandleConfig);
+
+ m_console.Commands.AddCommand(
+ "General", false, "config show",
+ "config show [] []",
+ "Show config information",
+ "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
+ + "If a section is given but not a field, then all fields in that section are printed.",
+ HandleConfig);
+
+ m_console.Commands.AddCommand(
+ "General", false, "config save",
+ "config save ",
+ "Save current configuration to a file at the given path", HandleConfig);
+
+ m_console.Commands.AddCommand(
+ "General", false, "command-script",
+ "command-script