From 45d1e6ab09309e21f96979548b5d1b4904800f65 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Nov 2012 04:45:53 +0000 Subject: Make "show info" command available across all servers This helpfully lists version information, startup location and console log level --- OpenSim/Framework/Servers/BaseOpenSimServer.cs | 178 +----------------------- OpenSim/Framework/Servers/ServerBase.cs | 184 ++++++++++++++++++++++++- OpenSim/Region/Application/OpenSim.cs | 17 +-- OpenSim/Server/Base/ServicesServerBase.cs | 43 +----- prebuild.xml | 1 + 5 files changed, 186 insertions(+), 237 deletions(-) diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs index 019b68b..9560171 100644 --- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs +++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs @@ -62,19 +62,6 @@ namespace OpenSim.Framework.Servers /// private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); - 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; /// @@ -90,27 +77,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; - } - } } /// @@ -121,34 +92,6 @@ namespace OpenSim.Framework.Servers if (m_console == null) return; - ILoggerRepository repository = LogManager.GetRepository(); - IAppender[] appenders = repository.GetAppenders(); - - foreach (IAppender appender in appenders) - { - if (appender.Name == "Console") - { - m_consoleAppender = (OpenSimAppender)appender; - break; - } - } - - 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)); - } - RegisterCommonCommands(); m_console.Commands.AddCommand("General", false, "quit", @@ -163,10 +106,6 @@ namespace OpenSim.Framework.Servers "set log level ", "Set the console logging level", HandleLogLevel); - m_console.Commands.AddCommand("General", false, "show info", - "show info", - "Show general information about the server", HandleShow); - m_console.Commands.AddCommand("General", false, "show threads", "show threads", "Show thread status", HandleShow); @@ -279,8 +218,6 @@ namespace OpenSim.Framework.Servers public virtual void Startup() { m_log.Info("[STARTUP]: Beginning startup processing"); - - EnhanceVersionInformation(); m_log.Info("[STARTUP]: OpenSimulator 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 @@ -377,10 +314,6 @@ namespace OpenSim.Framework.Servers switch (showParams[0]) { - case "info": - ShowInfo(); - break; - case "threads": Notice(GetThreadsReport()); break; @@ -410,116 +343,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); - } - - /// - /// 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) { diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index 0835aad..129b5fa 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs @@ -27,26 +27,90 @@ 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); + /// /// 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; + /// - /// Time at which this server was started + /// Server version information. Usually VersionInfo + information about git commit, operating system, etc. /// - protected DateTime m_startuptime; + protected string m_version; public ServerBase() { m_startuptime = DateTime.Now; + m_version = VersionInfo.Version; + EnhanceVersionInformation(); + } + + 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("[LOGGING]: Logging started to file {0}", m_logFileAppender.File); + } } /// @@ -58,6 +122,9 @@ namespace OpenSim.Framework.Servers 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); } @@ -71,6 +138,10 @@ namespace OpenSim.Framework.Servers switch (showParams[0]) { + case "info": + ShowInfo(); + break; + case "uptime": Notice(GetUptimeReport()); break; @@ -90,6 +161,115 @@ namespace OpenSim.Framework.Servers return sb.ToString(); } + protected void ShowInfo() + { + Notice(GetVersionText()); + Notice("Startup directory: " + m_startupDirectory); + if (null != m_consoleAppender) + Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold)); + } + + /// + /// 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 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 diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 47252f6..e5aecbc 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -106,22 +106,6 @@ namespace OpenSim m_timeInterval = startupConfig.GetInt("timer_Interval", 1200); } - if (m_logFileAppender != null) - { - if (m_logFileAppender is log4net.Appender.FileAppender) - { - log4net.Appender.FileAppender appender = - (log4net.Appender.FileAppender)m_logFileAppender; - string fileName = startupConfig.GetString("LogFile", String.Empty); - if (fileName != String.Empty) - { - appender.File = fileName; - appender.ActivateOptions(); - } - m_log.InfoFormat("[LOGGING]: Logging started to file {0}", appender.File); - } - } - string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty); FireAndForgetMethod asyncCallMethod; if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse(asyncCallMethodStr, out asyncCallMethod)) @@ -174,6 +158,7 @@ namespace OpenSim MainConsole.Instance = m_console; + RegisterCommonAppenders(m_config.Source.Configs["Startup"]); RegisterConsoleCommands(); base.StartupSpecific(); diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 285168c..15586f8 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs @@ -191,48 +191,7 @@ 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) { diff --git a/prebuild.xml b/prebuild.xml index bb9d80c..5be86e2 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -445,6 +445,7 @@ + -- cgit v1.1