aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs2
-rwxr-xr-xOpenSim/Framework/Console/ConsoleBase.cs10
-rw-r--r--OpenSim/Framework/Console/MockConsole.cs7
-rw-r--r--OpenSim/Framework/ICommandConsole.cs5
-rw-r--r--OpenSim/Framework/IConsole.cs2
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs369
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs510
-rw-r--r--OpenSim/Region/Application/ConfigurationLoader.cs1
-rw-r--r--OpenSim/Region/Application/OpenSim.cs185
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs67
-rw-r--r--OpenSim/Server/Base/HttpServerBase.cs2
-rw-r--r--OpenSim/Server/Base/ServicesServerBase.cs150
-rw-r--r--prebuild.xml1
13 files changed, 605 insertions, 706 deletions
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index bd23d1c..d1e29b4 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -711,7 +711,7 @@ namespace OpenSim.Framework.Console
711 /// </summary> 711 /// </summary>
712 public void Prompt() 712 public void Prompt()
713 { 713 {
714 string line = ReadLine(m_defaultPrompt + "# ", true, true); 714 string line = ReadLine(DefaultPrompt + "# ", true, true);
715 715
716 if (line != String.Empty) 716 if (line != String.Empty)
717 Output("Invalid command"); 717 Output("Invalid command");
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 4b375d9..2d8e723 100755
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
43 43
44 public object ConsoleScene { get; set; } 44 public object ConsoleScene { get; set; }
45 45
46 /// <summary> 46 public string DefaultPrompt { get; set; }
47 /// The default prompt text.
48 /// </summary>
49 public string DefaultPrompt
50 {
51 set { m_defaultPrompt = value; }
52 get { return m_defaultPrompt; }
53 }
54 protected string m_defaultPrompt;
55 47
56 public ConsoleBase(string defaultPrompt) 48 public ConsoleBase(string defaultPrompt)
57 { 49 {
diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs
index b489f93..8ba58e4 100644
--- a/OpenSim/Framework/Console/MockConsole.cs
+++ b/OpenSim/Framework/Console/MockConsole.cs
@@ -46,13 +46,18 @@ namespace OpenSim.Framework.Console
46 46
47 public ICommands Commands { get { return m_commands; } } 47 public ICommands Commands { get { return m_commands; } }
48 48
49 public string DefaultPrompt { get; set; }
50
49 public void Prompt() {} 51 public void Prompt() {}
50 52
51 public void RunCommand(string cmd) {} 53 public void RunCommand(string cmd) {}
52 54
53 public string ReadLine(string p, bool isCommand, bool e) { return ""; } 55 public string ReadLine(string p, bool isCommand, bool e) { return ""; }
54 56
55 public object ConsoleScene { get { return null; } } 57 public object ConsoleScene {
58 get { return null; }
59 set {}
60 }
56 61
57 public void Output(string text, string level) {} 62 public void Output(string text, string level) {}
58 public void Output(string text) {} 63 public void Output(string text) {}
diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs
index 8cd20da..a6573f8 100644
--- a/OpenSim/Framework/ICommandConsole.cs
+++ b/OpenSim/Framework/ICommandConsole.cs
@@ -83,6 +83,11 @@ namespace OpenSim.Framework
83 ICommands Commands { get; } 83 ICommands Commands { get; }
84 84
85 /// <summary> 85 /// <summary>
86 /// The default prompt text.
87 /// </summary>
88 string DefaultPrompt { get; set; }
89
90 /// <summary>
86 /// Display a command prompt on the console and wait for user input 91 /// Display a command prompt on the console and wait for user input
87 /// </summary> 92 /// </summary>
88 void Prompt(); 93 void Prompt();
diff --git a/OpenSim/Framework/IConsole.cs b/OpenSim/Framework/IConsole.cs
index 33024b2..79560d8 100644
--- a/OpenSim/Framework/IConsole.cs
+++ b/OpenSim/Framework/IConsole.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Framework
32{ 32{
33 public interface IConsole 33 public interface IConsole
34 { 34 {
35 object ConsoleScene { get; } 35 object ConsoleScene { get; set; }
36 36
37 void Output(string text, string level); 37 void Output(string text, string level);
38 void Output(string text); 38 void Output(string text);
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
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index d19234b..c182a3a 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -26,20 +26,392 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
29using System.Text; 32using System.Text;
33using System.Text.RegularExpressions;
34using log4net;
35using log4net.Appender;
36using log4net.Core;
37using log4net.Repository;
38using Nini.Config;
39using OpenSim.Framework.Console;
30 40
31namespace OpenSim.Framework.Servers 41namespace OpenSim.Framework.Servers
32{ 42{
33 public class ServerBase 43 public class ServerBase
34 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 public IConfigSource Config { get; protected set; }
48
35 /// <summary> 49 /// <summary>
36 /// Time at which this server was started 50 /// Console to be used for any command line output. Can be null, in which case there should be no output.
37 /// </summary> 51 /// </summary>
52 protected ICommandConsole m_console;
53
54 protected OpenSimAppender m_consoleAppender;
55 protected FileAppender m_logFileAppender;
56
38 protected DateTime m_startuptime; 57 protected DateTime m_startuptime;
58 protected string m_startupDirectory = Environment.CurrentDirectory;
59
60 protected string m_pidFile = String.Empty;
61
62 /// <summary>
63 /// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
64 /// </summary>
65 protected string m_version;
39 66
40 public ServerBase() 67 public ServerBase()
41 { 68 {
42 m_startuptime = DateTime.Now; 69 m_startuptime = DateTime.Now;
70 m_version = VersionInfo.Version;
71 EnhanceVersionInformation();
72 }
73
74 protected void CreatePIDFile(string path)
75 {
76 try
77 {
78 string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
79
80 using (FileStream fs = File.Create(path))
81 {
82 Byte[] buf = Encoding.ASCII.GetBytes(pidstring);
83 fs.Write(buf, 0, buf.Length);
84 }
85
86 m_pidFile = path;
87
88 m_log.InfoFormat("[SERVER BASE]: Created pid file {0}", m_pidFile);
89 }
90 catch (Exception e)
91 {
92 m_log.Warn(string.Format("[SERVER BASE]: Could not create PID file at {0} ", path), e);
93 }
94 }
95
96 protected void RemovePIDFile()
97 {
98 if (m_pidFile != String.Empty)
99 {
100 try
101 {
102 File.Delete(m_pidFile);
103 }
104 catch (Exception e)
105 {
106 m_log.Error(string.Format("[SERVER BASE]: Error whilst removing {0} ", m_pidFile), e);
107 }
108
109 m_pidFile = String.Empty;
110 }
111 }
112
113 public void RegisterCommonAppenders(IConfig startupConfig)
114 {
115 ILoggerRepository repository = LogManager.GetRepository();
116 IAppender[] appenders = repository.GetAppenders();
117
118 foreach (IAppender appender in appenders)
119 {
120 if (appender.Name == "Console")
121 {
122 m_consoleAppender = (OpenSimAppender)appender;
123 }
124 else if (appender.Name == "LogFileAppender")
125 {
126 m_logFileAppender = (FileAppender)appender;
127 }
128 }
129
130 if (null == m_consoleAppender)
131 {
132 Notice("No appender named Console found (see the log4net config file for this executable)!");
133 }
134 else
135 {
136 // FIXME: This should be done through an interface rather than casting.
137 m_consoleAppender.Console = (ConsoleBase)m_console;
138
139 // If there is no threshold set then the threshold is effectively everything.
140 if (null == m_consoleAppender.Threshold)
141 m_consoleAppender.Threshold = Level.All;
142
143 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
144 }
145
146 if (m_logFileAppender != null && startupConfig != null)
147 {
148 string cfgFileName = startupConfig.GetString("LogFile", null);
149 if (cfgFileName != null)
150 {
151 m_logFileAppender.File = cfgFileName;
152 m_logFileAppender.ActivateOptions();
153 }
154
155 m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File);
156 }
157 }
158
159 /// <summary>
160 /// Register common commands once m_console has been set if it is going to be set
161 /// </summary>
162 public void RegisterCommonCommands()
163 {
164 if (m_console == null)
165 return;
166
167 m_console.Commands.AddCommand(
168 "General", false, "show info", "show info", "Show general information about the server", HandleShow);
169
170 m_console.Commands.AddCommand(
171 "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow);
172
173 m_console.Commands.AddCommand(
174 "General", false, "get log level", "get log level", "Get the current console logging level",
175 (mod, cmd) => ShowLogLevel());
176
177 m_console.Commands.AddCommand(
178 "General", false, "set log level", "set log level <level>",
179 "Set the console logging level for this session.", HandleSetLogLevel);
180
181 m_console.Commands.AddCommand(
182 "General", false, "config set",
183 "config set <section> <key> <value>",
184 "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);
185
186 m_console.Commands.AddCommand(
187 "General", false, "config get",
188 "config get [<section>] [<key>]",
189 "Synonym for config show",
190 HandleConfig);
191
192 m_console.Commands.AddCommand(
193 "General", false, "config show",
194 "config show [<section>] [<key>]",
195 "Show config information",
196 "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
197 + "If a section is given but not a field, then all fields in that section are printed.",
198 HandleConfig);
199
200 m_console.Commands.AddCommand(
201 "General", false, "config save",
202 "config save <path>",
203 "Save current configuration to a file at the given path", HandleConfig);
204
205 m_console.Commands.AddCommand(
206 "General", false, "command-script",
207 "command-script <script>",
208 "Run a command script from file", HandleScript);
209 }
210
211 public virtual void HandleShow(string module, string[] cmd)
212 {
213 List<string> args = new List<string>(cmd);
214
215 args.RemoveAt(0);
216
217 string[] showParams = args.ToArray();
218
219 switch (showParams[0])
220 {
221 case "info":
222 ShowInfo();
223 break;
224
225 case "uptime":
226 Notice(GetUptimeReport());
227 break;
228 }
229 }
230
231 /// <summary>
232 /// Change and load configuration file data.
233 /// </summary>
234 /// <param name="module"></param>
235 /// <param name="cmd"></param>
236 private void HandleConfig(string module, string[] cmd)
237 {
238 List<string> args = new List<string>(cmd);
239 args.RemoveAt(0);
240 string[] cmdparams = args.ToArray();
241
242 if (cmdparams.Length > 0)
243 {
244 string firstParam = cmdparams[0].ToLower();
245
246 switch (firstParam)
247 {
248 case "set":
249 if (cmdparams.Length < 4)
250 {
251 Notice("Syntax: config set <section> <key> <value>");
252 Notice("Example: config set ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
253 }
254 else
255 {
256 IConfig c;
257 IConfigSource source = new IniConfigSource();
258 c = source.AddConfig(cmdparams[1]);
259 if (c != null)
260 {
261 string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
262 c.Set(cmdparams[2], _value);
263 Config.Merge(source);
264
265 Notice("In section [{0}], set {1} = {2}", c.Name, cmdparams[2], _value);
266 }
267 }
268 break;
269
270 case "get":
271 case "show":
272 if (cmdparams.Length == 1)
273 {
274 foreach (IConfig config in Config.Configs)
275 {
276 Notice("[{0}]", config.Name);
277 string[] keys = config.GetKeys();
278 foreach (string key in keys)
279 Notice(" {0} = {1}", key, config.GetString(key));
280 }
281 }
282 else if (cmdparams.Length == 2 || cmdparams.Length == 3)
283 {
284 IConfig config = Config.Configs[cmdparams[1]];
285 if (config == null)
286 {
287 Notice("Section \"{0}\" does not exist.",cmdparams[1]);
288 break;
289 }
290 else
291 {
292 if (cmdparams.Length == 2)
293 {
294 Notice("[{0}]", config.Name);
295 foreach (string key in config.GetKeys())
296 Notice(" {0} = {1}", key, config.GetString(key));
297 }
298 else
299 {
300 Notice(
301 "config get {0} {1} : {2}",
302 cmdparams[1], cmdparams[2], config.GetString(cmdparams[2]));
303 }
304 }
305 }
306 else
307 {
308 Notice("Syntax: config {0} [<section>] [<key>]", firstParam);
309 Notice("Example: config {0} ScriptEngine.DotNetEngine NumberOfScriptThreads", firstParam);
310 }
311
312 break;
313
314 case "save":
315 if (cmdparams.Length < 2)
316 {
317 Notice("Syntax: config save <path>");
318 return;
319 }
320
321 string path = cmdparams[1];
322 Notice("Saving configuration file: {0}", path);
323
324 if (Config is IniConfigSource)
325 {
326 IniConfigSource iniCon = (IniConfigSource)Config;
327 iniCon.Save(path);
328 }
329 else if (Config is XmlConfigSource)
330 {
331 XmlConfigSource xmlCon = (XmlConfigSource)Config;
332 xmlCon.Save(path);
333 }
334
335 break;
336 }
337 }
338 }
339
340 private void HandleSetLogLevel(string module, string[] cmd)
341 {
342 if (cmd.Length != 4)
343 {
344 Notice("Usage: set log level <level>");
345 return;
346 }
347
348 if (null == m_consoleAppender)
349 {
350 Notice("No appender named Console found (see the log4net config file for this executable)!");
351 return;
352 }
353
354 string rawLevel = cmd[3];
355
356 ILoggerRepository repository = LogManager.GetRepository();
357 Level consoleLevel = repository.LevelMap[rawLevel];
358
359 if (consoleLevel != null)
360 m_consoleAppender.Threshold = consoleLevel;
361 else
362 Notice(
363 "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF",
364 rawLevel);
365
366 ShowLogLevel();
367 }
368
369 private void ShowLogLevel()
370 {
371 Notice("Console log level is {0}", m_consoleAppender.Threshold);
372 }
373
374 protected virtual void HandleScript(string module, string[] parms)
375 {
376 if (parms.Length != 2)
377 {
378 Notice("Usage: command-script <path-to-script");
379 return;
380 }
381
382 RunCommandScript(parms[1]);
383 }
384
385 /// <summary>
386 /// Run an optional startup list of commands
387 /// </summary>
388 /// <param name="fileName"></param>
389 protected void RunCommandScript(string fileName)
390 {
391 if (m_console == null)
392 return;
393
394 if (File.Exists(fileName))
395 {
396 m_log.Info("[SERVER BASE]: Running " + fileName);
397
398 using (StreamReader readFile = File.OpenText(fileName))
399 {
400 string currentCommand;
401 while ((currentCommand = readFile.ReadLine()) != null)
402 {
403 currentCommand = currentCommand.Trim();
404 if (!(currentCommand == ""
405 || currentCommand.StartsWith(";")
406 || currentCommand.StartsWith("//")
407 || currentCommand.StartsWith("#")))
408 {
409 m_log.Info("[SERVER BASE]: Running '" + currentCommand + "'");
410 m_console.RunCommand(currentCommand);
411 }
412 }
413 }
414 }
43 } 415 }
44 416
45 /// <summary> 417 /// <summary>
@@ -54,5 +426,141 @@ namespace OpenSim.Framework.Servers
54 426
55 return sb.ToString(); 427 return sb.ToString();
56 } 428 }
429
430 protected void ShowInfo()
431 {
432 Notice(GetVersionText());
433 Notice("Startup directory: " + m_startupDirectory);
434 if (null != m_consoleAppender)
435 Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold));
436 }
437
438 /// <summary>
439 /// Enhance the version string with extra information if it's available.
440 /// </summary>
441 protected void EnhanceVersionInformation()
442 {
443 string buildVersion = string.Empty;
444
445 // The subversion information is deprecated and will be removed at a later date
446 // Add subversion revision information if available
447 // Try file "svn_revision" in the current directory first, then the .svn info.
448 // This allows to make the revision available in simulators not running from the source tree.
449 // FIXME: Making an assumption about the directory we're currently in - we do this all over the place
450 // elsewhere as well
451 string gitDir = "../.git/";
452 string gitRefPointerPath = gitDir + "HEAD";
453
454 string svnRevisionFileName = "svn_revision";
455 string svnFileName = ".svn/entries";
456 string manualVersionFileName = ".version";
457 string inputLine;
458 int strcmp;
459
460 if (File.Exists(manualVersionFileName))
461 {
462 using (StreamReader CommitFile = File.OpenText(manualVersionFileName))
463 buildVersion = CommitFile.ReadLine();
464
465 m_version += buildVersion ?? "";
466 }
467 else if (File.Exists(gitRefPointerPath))
468 {
469// m_log.DebugFormat("[SERVER BASE]: Found {0}", gitRefPointerPath);
470
471 string rawPointer = "";
472
473 using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
474 rawPointer = pointerFile.ReadLine();
475
476// m_log.DebugFormat("[SERVER BASE]: rawPointer [{0}]", rawPointer);
477
478 Match m = Regex.Match(rawPointer, "^ref: (.+)$");
479
480 if (m.Success)
481 {
482// m_log.DebugFormat("[SERVER BASE]: Matched [{0}]", m.Groups[1].Value);
483
484 string gitRef = m.Groups[1].Value;
485 string gitRefPath = gitDir + gitRef;
486 if (File.Exists(gitRefPath))
487 {
488// m_log.DebugFormat("[SERVER BASE]: Found gitRefPath [{0}]", gitRefPath);
489
490 using (StreamReader refFile = File.OpenText(gitRefPath))
491 {
492 string gitHash = refFile.ReadLine();
493 m_version += gitHash.Substring(0, 7);
494 }
495 }
496 }
497 }
498 else
499 {
500 // Remove the else logic when subversion mirror is no longer used
501 if (File.Exists(svnRevisionFileName))
502 {
503 StreamReader RevisionFile = File.OpenText(svnRevisionFileName);
504 buildVersion = RevisionFile.ReadLine();
505 buildVersion.Trim();
506 RevisionFile.Close();
507 }
508
509 if (string.IsNullOrEmpty(buildVersion) && File.Exists(svnFileName))
510 {
511 StreamReader EntriesFile = File.OpenText(svnFileName);
512 inputLine = EntriesFile.ReadLine();
513 while (inputLine != null)
514 {
515 // using the dir svn revision at the top of entries file
516 strcmp = String.Compare(inputLine, "dir");
517 if (strcmp == 0)
518 {
519 buildVersion = EntriesFile.ReadLine();
520 break;
521 }
522 else
523 {
524 inputLine = EntriesFile.ReadLine();
525 }
526 }
527 EntriesFile.Close();
528 }
529
530 m_version += string.IsNullOrEmpty(buildVersion) ? " " : ("." + buildVersion + " ").Substring(0, 6);
531 }
532 }
533
534 protected string GetVersionText()
535 {
536 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
537 }
538
539 /// <summary>
540 /// Console output is only possible if a console has been established.
541 /// That is something that cannot be determined within this class. So
542 /// all attempts to use the console MUST be verified.
543 /// </summary>
544 /// <param name="msg"></param>
545 protected void Notice(string msg)
546 {
547 if (m_console != null)
548 {
549 m_console.Output(msg);
550 }
551 }
552
553 /// <summary>
554 /// Console output is only possible if a console has been established.
555 /// That is something that cannot be determined within this class. So
556 /// all attempts to use the console MUST be verified.
557 /// </summary>
558 /// <param name="format"></param>
559 /// <param name="components"></param>
560 protected void Notice(string format, params object[] components)
561 {
562 if (m_console != null)
563 m_console.OutputFormat(format, components);
564 }
57 } 565 }
58} \ No newline at end of file 566} \ No newline at end of file
diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs
index 8d95c41..fc3999f 100644
--- a/OpenSim/Region/Application/ConfigurationLoader.cs
+++ b/OpenSim/Region/Application/ConfigurationLoader.cs
@@ -188,7 +188,6 @@ namespace OpenSim
188 // Make sure command line options take precedence 188 // Make sure command line options take precedence
189 m_config.Source.Merge(argvSource); 189 m_config.Source.Merge(argvSource);
190 190
191
192 IConfig enVars = m_config.Source.Configs["Environment"]; 191 IConfig enVars = m_config.Source.Configs["Environment"];
193 192
194 if( enVars != null ) 193 if( enVars != null )
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 4c4abb6..7cafc5d 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -82,8 +82,8 @@ namespace OpenSim
82 { 82 {
83 base.ReadExtraConfigSettings(); 83 base.ReadExtraConfigSettings();
84 84
85 IConfig startupConfig = m_config.Source.Configs["Startup"]; 85 IConfig startupConfig = Config.Configs["Startup"];
86 IConfig networkConfig = m_config.Source.Configs["Network"]; 86 IConfig networkConfig = Config.Configs["Network"];
87 87
88 int stpMaxThreads = 15; 88 int stpMaxThreads = 15;
89 89
@@ -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))
@@ -164,7 +148,7 @@ namespace OpenSim
164 break; 148 break;
165 case "rest": 149 case "rest":
166 m_console = new RemoteConsole("Region"); 150 m_console = new RemoteConsole("Region");
167 ((RemoteConsole)m_console).ReadConfig(m_config.Source); 151 ((RemoteConsole)m_console).ReadConfig(Config);
168 break; 152 break;
169 default: 153 default:
170 m_console = new LocalConsole("Region"); 154 m_console = new LocalConsole("Region");
@@ -174,6 +158,7 @@ namespace OpenSim
174 158
175 MainConsole.Instance = m_console; 159 MainConsole.Instance = m_console;
176 160
161 RegisterCommonAppenders(Config.Configs["Startup"]);
177 RegisterConsoleCommands(); 162 RegisterConsoleCommands();
178 163
179 base.StartupSpecific(); 164 base.StartupSpecific();
@@ -372,26 +357,6 @@ namespace OpenSim
372 "restart", 357 "restart",
373 "Restart all sims in this instance", RunCommand); 358 "Restart all sims in this instance", RunCommand);
374 359
375 m_console.Commands.AddCommand("General", false, "config set",
376 "config set <section> <key> <value>",
377 "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);
378
379 m_console.Commands.AddCommand("General", false, "config get",
380 "config get [<section>] [<key>]",
381 "Synonym for config show",
382 HandleConfig);
383
384 m_console.Commands.AddCommand("General", false, "config show",
385 "config show [<section>] [<key>]",
386 "Show config information",
387 "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
388 + "If a section is given but not a field, then all fields in that section are printed.",
389 HandleConfig);
390
391 m_console.Commands.AddCommand("General", false, "config save",
392 "config save <path>",
393 "Save current configuration to a file at the given path", HandleConfig);
394
395 m_console.Commands.AddCommand("General", false, "command-script", 360 m_console.Commands.AddCommand("General", false, "command-script",
396 "command-script <script>", 361 "command-script <script>",
397 "Run a command script from file", RunCommand); 362 "Run a command script from file", RunCommand);
@@ -502,35 +467,6 @@ namespace OpenSim
502 } 467 }
503 468
504 /// <summary> 469 /// <summary>
505 /// Run an optional startup list of commands
506 /// </summary>
507 /// <param name="fileName"></param>
508 private void RunCommandScript(string fileName)
509 {
510 if (File.Exists(fileName))
511 {
512 m_log.Info("[COMMANDFILE]: Running " + fileName);
513
514 using (StreamReader readFile = File.OpenText(fileName))
515 {
516 string currentCommand;
517 while ((currentCommand = readFile.ReadLine()) != null)
518 {
519 currentCommand = currentCommand.Trim();
520 if (!(currentCommand == ""
521 || currentCommand.StartsWith(";")
522 || currentCommand.StartsWith("//")
523 || currentCommand.StartsWith("#")))
524 {
525 m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
526 m_console.RunCommand(currentCommand);
527 }
528 }
529 }
530 }
531 }
532
533 /// <summary>
534 /// Opens a file and uses it as input to the console command parser. 470 /// Opens a file and uses it as input to the console command parser.
535 /// </summary> 471 /// </summary>
536 /// <param name="fileName">name of file to use as input to the console</param> 472 /// <param name="fileName">name of file to use as input to the console</param>
@@ -634,111 +570,9 @@ namespace OpenSim
634 bool changed = PopulateRegionEstateInfo(regInfo); 570 bool changed = PopulateRegionEstateInfo(regInfo);
635 IScene scene; 571 IScene scene;
636 CreateRegion(regInfo, true, out scene); 572 CreateRegion(regInfo, true, out scene);
637 if (changed)
638 regInfo.EstateSettings.Save();
639 }
640 573
641 /// <summary> 574 if (changed)
642 /// Change and load configuration file data. 575 regInfo.EstateSettings.Save();
643 /// </summary>
644 /// <param name="module"></param>
645 /// <param name="cmd"></param>
646 private void HandleConfig(string module, string[] cmd)
647 {
648 List<string> args = new List<string>(cmd);
649 args.RemoveAt(0);
650 string[] cmdparams = args.ToArray();
651
652 if (cmdparams.Length > 0)
653 {
654 string firstParam = cmdparams[0].ToLower();
655
656 switch (firstParam)
657 {
658 case "set":
659 if (cmdparams.Length < 4)
660 {
661 Notice("Syntax: config set <section> <key> <value>");
662 Notice("Example: config set ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
663 }
664 else
665 {
666 IConfig c;
667 IConfigSource source = new IniConfigSource();
668 c = source.AddConfig(cmdparams[1]);
669 if (c != null)
670 {
671 string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
672 c.Set(cmdparams[2], _value);
673 m_config.Source.Merge(source);
674
675 Notice("In section [{0}], set {1} = {2}", c.Name, cmdparams[2], _value);
676 }
677 }
678 break;
679
680 case "get":
681 case "show":
682 if (cmdparams.Length == 1)
683 {
684 foreach (IConfig config in m_config.Source.Configs)
685 {
686 Notice("[{0}]", config.Name);
687 string[] keys = config.GetKeys();
688 foreach (string key in keys)
689 Notice(" {0} = {1}", key, config.GetString(key));
690 }
691 }
692 else if (cmdparams.Length == 2 || cmdparams.Length == 3)
693 {
694 IConfig config = m_config.Source.Configs[cmdparams[1]];
695 if (config == null)
696 {
697 Notice("Section \"{0}\" does not exist.",cmdparams[1]);
698 break;
699 }
700 else
701 {
702 if (cmdparams.Length == 2)
703 {
704 Notice("[{0}]", config.Name);
705 foreach (string key in config.GetKeys())
706 Notice(" {0} = {1}", key, config.GetString(key));
707 }
708 else
709 {
710 Notice(
711 "config get {0} {1} : {2}",
712 cmdparams[1], cmdparams[2], config.GetString(cmdparams[2]));
713 }
714 }
715 }
716 else
717 {
718 Notice("Syntax: config {0} [<section>] [<key>]", firstParam);
719 Notice("Example: config {0} ScriptEngine.DotNetEngine NumberOfScriptThreads", firstParam);
720 }
721
722 break;
723
724 case "save":
725 if (cmdparams.Length < 2)
726 {
727 Notice("Syntax: config save <path>");
728 return;
729 }
730
731 if (Application.iniFilePath == cmdparams[1])
732 {
733 Notice("Path can not be " + Application.iniFilePath);
734 return;
735 }
736
737 Notice("Saving configuration file: " + cmdparams[1]);
738 m_config.Save(cmdparams[1]);
739 break;
740 }
741 }
742 } 576 }
743 577
744 /// <summary> 578 /// <summary>
@@ -787,13 +621,6 @@ namespace OpenSim
787 621
788 switch (command) 622 switch (command)
789 { 623 {
790 case "command-script":
791 if (cmdparams.Length > 0)
792 {
793 RunCommandScript(cmdparams[0]);
794 }
795 break;
796
797 case "backup": 624 case "backup":
798 MainConsole.Instance.Output("Triggering save of pending object updates to persistent store"); 625 MainConsole.Instance.Output("Triggering save of pending object updates to persistent store");
799 SceneManager.BackupCurrentScene(); 626 SceneManager.BackupCurrentScene();
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 7bef1aa..eb4326e 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -104,13 +104,7 @@ namespace OpenSim
104 /// <value> 104 /// <value>
105 /// The config information passed into the OpenSimulator region server. 105 /// The config information passed into the OpenSimulator region server.
106 /// </value> 106 /// </value>
107 public OpenSimConfigSource ConfigSource 107 public OpenSimConfigSource ConfigSource { get; private set; }
108 {
109 get { return m_config; }
110 set { m_config = value; }
111 }
112
113 protected OpenSimConfigSource m_config;
114 108
115 public List<IClientNetworkServer> ClientServers 109 public List<IClientNetworkServer> ClientServers
116 { 110 {
@@ -150,13 +144,14 @@ namespace OpenSim
150 protected virtual void LoadConfigSettings(IConfigSource configSource) 144 protected virtual void LoadConfigSettings(IConfigSource configSource)
151 { 145 {
152 m_configLoader = new ConfigurationLoader(); 146 m_configLoader = new ConfigurationLoader();
153 m_config = m_configLoader.LoadConfigSettings(configSource, envConfigSource, out m_configSettings, out m_networkServersInfo); 147 ConfigSource = m_configLoader.LoadConfigSettings(configSource, envConfigSource, out m_configSettings, out m_networkServersInfo);
148 Config = ConfigSource.Source;
154 ReadExtraConfigSettings(); 149 ReadExtraConfigSettings();
155 } 150 }
156 151
157 protected virtual void ReadExtraConfigSettings() 152 protected virtual void ReadExtraConfigSettings()
158 { 153 {
159 IConfig networkConfig = m_config.Source.Configs["Network"]; 154 IConfig networkConfig = Config.Configs["Network"];
160 if (networkConfig != null) 155 if (networkConfig != null)
161 { 156 {
162 proxyUrl = networkConfig.GetString("proxy_url", ""); 157 proxyUrl = networkConfig.GetString("proxy_url", "");
@@ -189,7 +184,7 @@ namespace OpenSim
189 /// </summary> 184 /// </summary>
190 protected override void StartupSpecific() 185 protected override void StartupSpecific()
191 { 186 {
192 IConfig startupConfig = m_config.Source.Configs["Startup"]; 187 IConfig startupConfig = Config.Configs["Startup"];
193 if (startupConfig != null) 188 if (startupConfig != null)
194 { 189 {
195 string pidFile = startupConfig.GetString("PIDFile", String.Empty); 190 string pidFile = startupConfig.GetString("PIDFile", String.Empty);
@@ -205,7 +200,7 @@ namespace OpenSim
205 } 200 }
206 201
207 // Load the simulation data service 202 // Load the simulation data service
208 IConfig simDataConfig = m_config.Source.Configs["SimulationDataStore"]; 203 IConfig simDataConfig = Config.Configs["SimulationDataStore"];
209 if (simDataConfig == null) 204 if (simDataConfig == null)
210 throw new Exception("Configuration file is missing the [SimulationDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?"); 205 throw new Exception("Configuration file is missing the [SimulationDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?");
211 206
@@ -213,7 +208,7 @@ namespace OpenSim
213 if (String.IsNullOrEmpty(module)) 208 if (String.IsNullOrEmpty(module))
214 throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [SimulationDataStore] section."); 209 throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [SimulationDataStore] section.");
215 210
216 m_simulationDataService = ServerUtils.LoadPlugin<ISimulationDataService>(module, new object[] { m_config.Source }); 211 m_simulationDataService = ServerUtils.LoadPlugin<ISimulationDataService>(module, new object[] { Config });
217 if (m_simulationDataService == null) 212 if (m_simulationDataService == null)
218 throw new Exception( 213 throw new Exception(
219 string.Format( 214 string.Format(
@@ -221,7 +216,7 @@ namespace OpenSim
221 module)); 216 module));
222 217
223 // Load the estate data service 218 // Load the estate data service
224 IConfig estateDataConfig = m_config.Source.Configs["EstateDataStore"]; 219 IConfig estateDataConfig = Config.Configs["EstateDataStore"];
225 if (estateDataConfig == null) 220 if (estateDataConfig == null)
226 throw new Exception("Configuration file is missing the [EstateDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?"); 221 throw new Exception("Configuration file is missing the [EstateDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?");
227 222
@@ -229,7 +224,7 @@ namespace OpenSim
229 if (String.IsNullOrEmpty(module)) 224 if (String.IsNullOrEmpty(module))
230 throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] section"); 225 throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] section");
231 226
232 m_estateDataService = ServerUtils.LoadPlugin<IEstateDataService>(module, new object[] { m_config.Source }); 227 m_estateDataService = ServerUtils.LoadPlugin<IEstateDataService>(module, new object[] { Config });
233 if (m_estateDataService == null) 228 if (m_estateDataService == null)
234 throw new Exception( 229 throw new Exception(
235 string.Format( 230 string.Format(
@@ -257,7 +252,7 @@ namespace OpenSim
257 } 252 }
258 } 253 }
259 254
260 protected virtual void AddPluginCommands(CommandConsole console) 255 protected virtual void AddPluginCommands(ICommandConsole console)
261 { 256 {
262 List<string> topics = GetHelpTopics(); 257 List<string> topics = GetHelpTopics();
263 258
@@ -384,7 +379,7 @@ namespace OpenSim
384 } 379 }
385 380
386 IClientNetworkServer clientServer; 381 IClientNetworkServer clientServer;
387 Scene scene = SetupScene(regionInfo, proxyOffset, m_config.Source, out clientServer); 382 Scene scene = SetupScene(regionInfo, proxyOffset, Config, out clientServer);
388 383
389 m_log.Info("[MODULES]: Loading Region's modules (old style)"); 384 m_log.Info("[MODULES]: Loading Region's modules (old style)");
390 385
@@ -530,10 +525,10 @@ namespace OpenSim
530 string estateOwnerPassword = null; 525 string estateOwnerPassword = null;
531 string rawEstateOwnerUuid = null; 526 string rawEstateOwnerUuid = null;
532 527
533 if (m_config.Source.Configs[ESTATE_SECTION_NAME] != null) 528 if (Config.Configs[ESTATE_SECTION_NAME] != null)
534 { 529 {
535 string defaultEstateOwnerName 530 string defaultEstateOwnerName
536 = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerName", "").Trim(); 531 = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerName", "").Trim();
537 string[] ownerNames = defaultEstateOwnerName.Split(' '); 532 string[] ownerNames = defaultEstateOwnerName.Split(' ');
538 533
539 if (ownerNames.Length >= 2) 534 if (ownerNames.Length >= 2)
@@ -543,9 +538,9 @@ namespace OpenSim
543 } 538 }
544 539
545 // Info to be used only on Standalone Mode 540 // Info to be used only on Standalone Mode
546 rawEstateOwnerUuid = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerUUID", null); 541 rawEstateOwnerUuid = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerUUID", null);
547 estateOwnerEMail = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerEMail", null); 542 estateOwnerEMail = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerEMail", null);
548 estateOwnerPassword = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerPassword", null); 543 estateOwnerPassword = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerPassword", null);
549 } 544 }
550 545
551 MainConsole.Instance.OutputFormat("Estate {0} has no owner set.", regionInfo.EstateSettings.EstateName); 546 MainConsole.Instance.OutputFormat("Estate {0} has no owner set.", regionInfo.EstateSettings.EstateName);
@@ -797,7 +792,7 @@ namespace OpenSim
797 return new Scene( 792 return new Scene(
798 regionInfo, circuitManager, sceneGridService, 793 regionInfo, circuitManager, sceneGridService,
799 simDataService, estateDataService, false, 794 simDataService, estateDataService, false,
800 m_config.Source, m_version); 795 Config, m_version);
801 } 796 }
802 797
803 protected void ShutdownClientServer(RegionInfo whichRegion) 798 protected void ShutdownClientServer(RegionInfo whichRegion)
@@ -838,7 +833,7 @@ namespace OpenSim
838 protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier) 833 protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier)
839 { 834 {
840 return GetPhysicsScene( 835 return GetPhysicsScene(
841 m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, m_config.Source, osSceneIdentifier); 836 m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, Config, osSceneIdentifier);
842 } 837 }
843 838
844 /// <summary> 839 /// <summary>
@@ -1075,9 +1070,9 @@ namespace OpenSim
1075 1070
1076 string defaultEstateName = null; 1071 string defaultEstateName = null;
1077 1072
1078 if (m_config.Source.Configs[ESTATE_SECTION_NAME] != null) 1073 if (Config.Configs[ESTATE_SECTION_NAME] != null)
1079 { 1074 {
1080 defaultEstateName = m_config.Source.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateName", null); 1075 defaultEstateName = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateName", null);
1081 1076
1082 if (defaultEstateName != null) 1077 if (defaultEstateName != null)
1083 { 1078 {
@@ -1160,28 +1155,14 @@ namespace OpenSim
1160 MainConsole.Instance.Output("Joining the estate failed. Please try again."); 1155 MainConsole.Instance.Output("Joining the estate failed. Please try again.");
1161 } 1156 }
1162 } 1157 }
1163 } 1158 }
1164 1159
1165 return true; // need to update the database 1160 return true; // need to update the database
1166 } 1161 }
1167 } 1162 }
1168 1163
1169 public class OpenSimConfigSource 1164 public class OpenSimConfigSource
1170 { 1165 {
1171 public IConfigSource Source; 1166 public IConfigSource Source;
1172
1173 public void Save(string path)
1174 {
1175 if (Source is IniConfigSource)
1176 {
1177 IniConfigSource iniCon = (IniConfigSource) Source;
1178 iniCon.Save(path);
1179 }
1180 else if (Source is XmlConfigSource)
1181 {
1182 XmlConfigSource xmlCon = (XmlConfigSource) Source;
1183 xmlCon.Save(path);
1184 }
1185 }
1186 } 1167 }
1187} 1168} \ No newline at end of file
diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs
index 29b1c00..954783c 100644
--- a/OpenSim/Server/Base/HttpServerBase.cs
+++ b/OpenSim/Server/Base/HttpServerBase.cs
@@ -52,7 +52,7 @@ namespace OpenSim.Server.Base
52 52
53 protected override void ReadConfig() 53 protected override void ReadConfig()
54 { 54 {
55 IConfig networkConfig = m_Config.Configs["Network"]; 55 IConfig networkConfig = Config.Configs["Network"];
56 56
57 if (networkConfig == null) 57 if (networkConfig == null)
58 { 58 {
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs
index 56bb7ae..5b23149 100644
--- a/OpenSim/Server/Base/ServicesServerBase.cs
+++ b/OpenSim/Server/Base/ServicesServerBase.cs
@@ -56,23 +56,10 @@ namespace OpenSim.Server.Base
56 // 56 //
57 protected string[] m_Arguments; 57 protected string[] m_Arguments;
58 58
59 // Configuration
60 //
61 protected IConfigSource m_Config = null;
62
63 public IConfigSource Config
64 {
65 get { return m_Config; }
66 }
67
68 // Run flag 59 // Run flag
69 // 60 //
70 private bool m_Running = true; 61 private bool m_Running = true;
71 62
72 // PID file
73 //
74 private string m_pidFile = String.Empty;
75
76 // Handle all the automagical stuff 63 // Handle all the automagical stuff
77 // 64 //
78 public ServicesServerBase(string prompt, string[] args) : base() 65 public ServicesServerBase(string prompt, string[] args) : base()
@@ -122,11 +109,11 @@ namespace OpenSim.Server.Base
122 configUri.Scheme == Uri.UriSchemeHttp) 109 configUri.Scheme == Uri.UriSchemeHttp)
123 { 110 {
124 XmlReader r = XmlReader.Create(iniFile); 111 XmlReader r = XmlReader.Create(iniFile);
125 m_Config = new XmlConfigSource(r); 112 Config = new XmlConfigSource(r);
126 } 113 }
127 else 114 else
128 { 115 {
129 m_Config = new IniConfigSource(iniFile); 116 Config = new IniConfigSource(iniFile);
130 } 117 }
131 } 118 }
132 catch (Exception e) 119 catch (Exception e)
@@ -138,13 +125,13 @@ namespace OpenSim.Server.Base
138 // Merge the configuration from the command line into the 125 // Merge the configuration from the command line into the
139 // loaded file 126 // loaded file
140 // 127 //
141 m_Config.Merge(argvConfig); 128 Config.Merge(argvConfig);
142 129
143 // Refresh the startupConfig post merge 130 // Refresh the startupConfig post merge
144 // 131 //
145 if (m_Config.Configs["Startup"] != null) 132 if (Config.Configs["Startup"] != null)
146 { 133 {
147 startupConfig = m_Config.Configs["Startup"]; 134 startupConfig = Config.Configs["Startup"];
148 } 135 }
149 136
150 prompt = startupConfig.GetString("Prompt", prompt); 137 prompt = startupConfig.GetString("Prompt", prompt);
@@ -174,6 +161,8 @@ namespace OpenSim.Server.Base
174 MainConsole.Instance = new LocalConsole(prompt); 161 MainConsole.Instance = new LocalConsole(prompt);
175 } 162 }
176 163
164 m_console = MainConsole.Instance;
165
177 // Configure the appenders for log4net 166 // Configure the appenders for log4net
178 // 167 //
179 OpenSimAppender consoleAppender = null; 168 OpenSimAppender consoleAppender = null;
@@ -189,54 +178,15 @@ namespace OpenSim.Server.Base
189 XmlConfigurator.Configure(); 178 XmlConfigurator.Configure();
190 } 179 }
191 180
192 ILoggerRepository repository = LogManager.GetRepository(); 181 RegisterCommonAppenders(startupConfig);
193 IAppender[] appenders = repository.GetAppenders();
194
195 foreach (IAppender appender in appenders)
196 {
197 if (appender.Name == "Console")
198 {
199 consoleAppender = (OpenSimAppender)appender;
200 }
201 if (appender.Name == "LogFileAppender")
202 {
203 fileAppender = (FileAppender)appender;
204 }
205 }
206
207 if (consoleAppender == null)
208 {
209 System.Console.WriteLine("No console appender found. Server can't start");
210 Thread.CurrentThread.Abort();
211 }
212 else
213 {
214 consoleAppender.Console = (ConsoleBase)MainConsole.Instance;
215
216 if (null == consoleAppender.Threshold)
217 consoleAppender.Threshold = Level.All;
218 }
219
220 // Set log file
221 //
222 if (fileAppender != null)
223 {
224 if (startupConfig != null)
225 {
226 string cfgFileName = startupConfig.GetString("logfile", null);
227 if (cfgFileName != null)
228 {
229 fileAppender.File = cfgFileName;
230 fileAppender.ActivateOptions();
231 }
232 }
233 }
234 182
235 if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) 183 if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
236 { 184 {
237 CreatePIDFile(startupConfig.GetString("PIDFile")); 185 CreatePIDFile(startupConfig.GetString("PIDFile"));
238 } 186 }
239 187
188 RegisterCommonCommands();
189
240 // Register the quit command 190 // Register the quit command
241 // 191 //
242 MainConsole.Instance.Commands.AddCommand("General", false, "quit", 192 MainConsole.Instance.Commands.AddCommand("General", false, "quit",
@@ -246,16 +196,6 @@ namespace OpenSim.Server.Base
246 MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", 196 MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
247 "shutdown", 197 "shutdown",
248 "Quit the application", HandleQuit); 198 "Quit the application", HandleQuit);
249
250 // Register a command to read other commands from a file
251 MainConsole.Instance.Commands.AddCommand("General", false, "command-script",
252 "command-script <script>",
253 "Run a command script from file", HandleScript);
254
255 MainConsole.Instance.Commands.AddCommand("General", false, "show uptime",
256 "show uptime",
257 "Show server uptime", HandleShow);
258
259 199
260 // Allow derived classes to perform initialization that 200 // Allow derived classes to perform initialization that
261 // needs to be done after the console has opened 201 // needs to be done after the console has opened
@@ -282,8 +222,8 @@ namespace OpenSim.Server.Base
282 } 222 }
283 } 223 }
284 224
285 if (m_pidFile != String.Empty) 225 RemovePIDFile();
286 File.Delete(m_pidFile); 226
287 return 0; 227 return 0;
288 } 228 }
289 229
@@ -291,43 +231,9 @@ namespace OpenSim.Server.Base
291 { 231 {
292 m_Running = false; 232 m_Running = false;
293 m_log.Info("[CONSOLE] Quitting"); 233 m_log.Info("[CONSOLE] Quitting");
294 }
295 234
296 protected virtual void HandleScript(string module, string[] parms)
297 {
298 if (parms.Length != 2)
299 {
300 return;
301 }
302 RunCommandScript(parms[1]);
303 } 235 }
304 236
305 /// <summary>
306 /// Run an optional startup list of commands
307 /// </summary>
308 /// <param name="fileName"></param>
309 private void RunCommandScript(string fileName)
310 {
311 if (File.Exists(fileName))
312 {
313 m_log.Info("[COMMANDFILE]: Running " + fileName);
314
315 using (StreamReader readFile = File.OpenText(fileName))
316 {
317 string currentCommand;
318 while ((currentCommand = readFile.ReadLine()) != null)
319 {
320 if (currentCommand != String.Empty)
321 {
322 m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
323 MainConsole.Instance.RunCommand(currentCommand);
324 }
325 }
326 }
327 }
328 }
329
330
331 protected virtual void ReadConfig() 237 protected virtual void ReadConfig()
332 { 238 {
333 } 239 }
@@ -335,37 +241,5 @@ namespace OpenSim.Server.Base
335 protected virtual void Initialise() 241 protected virtual void Initialise()
336 { 242 {
337 } 243 }
338
339 protected void CreatePIDFile(string path)
340 {
341 try
342 {
343 string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
344 FileStream fs = File.Create(path);
345 Byte[] buf = Encoding.ASCII.GetBytes(pidstring);
346 fs.Write(buf, 0, buf.Length);
347 fs.Close();
348 m_pidFile = path;
349 }
350 catch (Exception)
351 {
352 }
353 }
354
355 public virtual void HandleShow(string module, string[] cmd)
356 {
357 List<string> args = new List<string>(cmd);
358
359 args.RemoveAt(0);
360
361 string[] showParams = args.ToArray();
362
363 switch (showParams[0])
364 {
365 case "uptime":
366 MainConsole.Instance.Output(GetUptimeReport());
367 break;
368 }
369 }
370 } 244 }
371} \ No newline at end of file 245} \ No newline at end of file
diff --git a/prebuild.xml b/prebuild.xml
index e13ce8b..d99da2b 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -446,6 +446,7 @@
446 <Reference name="XMLRPC" path="../../../bin/"/> 446 <Reference name="XMLRPC" path="../../../bin/"/>
447 <Reference name="log4net" path="../../../bin/"/> 447 <Reference name="log4net" path="../../../bin/"/>
448 <Reference name="HttpServer_OpenSim" path="../../../bin/"/> 448 <Reference name="HttpServer_OpenSim" path="../../../bin/"/>
449 <Reference name="Nini" path="../../../bin/"/>
449 450
450 <Files> 451 <Files>
451 <Match pattern="*.cs" recurse="false"> 452 <Match pattern="*.cs" recurse="false">