29 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Threading;
36 using OpenSim.Framework;
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
73 IConfigSource argvSource, EnvConfigSource envConfigSource, out
ConfigSettings configSettings,
79 bool iniFileExists =
false;
81 IConfig startupConfig = argvSource.Configs[
"Startup"];
83 List<string> sources =
new List<string>();
85 string masterFileName = startupConfig.GetString(
"inimaster",
"OpenSimDefaults.ini");
87 if (masterFileName ==
"none")
88 masterFileName = String.Empty;
90 if (IsUri(masterFileName))
92 if (!sources.Contains(masterFileName))
93 sources.Add(masterFileName);
97 string masterFilePath = Path.GetFullPath(
98 Path.Combine(Util.configDir(), masterFileName));
100 if (masterFileName != String.Empty)
102 if (
File.Exists(masterFilePath))
104 if (!sources.Contains(masterFilePath))
105 sources.Add(masterFilePath);
109 m_log.ErrorFormat(
"Master ini file {0} not found", Path.GetFullPath(masterFilePath));
115 string iniFileName = startupConfig.GetString(
"inifile",
"OpenSim.ini");
117 if (IsUri(iniFileName))
119 if (!sources.Contains(iniFileName))
120 sources.Add(iniFileName);
121 Application.iniFilePath = iniFileName;
125 Application.iniFilePath = Path.GetFullPath(
126 Path.Combine(Util.configDir(), iniFileName));
130 iniFileName =
"OpenSim.xml";
131 Application.iniFilePath = Path.GetFullPath(Path.Combine(Util.configDir(), iniFileName));
142 m_config.Source =
new IniConfigSource();
143 m_config.Source.Merge(DefaultConfig());
145 m_log.Info(
"[CONFIG]: Reading configuration settings");
147 for (
int i = 0 ; i < sources.Count ; i++)
149 if (ReadConfig(
m_config, sources[i]))
151 iniFileExists =
true;
157 string iniDirName = startupConfig.GetString(
"inidirectory",
"config");
158 string iniDirPath = Path.Combine(Util.configDir(), iniDirName);
160 if (Directory.Exists(iniDirPath))
162 m_log.InfoFormat(
"[CONFIG]: Searching folder {0} for config ini files", iniDirPath);
163 List<string> overrideSources =
new List<string>();
165 string[] fileEntries = Directory.GetFiles(iniDirName);
166 foreach (
string filePath
in fileEntries)
168 if (Path.GetExtension(filePath).ToLower() ==
".ini")
170 if (!sources.Contains(Path.GetFullPath(filePath)))
172 overrideSources.Add(Path.GetFullPath(filePath));
174 sources.Add(Path.GetFullPath(filePath));
180 if (overrideSources.Count > 0)
183 overrideConfig.Source =
new IniConfigSource();
185 for (
int i = 0 ; i < overrideSources.Count ; i++)
187 if (ReadConfig(overrideConfig, overrideSources[i]))
189 iniFileExists =
true;
190 AddIncludes(overrideConfig, overrideSources);
193 m_config.Source.Merge(overrideConfig.Source);
197 if (sources.Count == 0)
199 m_log.FatalFormat(
"[CONFIG]: Could not load any configuration");
202 else if (!iniFileExists)
204 m_log.FatalFormat(
"[CONFIG]: Could not load any configuration");
205 m_log.FatalFormat(
"[CONFIG]: Configuration exists, but there was an error loading it!");
210 m_log.Info(
"[CONFIG]: Loading environment variables for Config");
211 Util.MergeEnvironmentToConfig(m_config.Source);
214 m_config.Source.Merge(argvSource);
216 m_config.Source.ReplaceKeyValues();
230 foreach (IConfig config
in configSource.
Source.Configs)
233 string[] keys = config.GetKeys();
234 foreach (
string k
in keys)
236 if (k.StartsWith(
"Include-"))
239 string file = config.GetString(k);
242 if (!sources.Contains(file))
247 string basepath = Path.GetFullPath(Util.configDir());
249 string chunkWithoutWildcards = file;
250 string chunkWithWildcards = string.Empty;
251 int wildcardIndex = file.IndexOfAny(
new char[] {
'*',
'?' });
252 if (wildcardIndex != -1)
254 chunkWithoutWildcards = file.Substring(0, wildcardIndex);
255 chunkWithWildcards = file.Substring(wildcardIndex);
257 string path = Path.Combine(basepath, chunkWithoutWildcards);
258 path = Path.GetFullPath(path) + chunkWithWildcards;
259 string[] paths = Util.Glob(path);
262 if (wildcardIndex == -1 && paths.Length == 0)
264 m_log.WarnFormat(
"[CONFIG]: Could not find include file {0}", path);
268 foreach (
string p
in paths)
270 if (!sources.Contains(p))
284 bool IsUri(
string file)
288 return Uri.TryCreate(file, UriKind.Absolute,
289 out configUri) && configUri.Scheme == Uri.UriSchemeHttp;
297 private bool ReadConfig(OpenSimConfigSource configSource,
string iniPath)
299 bool success =
false;
303 m_log.InfoFormat(
"[CONFIG]: Reading configuration file {0}", Path.GetFullPath(iniPath));
305 configSource.Source.Merge(
new IniConfigSource(iniPath));
310 m_log.InfoFormat(
"[CONFIG]: {0} is a http:// URI, fetching ...", iniPath);
316 XmlReader r = XmlReader.Create(iniPath);
317 XmlConfigSource cs =
new XmlConfigSource(r);
318 configSource.Source.Merge(cs);
324 m_log.FatalFormat(
"[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath);
335 private static IConfigSource DefaultConfig()
337 IConfigSource defaultConfig =
new IniConfigSource();
340 IConfig config = defaultConfig.Configs[
"Startup"];
343 config = defaultConfig.AddConfig(
"Startup");
345 config.Set(
"region_info_source",
"filesystem");
347 config.Set(
"physics",
"OpenDynamicsEngine");
348 config.Set(
"meshing",
"Meshmerizer");
349 config.Set(
"physical_prim",
true);
350 config.Set(
"serverside_object_permissions",
true);
351 config.Set(
"storage_prim_inventories",
true);
352 config.Set(
"startup_console_commands_file", String.Empty);
353 config.Set(
"shutdown_console_commands_file", String.Empty);
354 config.Set(
"DefaultScriptEngine",
"XEngine");
355 config.Set(
"clientstack_plugin",
"OpenSim.Region.ClientStack.LindenUDP.dll");
357 config.Set(
"EventQueue",
true);
361 IConfig config = defaultConfig.Configs[
"Network"];
364 config = defaultConfig.AddConfig(
"Network");
366 config.Set(
"http_listener_port", ConfigSettings.DefaultRegionHttpPort);
369 return defaultConfig;
377 IConfig startupConfig = m_config.Source.Configs[
"Startup"];
378 if (startupConfig != null)
380 m_configSettings.PhysicsEngine = startupConfig.GetString(
"physics");
381 m_configSettings.MeshEngineName = startupConfig.GetString(
"meshing");
383 m_configSettings.ClientstackDll
384 = startupConfig.GetString(
"clientstack_plugin",
"OpenSim.Region.ClientStack.LindenUDP.dll");
387 m_networkServersInfo.loadFromConfiguration(m_config.Source);
Loads the Configuration files into nIni
virtual void ReadConfigSettings()
Read initial region settings from the ConfigSource
ConfigSettings m_configSettings
Various Config settings the region needs to start Physics Engine, Mesh Engine, GridMode, PhysicsPrim allowed, Neighbor, StorageDLL, Storage Connection String, Estate connection String, Client Stack Standalone settings.
Starting class for the OpenSimulator Region
NetworkServersInfo m_networkServersInfo
Grid Service Information. This refers to classes and addresses of the grid service ...
OpenSimConfigSource LoadConfigSettings(IConfigSource argvSource, EnvConfigSource envConfigSource, out ConfigSettings configSettings, out NetworkServersInfo networkInfo)
Loads the region configuration
OpenSimConfigSource m_config
A source of Configuration data
static string iniFilePath
Path to the main ini Configuration file