diff options
author | Melanie | 2012-11-22 13:37:27 +0000 |
---|---|---|
committer | Melanie | 2012-11-22 13:37:27 +0000 |
commit | 3c1a58c67a9162480054674ae8c83f5b501576db (patch) | |
tree | 7864eb3dd4aea66bd41b49a43a810c6c623c2485 /OpenSim/Framework/Servers/BaseOpenSimServer.cs | |
parent | Merge branch 'avination' into careminster (diff) | |
parent | Factor out command script code. (diff) | |
download | opensim-SC-3c1a58c67a9162480054674ae8c83f5b501576db.zip opensim-SC-3c1a58c67a9162480054674ae8c83f5b501576db.tar.gz opensim-SC-3c1a58c67a9162480054674ae8c83f5b501576db.tar.bz2 opensim-SC-3c1a58c67a9162480054674ae8c83f5b501576db.tar.xz |
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Framework/Servers/BaseOpenSimServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/BaseOpenSimServer.cs | 369 |
1 files changed, 38 insertions, 331 deletions
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs index e6ca380..2c21800 100644 --- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs +++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs | |||
@@ -61,22 +61,6 @@ namespace OpenSim.Framework.Servers | |||
61 | /// server. | 61 | /// server. |
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 | |||
65 | protected CommandConsole m_console; | ||
66 | protected OpenSimAppender m_consoleAppender; | ||
67 | protected IAppender m_logFileAppender = null; | ||
68 | |||
69 | /// <summary> | ||
70 | /// Record the initial startup directory for info purposes | ||
71 | /// </summary> | ||
72 | protected string m_startupDirectory = Environment.CurrentDirectory; | ||
73 | |||
74 | /// <summary> | ||
75 | /// Server version information. Usually VersionInfo + information about git commit, operating system, etc. | ||
76 | /// </summary> | ||
77 | protected string m_version; | ||
78 | |||
79 | protected string m_pidFile = String.Empty; | ||
80 | 64 | ||
81 | /// <summary> | 65 | /// <summary> |
82 | /// Random uuid for private data | 66 | /// Random uuid for private data |
@@ -91,27 +75,11 @@ namespace OpenSim.Framework.Servers | |||
91 | 75 | ||
92 | public BaseOpenSimServer() : base() | 76 | public BaseOpenSimServer() : base() |
93 | { | 77 | { |
94 | m_version = VersionInfo.Version; | ||
95 | |||
96 | // Random uuid for private data | 78 | // Random uuid for private data |
97 | m_osSecret = UUID.Random().ToString(); | 79 | m_osSecret = UUID.Random().ToString(); |
98 | 80 | ||
99 | m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics); | 81 | m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics); |
100 | m_periodicDiagnosticsTimer.Enabled = true; | 82 | m_periodicDiagnosticsTimer.Enabled = true; |
101 | |||
102 | // This thread will go on to become the console listening thread | ||
103 | Thread.CurrentThread.Name = "ConsoleThread"; | ||
104 | |||
105 | ILoggerRepository repository = LogManager.GetRepository(); | ||
106 | IAppender[] appenders = repository.GetAppenders(); | ||
107 | |||
108 | foreach (IAppender appender in appenders) | ||
109 | { | ||
110 | if (appender.Name == "LogFileAppender") | ||
111 | { | ||
112 | m_logFileAppender = appender; | ||
113 | } | ||
114 | } | ||
115 | } | 83 | } |
116 | 84 | ||
117 | /// <summary> | 85 | /// <summary> |
@@ -119,77 +87,40 @@ namespace OpenSim.Framework.Servers | |||
119 | /// </summary> | 87 | /// </summary> |
120 | protected virtual void StartupSpecific() | 88 | protected virtual void StartupSpecific() |
121 | { | 89 | { |
122 | if (m_console != null) | 90 | if (m_console == null) |
123 | { | 91 | return; |
124 | ILoggerRepository repository = LogManager.GetRepository(); | 92 | |
125 | IAppender[] appenders = repository.GetAppenders(); | 93 | RegisterCommonCommands(); |
126 | 94 | ||
127 | foreach (IAppender appender in appenders) | 95 | m_console.Commands.AddCommand("General", false, "quit", |
128 | { | 96 | "quit", |
129 | if (appender.Name == "Console") | 97 | "Quit the application", HandleQuit); |
130 | { | 98 | |
131 | m_consoleAppender = (OpenSimAppender)appender; | 99 | m_console.Commands.AddCommand("General", false, "shutdown", |
132 | break; | 100 | "shutdown", |
133 | } | 101 | "Quit the application", HandleQuit); |
134 | } | 102 | |
135 | 103 | m_console.Commands.AddCommand("General", false, "show threads", | |
136 | if (null == m_consoleAppender) | 104 | "show threads", |
137 | { | 105 | "Show thread status", HandleShow); |
138 | Notice("No appender named Console found (see the log4net config file for this executable)!"); | 106 | |
139 | } | 107 | m_console.Commands.AddCommand("General", false, "show version", |
140 | else | 108 | "show version", |
141 | { | 109 | "Show server version", HandleShow); |
142 | m_consoleAppender.Console = m_console; | 110 | |
143 | 111 | m_console.Commands.AddCommand("General", false, "threads abort", | |
144 | // If there is no threshold set then the threshold is effectively everything. | 112 | "threads abort <thread-id>", |
145 | if (null == m_consoleAppender.Threshold) | 113 | "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort); |
146 | m_consoleAppender.Threshold = Level.All; | 114 | |
147 | 115 | m_console.Commands.AddCommand("General", false, "threads show", | |
148 | Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold)); | 116 | "threads show", |
149 | } | 117 | "Show thread status. Synonym for \"show threads\"", |
150 | 118 | (string module, string[] args) => Notice(GetThreadsReport())); | |
151 | m_console.Commands.AddCommand("General", false, "quit", | 119 | |
152 | "quit", | 120 | m_console.Commands.AddCommand("General", false, "force gc", |
153 | "Quit the application", HandleQuit); | 121 | "force gc", |
154 | 122 | "Manually invoke runtime garbage collection. For debugging purposes", | |
155 | m_console.Commands.AddCommand("General", false, "shutdown", | 123 | HandleForceGc); |
156 | "shutdown", | ||
157 | "Quit the application", HandleQuit); | ||
158 | |||
159 | m_console.Commands.AddCommand("General", false, "set log level", | ||
160 | "set log level <level>", | ||
161 | "Set the console logging level", HandleLogLevel); | ||
162 | |||
163 | m_console.Commands.AddCommand("General", false, "show info", | ||
164 | "show info", | ||
165 | "Show general information about the server", HandleShow); | ||
166 | |||
167 | m_console.Commands.AddCommand("General", false, "show threads", | ||
168 | "show threads", | ||
169 | "Show thread status", HandleShow); | ||
170 | |||
171 | m_console.Commands.AddCommand("General", false, "show uptime", | ||
172 | "show uptime", | ||
173 | "Show server uptime", HandleShow); | ||
174 | |||
175 | m_console.Commands.AddCommand("General", false, "show version", | ||
176 | "show version", | ||
177 | "Show server version", HandleShow); | ||
178 | |||
179 | m_console.Commands.AddCommand("General", false, "threads abort", | ||
180 | "threads abort <thread-id>", | ||
181 | "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort); | ||
182 | |||
183 | m_console.Commands.AddCommand("General", false, "threads show", | ||
184 | "threads show", | ||
185 | "Show thread status. Synonym for \"show threads\"", | ||
186 | (string module, string[] args) => Notice(GetThreadsReport())); | ||
187 | |||
188 | m_console.Commands.AddCommand("General", false, "force gc", | ||
189 | "force gc", | ||
190 | "Manually invoke runtime garbage collection. For debugging purposes", | ||
191 | HandleForceGc); | ||
192 | } | ||
193 | } | 124 | } |
194 | 125 | ||
195 | private void HandleForceGc(string module, string[] args) | 126 | private void HandleForceGc(string module, string[] args) |
@@ -281,8 +212,6 @@ namespace OpenSim.Framework.Servers | |||
281 | public virtual void Startup() | 212 | public virtual void Startup() |
282 | { | 213 | { |
283 | m_log.Info("[STARTUP]: Beginning startup processing"); | 214 | m_log.Info("[STARTUP]: Beginning startup processing"); |
284 | |||
285 | EnhanceVersionInformation(); | ||
286 | 215 | ||
287 | m_log.Info("[STARTUP]: Careminster version: " + m_version + Environment.NewLine); | 216 | m_log.Info("[STARTUP]: Careminster version: " + m_version + Environment.NewLine); |
288 | // clr version potentially is more confusing than helpful, since it doesn't tell us if we're running under Mono/MS .NET and | 217 | // 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 | |||
319 | Shutdown(); | 248 | Shutdown(); |
320 | } | 249 | } |
321 | 250 | ||
322 | private void HandleLogLevel(string module, string[] cmd) | 251 | public override void HandleShow(string module, string[] cmd) |
323 | { | ||
324 | if (null == m_consoleAppender) | ||
325 | { | ||
326 | Notice("No appender named Console found (see the log4net config file for this executable)!"); | ||
327 | return; | ||
328 | } | ||
329 | |||
330 | if (cmd.Length > 3) | ||
331 | { | ||
332 | string rawLevel = cmd[3]; | ||
333 | |||
334 | ILoggerRepository repository = LogManager.GetRepository(); | ||
335 | Level consoleLevel = repository.LevelMap[rawLevel]; | ||
336 | |||
337 | if (consoleLevel != null) | ||
338 | m_consoleAppender.Threshold = consoleLevel; | ||
339 | else | ||
340 | Notice( | ||
341 | String.Format( | ||
342 | "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF", | ||
343 | rawLevel)); | ||
344 | } | ||
345 | |||
346 | Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold)); | ||
347 | } | ||
348 | |||
349 | /// <summary> | ||
350 | /// Show help information | ||
351 | /// </summary> | ||
352 | /// <param name="helpArgs"></param> | ||
353 | protected virtual void ShowHelp(string[] helpArgs) | ||
354 | { | 252 | { |
355 | Notice(""); | 253 | base.HandleShow(module, cmd); |
356 | |||
357 | if (helpArgs.Length == 0) | ||
358 | { | ||
359 | Notice("set log level [level] - change the console logging level only. For example, off or debug."); | ||
360 | Notice("show info - show server information (e.g. startup path)."); | ||
361 | Notice("show threads - list tracked threads"); | ||
362 | Notice("show uptime - show server startup time and uptime."); | ||
363 | Notice("show version - show server version."); | ||
364 | Notice(""); | ||
365 | 254 | ||
366 | return; | ||
367 | } | ||
368 | } | ||
369 | |||
370 | public virtual void HandleShow(string module, string[] cmd) | ||
371 | { | ||
372 | List<string> args = new List<string>(cmd); | 255 | List<string> args = new List<string>(cmd); |
373 | 256 | ||
374 | args.RemoveAt(0); | 257 | args.RemoveAt(0); |
@@ -377,18 +260,10 @@ namespace OpenSim.Framework.Servers | |||
377 | 260 | ||
378 | switch (showParams[0]) | 261 | switch (showParams[0]) |
379 | { | 262 | { |
380 | case "info": | ||
381 | ShowInfo(); | ||
382 | break; | ||
383 | |||
384 | case "threads": | 263 | case "threads": |
385 | Notice(GetThreadsReport()); | 264 | Notice(GetThreadsReport()); |
386 | break; | 265 | break; |
387 | 266 | ||
388 | case "uptime": | ||
389 | Notice(GetUptimeReport()); | ||
390 | break; | ||
391 | |||
392 | case "version": | 267 | case "version": |
393 | Notice(GetVersionText()); | 268 | Notice(GetVersionText()); |
394 | break; | 269 | break; |
@@ -414,160 +289,7 @@ namespace OpenSim.Framework.Servers | |||
414 | MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId); | 289 | MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId); |
415 | else | 290 | else |
416 | MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId); | 291 | MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId); |
417 | } | 292 | } |
418 | |||
419 | protected void ShowInfo() | ||
420 | { | ||
421 | Notice(GetVersionText()); | ||
422 | Notice("Startup directory: " + m_startupDirectory); | ||
423 | if (null != m_consoleAppender) | ||
424 | Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold)); | ||
425 | } | ||
426 | |||
427 | protected string GetVersionText() | ||
428 | { | ||
429 | return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion); | ||
430 | } | ||
431 | |||
432 | /// <summary> | ||
433 | /// Console output is only possible if a console has been established. | ||
434 | /// That is something that cannot be determined within this class. So | ||
435 | /// all attempts to use the console MUST be verified. | ||
436 | /// </summary> | ||
437 | /// <param name="msg"></param> | ||
438 | protected void Notice(string msg) | ||
439 | { | ||
440 | if (m_console != null) | ||
441 | { | ||
442 | m_console.Output(msg); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | /// <summary> | ||
447 | /// Console output is only possible if a console has been established. | ||
448 | /// That is something that cannot be determined within this class. So | ||
449 | /// all attempts to use the console MUST be verified. | ||
450 | /// </summary> | ||
451 | /// <param name="format"></param> | ||
452 | /// <param name="components"></param> | ||
453 | protected void Notice(string format, params string[] components) | ||
454 | { | ||
455 | if (m_console != null) | ||
456 | m_console.OutputFormat(format, components); | ||
457 | } | ||
458 | |||
459 | /// <summary> | ||
460 | /// Enhance the version string with extra information if it's available. | ||
461 | /// </summary> | ||
462 | protected void EnhanceVersionInformation() | ||
463 | { | ||
464 | string buildVersion = string.Empty; | ||
465 | |||
466 | // The subversion information is deprecated and will be removed at a later date | ||
467 | // Add subversion revision information if available | ||
468 | // Try file "svn_revision" in the current directory first, then the .svn info. | ||
469 | // This allows to make the revision available in simulators not running from the source tree. | ||
470 | // FIXME: Making an assumption about the directory we're currently in - we do this all over the place | ||
471 | // elsewhere as well | ||
472 | string gitDir = "../.git/"; | ||
473 | string gitRefPointerPath = gitDir + "HEAD"; | ||
474 | |||
475 | string svnRevisionFileName = "svn_revision"; | ||
476 | string svnFileName = ".svn/entries"; | ||
477 | string manualVersionFileName = ".version"; | ||
478 | string inputLine; | ||
479 | int strcmp; | ||
480 | |||
481 | if (File.Exists(manualVersionFileName)) | ||
482 | { | ||
483 | using (StreamReader CommitFile = File.OpenText(manualVersionFileName)) | ||
484 | buildVersion = CommitFile.ReadLine(); | ||
485 | |||
486 | m_version += buildVersion ?? ""; | ||
487 | } | ||
488 | else if (File.Exists(gitRefPointerPath)) | ||
489 | { | ||
490 | // m_log.DebugFormat("[OPENSIM]: Found {0}", gitRefPointerPath); | ||
491 | |||
492 | string rawPointer = ""; | ||
493 | |||
494 | using (StreamReader pointerFile = File.OpenText(gitRefPointerPath)) | ||
495 | rawPointer = pointerFile.ReadLine(); | ||
496 | |||
497 | // m_log.DebugFormat("[OPENSIM]: rawPointer [{0}]", rawPointer); | ||
498 | |||
499 | Match m = Regex.Match(rawPointer, "^ref: (.+)$"); | ||
500 | |||
501 | if (m.Success) | ||
502 | { | ||
503 | // m_log.DebugFormat("[OPENSIM]: Matched [{0}]", m.Groups[1].Value); | ||
504 | |||
505 | string gitRef = m.Groups[1].Value; | ||
506 | string gitRefPath = gitDir + gitRef; | ||
507 | if (File.Exists(gitRefPath)) | ||
508 | { | ||
509 | // m_log.DebugFormat("[OPENSIM]: Found gitRefPath [{0}]", gitRefPath); | ||
510 | |||
511 | using (StreamReader refFile = File.OpenText(gitRefPath)) | ||
512 | { | ||
513 | string gitHash = refFile.ReadLine(); | ||
514 | m_version += gitHash.Substring(0, 7); | ||
515 | } | ||
516 | } | ||
517 | } | ||
518 | } | ||
519 | else | ||
520 | { | ||
521 | // Remove the else logic when subversion mirror is no longer used | ||
522 | if (File.Exists(svnRevisionFileName)) | ||
523 | { | ||
524 | StreamReader RevisionFile = File.OpenText(svnRevisionFileName); | ||
525 | buildVersion = RevisionFile.ReadLine(); | ||
526 | buildVersion.Trim(); | ||
527 | RevisionFile.Close(); | ||
528 | } | ||
529 | |||
530 | if (string.IsNullOrEmpty(buildVersion) && File.Exists(svnFileName)) | ||
531 | { | ||
532 | StreamReader EntriesFile = File.OpenText(svnFileName); | ||
533 | inputLine = EntriesFile.ReadLine(); | ||
534 | while (inputLine != null) | ||
535 | { | ||
536 | // using the dir svn revision at the top of entries file | ||
537 | strcmp = String.Compare(inputLine, "dir"); | ||
538 | if (strcmp == 0) | ||
539 | { | ||
540 | buildVersion = EntriesFile.ReadLine(); | ||
541 | break; | ||
542 | } | ||
543 | else | ||
544 | { | ||
545 | inputLine = EntriesFile.ReadLine(); | ||
546 | } | ||
547 | } | ||
548 | EntriesFile.Close(); | ||
549 | } | ||
550 | |||
551 | m_version += string.IsNullOrEmpty(buildVersion) ? " " : ("." + buildVersion + " ").Substring(0, 6); | ||
552 | } | ||
553 | } | ||
554 | |||
555 | protected void CreatePIDFile(string path) | ||
556 | { | ||
557 | try | ||
558 | { | ||
559 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | ||
560 | FileStream fs = File.Create(path); | ||
561 | |||
562 | Byte[] buf = Encoding.ASCII.GetBytes(pidstring); | ||
563 | fs.Write(buf, 0, buf.Length); | ||
564 | fs.Close(); | ||
565 | m_pidFile = path; | ||
566 | } | ||
567 | catch (Exception) | ||
568 | { | ||
569 | } | ||
570 | } | ||
571 | 293 | ||
572 | public string osSecret { | 294 | public string osSecret { |
573 | // Secret uuid for the simulator | 295 | // Secret uuid for the simulator |
@@ -586,20 +308,5 @@ namespace OpenSim.Framework.Servers | |||
586 | return StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version); | 308 | return StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version); |
587 | } | 309 | } |
588 | } | 310 | } |
589 | |||
590 | protected void RemovePIDFile() | ||
591 | { | ||
592 | if (m_pidFile != String.Empty) | ||
593 | { | ||
594 | try | ||
595 | { | ||
596 | File.Delete(m_pidFile); | ||
597 | m_pidFile = String.Empty; | ||
598 | } | ||
599 | catch (Exception) | ||
600 | { | ||
601 | } | ||
602 | } | ||
603 | } | ||
604 | } | 311 | } |
605 | } | 312 | } \ No newline at end of file |