aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-11-22 04:45:53 +0000
committerJustin Clark-Casey (justincc)2012-11-22 04:45:53 +0000
commit45d1e6ab09309e21f96979548b5d1b4904800f65 (patch)
tree7100fb7c02636a06e9c7de8d0c644de5f118c5e1 /OpenSim
parentFactor out common registration of "show uptime" command (diff)
downloadopensim-SC_OLD-45d1e6ab09309e21f96979548b5d1b4904800f65.zip
opensim-SC_OLD-45d1e6ab09309e21f96979548b5d1b4904800f65.tar.gz
opensim-SC_OLD-45d1e6ab09309e21f96979548b5d1b4904800f65.tar.bz2
opensim-SC_OLD-45d1e6ab09309e21f96979548b5d1b4904800f65.tar.xz
Make "show info" command available across all servers
This helpfully lists version information, startup location and console log level
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs178
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs184
-rw-r--r--OpenSim/Region/Application/OpenSim.cs17
-rw-r--r--OpenSim/Server/Base/ServicesServerBase.cs43
4 files changed, 185 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
62 /// </summary> 62 /// </summary>
63 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); 63 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
64 64
65 protected OpenSimAppender m_consoleAppender;
66 protected IAppender m_logFileAppender = null;
67
68 /// <summary>
69 /// Record the initial startup directory for info purposes
70 /// </summary>
71 protected string m_startupDirectory = Environment.CurrentDirectory;
72
73 /// <summary>
74 /// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
75 /// </summary>
76 protected string m_version;
77
78 protected string m_pidFile = String.Empty; 65 protected string m_pidFile = String.Empty;
79 66
80 /// <summary> 67 /// <summary>
@@ -90,27 +77,11 @@ namespace OpenSim.Framework.Servers
90 77
91 public BaseOpenSimServer() : base() 78 public BaseOpenSimServer() : base()
92 { 79 {
93 m_version = VersionInfo.Version;
94
95 // Random uuid for private data 80 // Random uuid for private data
96 m_osSecret = UUID.Random().ToString(); 81 m_osSecret = UUID.Random().ToString();
97 82
98 m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics); 83 m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
99 m_periodicDiagnosticsTimer.Enabled = true; 84 m_periodicDiagnosticsTimer.Enabled = true;
100
101 // This thread will go on to become the console listening thread
102 Thread.CurrentThread.Name = "ConsoleThread";
103
104 ILoggerRepository repository = LogManager.GetRepository();
105 IAppender[] appenders = repository.GetAppenders();
106
107 foreach (IAppender appender in appenders)
108 {
109 if (appender.Name == "LogFileAppender")
110 {
111 m_logFileAppender = appender;
112 }
113 }
114 } 85 }
115 86
116 /// <summary> 87 /// <summary>
@@ -121,34 +92,6 @@ namespace OpenSim.Framework.Servers
121 if (m_console == null) 92 if (m_console == null)
122 return; 93 return;
123 94
124 ILoggerRepository repository = LogManager.GetRepository();
125 IAppender[] appenders = repository.GetAppenders();
126
127 foreach (IAppender appender in appenders)
128 {
129 if (appender.Name == "Console")
130 {
131 m_consoleAppender = (OpenSimAppender)appender;
132 break;
133 }
134 }
135
136 if (null == m_consoleAppender)
137 {
138 Notice("No appender named Console found (see the log4net config file for this executable)!");
139 }
140 else
141 {
142 // FIXME: This should be done through an interface rather than casting.
143 m_consoleAppender.Console = (ConsoleBase)m_console;
144
145 // If there is no threshold set then the threshold is effectively everything.
146 if (null == m_consoleAppender.Threshold)
147 m_consoleAppender.Threshold = Level.All;
148
149 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
150 }
151
152 RegisterCommonCommands(); 95 RegisterCommonCommands();
153 96
154 m_console.Commands.AddCommand("General", false, "quit", 97 m_console.Commands.AddCommand("General", false, "quit",
@@ -163,10 +106,6 @@ namespace OpenSim.Framework.Servers
163 "set log level <level>", 106 "set log level <level>",
164 "Set the console logging level", HandleLogLevel); 107 "Set the console logging level", HandleLogLevel);
165 108
166 m_console.Commands.AddCommand("General", false, "show info",
167 "show info",
168 "Show general information about the server", HandleShow);
169
170 m_console.Commands.AddCommand("General", false, "show threads", 109 m_console.Commands.AddCommand("General", false, "show threads",
171 "show threads", 110 "show threads",
172 "Show thread status", HandleShow); 111 "Show thread status", HandleShow);
@@ -279,8 +218,6 @@ namespace OpenSim.Framework.Servers
279 public virtual void Startup() 218 public virtual void Startup()
280 { 219 {
281 m_log.Info("[STARTUP]: Beginning startup processing"); 220 m_log.Info("[STARTUP]: Beginning startup processing");
282
283 EnhanceVersionInformation();
284 221
285 m_log.Info("[STARTUP]: OpenSimulator version: " + m_version + Environment.NewLine); 222 m_log.Info("[STARTUP]: OpenSimulator version: " + m_version + Environment.NewLine);
286 // clr version potentially is more confusing than helpful, since it doesn't tell us if we're running under Mono/MS .NET and 223 // 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
377 314
378 switch (showParams[0]) 315 switch (showParams[0])
379 { 316 {
380 case "info":
381 ShowInfo();
382 break;
383
384 case "threads": 317 case "threads":
385 Notice(GetThreadsReport()); 318 Notice(GetThreadsReport());
386 break; 319 break;
@@ -410,116 +343,7 @@ namespace OpenSim.Framework.Servers
410 MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId); 343 MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId);
411 else 344 else
412 MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId); 345 MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId);
413 } 346 }
414
415 protected void ShowInfo()
416 {
417 Notice(GetVersionText());
418 Notice("Startup directory: " + m_startupDirectory);
419 if (null != m_consoleAppender)
420 Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold));
421 }
422
423 protected string GetVersionText()
424 {
425 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
426 }
427
428 /// <summary>
429 /// Enhance the version string with extra information if it's available.
430 /// </summary>
431 protected void EnhanceVersionInformation()
432 {
433 string buildVersion = string.Empty;
434
435 // The subversion information is deprecated and will be removed at a later date
436 // Add subversion revision information if available
437 // Try file "svn_revision" in the current directory first, then the .svn info.
438 // This allows to make the revision available in simulators not running from the source tree.
439 // FIXME: Making an assumption about the directory we're currently in - we do this all over the place
440 // elsewhere as well
441 string gitDir = "../.git/";
442 string gitRefPointerPath = gitDir + "HEAD";
443
444 string svnRevisionFileName = "svn_revision";
445 string svnFileName = ".svn/entries";
446 string manualVersionFileName = ".version";
447 string inputLine;
448 int strcmp;
449
450 if (File.Exists(manualVersionFileName))
451 {
452 using (StreamReader CommitFile = File.OpenText(manualVersionFileName))
453 buildVersion = CommitFile.ReadLine();
454
455 m_version += buildVersion ?? "";
456 }
457 else if (File.Exists(gitRefPointerPath))
458 {
459// m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath);
460
461 string rawPointer = "";
462
463 using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
464 rawPointer = pointerFile.ReadLine();
465
466// m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer);
467
468 Match m = Regex.Match(rawPointer, "^ref: (.+)$");
469
470 if (m.Success)
471 {
472// m_log.DebugFormat("[OPENSIM]: Matched [{0}]", m.Groups[1].Value);
473
474 string gitRef = m.Groups[1].Value;
475 string gitRefPath = gitDir + gitRef;
476 if (File.Exists(gitRefPath))
477 {
478// m_log.DebugFormat("[OPENSIM]: Found gitRefPath [{0}]", gitRefPath);
479
480 using (StreamReader refFile = File.OpenText(gitRefPath))
481 {
482 string gitHash = refFile.ReadLine();
483 m_version += gitHash.Substring(0, 7);
484 }
485 }
486 }
487 }
488 else
489 {
490 // Remove the else logic when subversion mirror is no longer used
491 if (File.Exists(svnRevisionFileName))
492 {
493 StreamReader RevisionFile = File.OpenText(svnRevisionFileName);
494 buildVersion = RevisionFile.ReadLine();
495 buildVersion.Trim();
496 RevisionFile.Close();
497 }
498
499 if (string.IsNullOrEmpty(buildVersion) && File.Exists(svnFileName))
500 {
501 StreamReader EntriesFile = File.OpenText(svnFileName);
502 inputLine = EntriesFile.ReadLine();
503 while (inputLine != null)
504 {
505 // using the dir svn revision at the top of entries file
506 strcmp = String.Compare(inputLine, "dir");
507 if (strcmp == 0)
508 {
509 buildVersion = EntriesFile.ReadLine();
510 break;
511 }
512 else
513 {
514 inputLine = EntriesFile.ReadLine();
515 }
516 }
517 EntriesFile.Close();
518 }
519
520 m_version += string.IsNullOrEmpty(buildVersion) ? " " : ("." + buildVersion + " ").Substring(0, 6);
521 }
522 }
523 347
524 protected void CreatePIDFile(string path) 348 protected void CreatePIDFile(string path)
525 { 349 {
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 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
30using System.Text; 32using System.Text;
33using System.Text.RegularExpressions;
34using log4net;
35using log4net.Appender;
36using log4net.Core;
37using log4net.Repository;
38using Nini.Config;
31using OpenSim.Framework.Console; 39using OpenSim.Framework.Console;
32 40
33namespace OpenSim.Framework.Servers 41namespace OpenSim.Framework.Servers
34{ 42{
35 public class ServerBase 43 public class ServerBase
36 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
37 /// <summary> 47 /// <summary>
38 /// Console to be used for any command line output. Can be null, in which case there should be no output. 48 /// Console to be used for any command line output. Can be null, in which case there should be no output.
39 /// </summary> 49 /// </summary>
40 protected ICommandConsole m_console; 50 protected ICommandConsole m_console;
41 51
52 protected OpenSimAppender m_consoleAppender;
53 protected FileAppender m_logFileAppender;
54
55 protected DateTime m_startuptime;
56 protected string m_startupDirectory = Environment.CurrentDirectory;
57
42 /// <summary> 58 /// <summary>
43 /// Time at which this server was started 59 /// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
44 /// </summary> 60 /// </summary>
45 protected DateTime m_startuptime; 61 protected string m_version;
46 62
47 public ServerBase() 63 public ServerBase()
48 { 64 {
49 m_startuptime = DateTime.Now; 65 m_startuptime = DateTime.Now;
66 m_version = VersionInfo.Version;
67 EnhanceVersionInformation();
68 }
69
70 public void RegisterCommonAppenders(IConfig startupConfig)
71 {
72 ILoggerRepository repository = LogManager.GetRepository();
73 IAppender[] appenders = repository.GetAppenders();
74
75 foreach (IAppender appender in appenders)
76 {
77 if (appender.Name == "Console")
78 {
79 m_consoleAppender = (OpenSimAppender)appender;
80 }
81 else if (appender.Name == "LogFileAppender")
82 {
83 m_logFileAppender = (FileAppender)appender;
84 }
85 }
86
87 if (null == m_consoleAppender)
88 {
89 Notice("No appender named Console found (see the log4net config file for this executable)!");
90 }
91 else
92 {
93 // FIXME: This should be done through an interface rather than casting.
94 m_consoleAppender.Console = (ConsoleBase)m_console;
95
96 // If there is no threshold set then the threshold is effectively everything.
97 if (null == m_consoleAppender.Threshold)
98 m_consoleAppender.Threshold = Level.All;
99
100 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
101 }
102
103 if (m_logFileAppender != null && startupConfig != null)
104 {
105 string cfgFileName = startupConfig.GetString("LogFile", null);
106 if (cfgFileName != null)
107 {
108 m_logFileAppender.File = cfgFileName;
109 m_logFileAppender.ActivateOptions();
110 }
111
112 m_log.InfoFormat("[LOGGING]: Logging started to file {0}", m_logFileAppender.File);
113 }
50 } 114 }
51 115
52 /// <summary> 116 /// <summary>
@@ -58,6 +122,9 @@ namespace OpenSim.Framework.Servers
58 return; 122 return;
59 123
60 m_console.Commands.AddCommand( 124 m_console.Commands.AddCommand(
125 "General", false, "show info", "show info", "Show general information about the server", HandleShow);
126
127 m_console.Commands.AddCommand(
61 "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow); 128 "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow);
62 } 129 }
63 130
@@ -71,6 +138,10 @@ namespace OpenSim.Framework.Servers
71 138
72 switch (showParams[0]) 139 switch (showParams[0])
73 { 140 {
141 case "info":
142 ShowInfo();
143 break;
144
74 case "uptime": 145 case "uptime":
75 Notice(GetUptimeReport()); 146 Notice(GetUptimeReport());
76 break; 147 break;
@@ -90,6 +161,115 @@ namespace OpenSim.Framework.Servers
90 return sb.ToString(); 161 return sb.ToString();
91 } 162 }
92 163
164 protected void ShowInfo()
165 {
166 Notice(GetVersionText());
167 Notice("Startup directory: " + m_startupDirectory);
168 if (null != m_consoleAppender)
169 Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold));
170 }
171
172 /// <summary>
173 /// Enhance the version string with extra information if it's available.
174 /// </summary>
175 protected void EnhanceVersionInformation()
176 {
177 string buildVersion = string.Empty;
178
179 // The subversion information is deprecated and will be removed at a later date
180 // Add subversion revision information if available
181 // Try file "svn_revision" in the current directory first, then the .svn info.
182 // This allows to make the revision available in simulators not running from the source tree.
183 // FIXME: Making an assumption about the directory we're currently in - we do this all over the place
184 // elsewhere as well
185 string gitDir = "../.git/";
186 string gitRefPointerPath = gitDir + "HEAD";
187
188 string svnRevisionFileName = "svn_revision";
189 string svnFileName = ".svn/entries";
190 string manualVersionFileName = ".version";
191 string inputLine;
192 int strcmp;
193
194 if (File.Exists(manualVersionFileName))
195 {
196 using (StreamReader CommitFile = File.OpenText(manualVersionFileName))
197 buildVersion = CommitFile.ReadLine();
198
199 m_version += buildVersion ?? "";
200 }
201 else if (File.Exists(gitRefPointerPath))
202 {
203// m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath);
204
205 string rawPointer = "";
206
207 using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
208 rawPointer = pointerFile.ReadLine();
209
210// m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer);
211
212 Match m = Regex.Match(rawPointer, "^ref: (.+)$");
213
214 if (m.Success)
215 {
216// m_log.DebugFormat("[OPENSIM]: Matched [{0}]", m.Groups[1].Value);
217
218 string gitRef = m.Groups[1].Value;
219 string gitRefPath = gitDir + gitRef;
220 if (File.Exists(gitRefPath))
221 {
222// m_log.DebugFormat("[OPENSIM]: Found gitRefPath [{0}]", gitRefPath);
223
224 using (StreamReader refFile = File.OpenText(gitRefPath))
225 {
226 string gitHash = refFile.ReadLine();
227 m_version += gitHash.Substring(0, 7);
228 }
229 }
230 }
231 }
232 else
233 {
234 // Remove the else logic when subversion mirror is no longer used
235 if (File.Exists(svnRevisionFileName))
236 {
237 StreamReader RevisionFile = File.OpenText(svnRevisionFileName);
238 buildVersion = RevisionFile.ReadLine();
239 buildVersion.Trim();
240 RevisionFile.Close();
241 }
242
243 if (string.IsNullOrEmpty(buildVersion) && File.Exists(svnFileName))
244 {
245 StreamReader EntriesFile = File.OpenText(svnFileName);
246 inputLine = EntriesFile.ReadLine();
247 while (inputLine != null)
248 {
249 // using the dir svn revision at the top of entries file
250 strcmp = String.Compare(inputLine, "dir");
251 if (strcmp == 0)
252 {
253 buildVersion = EntriesFile.ReadLine();
254 break;
255 }
256 else
257 {
258 inputLine = EntriesFile.ReadLine();
259 }
260 }
261 EntriesFile.Close();
262 }
263
264 m_version += string.IsNullOrEmpty(buildVersion) ? " " : ("." + buildVersion + " ").Substring(0, 6);
265 }
266 }
267
268 protected string GetVersionText()
269 {
270 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
271 }
272
93 /// <summary> 273 /// <summary>
94 /// Console output is only possible if a console has been established. 274 /// Console output is only possible if a console has been established.
95 /// That is something that cannot be determined within this class. So 275 /// 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
106 m_timeInterval = startupConfig.GetInt("timer_Interval", 1200); 106 m_timeInterval = startupConfig.GetInt("timer_Interval", 1200);
107 } 107 }
108 108
109 if (m_logFileAppender != null)
110 {
111 if (m_logFileAppender is log4net.Appender.FileAppender)
112 {
113 log4net.Appender.FileAppender appender =
114 (log4net.Appender.FileAppender)m_logFileAppender;
115 string fileName = startupConfig.GetString("LogFile", String.Empty);
116 if (fileName != String.Empty)
117 {
118 appender.File = fileName;
119 appender.ActivateOptions();
120 }
121 m_log.InfoFormat("[LOGGING]: Logging started to file {0}", appender.File);
122 }
123 }
124
125 string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty); 109 string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
126 FireAndForgetMethod asyncCallMethod; 110 FireAndForgetMethod asyncCallMethod;
127 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod)) 111 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
@@ -174,6 +158,7 @@ namespace OpenSim
174 158
175 MainConsole.Instance = m_console; 159 MainConsole.Instance = m_console;
176 160
161 RegisterCommonAppenders(m_config.Source.Configs["Startup"]);
177 RegisterConsoleCommands(); 162 RegisterConsoleCommands();
178 163
179 base.StartupSpecific(); 164 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
191 XmlConfigurator.Configure(); 191 XmlConfigurator.Configure();
192 } 192 }
193 193
194 ILoggerRepository repository = LogManager.GetRepository(); 194 RegisterCommonAppenders(startupConfig);
195 IAppender[] appenders = repository.GetAppenders();
196
197 foreach (IAppender appender in appenders)
198 {
199 if (appender.Name == "Console")
200 {
201 consoleAppender = (OpenSimAppender)appender;
202 }
203 if (appender.Name == "LogFileAppender")
204 {
205 fileAppender = (FileAppender)appender;
206 }
207 }
208
209 if (consoleAppender == null)
210 {
211 System.Console.WriteLine("No console appender found. Server can't start");
212 Thread.CurrentThread.Abort();
213 }
214 else
215 {
216 consoleAppender.Console = (ConsoleBase)MainConsole.Instance;
217
218 if (null == consoleAppender.Threshold)
219 consoleAppender.Threshold = Level.All;
220 }
221
222 // Set log file
223 //
224 if (fileAppender != null)
225 {
226 if (startupConfig != null)
227 {
228 string cfgFileName = startupConfig.GetString("logfile", null);
229 if (cfgFileName != null)
230 {
231 fileAppender.File = cfgFileName;
232 fileAppender.ActivateOptions();
233 }
234 }
235 }
236 195
237 if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) 196 if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
238 { 197 {