29 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Threading;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Console;
37 using OpenSim.Framework.Monitoring;
38 using OpenSim.Framework.Servers;
41 using log4net.Appender;
43 using log4net.Repository;
46 namespace OpenSim.Server.Base
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 public string ConfigDirectory
66 private bool m_Running =
true;
76 ArgvConfigSource argvConfig =
new ArgvConfigSource(args);
78 argvConfig.AddSwitch(
"Startup",
"console",
"c");
79 argvConfig.AddSwitch(
"Startup",
"logfile",
"l");
80 argvConfig.AddSwitch(
"Startup",
"inifile",
"i");
81 argvConfig.AddSwitch(
"Startup",
"prompt",
"p");
82 argvConfig.AddSwitch(
"Startup",
"logconfig",
"g");
86 if (Assembly.GetEntryAssembly() != null)
87 fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly()
.Location);
88 string iniFile = fileName +
".ini";
89 string logConfig = null;
91 IConfig startupConfig = argvConfig.Configs[
"Startup"];
92 if (startupConfig != null)
95 iniFile = startupConfig.GetString(
"inifile", iniFile);
98 prompt = startupConfig.GetString(
"prompt", prompt);
101 logConfig =startupConfig.GetString(
"logconfig", logConfig);
110 if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) &&
111 configUri.Scheme == Uri.UriSchemeHttp)
113 XmlReader r = XmlReader.Create(iniFile);
114 Config =
new XmlConfigSource(r);
118 Config =
new IniConfigSource(iniFile);
123 System.Console.WriteLine(
"Error reading from config source. {0}", e.Message);
128 m_log.Info(
"[CONFIG]: Loading environment variables for Config");
129 Util.MergeEnvironmentToConfig(Config);
132 Config.Merge(argvConfig);
134 Config.ReplaceKeyValues();
137 if (Config.Configs[
"Startup"] != null)
139 startupConfig = Config.Configs[
"Startup"];
142 ConfigDirectory = startupConfig.GetString(
"ConfigDirectory",
".");
144 prompt = startupConfig.GetString(
"Prompt", prompt);
150 string consoleType =
"local";
151 if (startupConfig != null)
152 consoleType = startupConfig.GetString(
"console", consoleType);
154 if (consoleType ==
"basic")
158 else if (consoleType ==
"rest")
163 else if (consoleType ==
"mock")
167 else if (consoleType ==
"local")
169 MainConsole.Instance =
new LocalConsole(prompt, startupConfig);
172 m_console = MainConsole.Instance;
174 if (logConfig != null)
176 FileInfo cfg =
new FileInfo(logConfig);
177 XmlConfigurator.Configure(cfg);
181 XmlConfigurator.Configure();
184 LogEnvironmentInformation();
185 RegisterCommonAppenders(startupConfig);
187 if (startupConfig.GetString(
"PIDFile", String.Empty) != String.Empty)
189 CreatePIDFile(startupConfig.GetString(
"PIDFile"));
192 RegisterCommonCommands();
193 RegisterCommonComponents(Config);
202 get {
return m_Running; }
207 Watchdog.Enabled =
true;
208 MemoryWatchdog.Enabled =
true;
214 MainConsole.Instance.Prompt();
218 m_log.ErrorFormat(
"Command error: {0}", e);
230 m_log.Info(
"[CONSOLE] Quitting");
232 base.ShutdownSpecific();
virtual void Initialise()
virtual void ReadConfig()
static ICommandConsole Instance
This is a Fake console that's used when setting up the Scene in Unit Tests Don't use this except for ...
override void ShutdownSpecific()
Should be overriden and referenced by descendents if they need to perform extra shutdown processing ...
A console that uses cursor control and color
A console that processes commands internally
ServicesServerBase(string prompt, string[] args)