diff options
author | onefang | 2019-05-19 21:24:15 +1000 |
---|---|---|
committer | onefang | 2019-05-19 21:24:15 +1000 |
commit | 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch) | |
tree | a9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Server/Base/ServicesServerBase.cs | |
parent | Add a build script. (diff) | |
download | opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2 opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz |
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Server/Base/ServicesServerBase.cs')
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 202 |
1 files changed, 172 insertions, 30 deletions
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 076868d..176e876 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs | |||
@@ -55,16 +55,16 @@ namespace OpenSim.Server.Base | |||
55 | // | 55 | // |
56 | protected string[] m_Arguments; | 56 | protected string[] m_Arguments; |
57 | 57 | ||
58 | public string ConfigDirectory | 58 | protected string m_configDirectory = "."; |
59 | { | ||
60 | get; | ||
61 | private set; | ||
62 | } | ||
63 | 59 | ||
64 | // Run flag | 60 | // Run flag |
65 | // | 61 | // |
66 | private bool m_Running = true; | 62 | private bool m_Running = true; |
67 | 63 | ||
64 | #if (_MONO) | ||
65 | private static Mono.Unix.UnixSignal[] signals; | ||
66 | #endif | ||
67 | |||
68 | // Handle all the automagical stuff | 68 | // Handle all the automagical stuff |
69 | // | 69 | // |
70 | public ServicesServerBase(string prompt, string[] args) : base() | 70 | public ServicesServerBase(string prompt, string[] args) : base() |
@@ -85,7 +85,7 @@ namespace OpenSim.Server.Base | |||
85 | string fileName = ""; | 85 | string fileName = ""; |
86 | if (Assembly.GetEntryAssembly() != null) | 86 | if (Assembly.GetEntryAssembly() != null) |
87 | fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location); | 87 | fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location); |
88 | string iniFile = "../config/" + fileName + ".ini"; | 88 | string iniFile = fileName + ".ini"; |
89 | string logConfig = null; | 89 | string logConfig = null; |
90 | 90 | ||
91 | IConfig startupConfig = argvConfig.Configs["Startup"]; | 91 | IConfig startupConfig = argvConfig.Configs["Startup"]; |
@@ -96,39 +96,31 @@ namespace OpenSim.Server.Base | |||
96 | 96 | ||
97 | // Check if a prompt was given on the command line | 97 | // Check if a prompt was given on the command line |
98 | prompt = startupConfig.GetString("prompt", prompt); | 98 | prompt = startupConfig.GetString("prompt", prompt); |
99 | 99 | ||
100 | // Check for a Log4Net config file on the command line | 100 | // Check for a Log4Net config file on the command line |
101 | logConfig =startupConfig.GetString("logconfig", logConfig); | 101 | logConfig =startupConfig.GetString("logconfig", logConfig); |
102 | } | 102 | } |
103 | 103 | ||
104 | // Find out of the file name is a URI and remote load it if possible. | 104 | Config = ReadConfigSource(iniFile); |
105 | // Load it as a local file otherwise. | ||
106 | Uri configUri; | ||
107 | 105 | ||
108 | try | 106 | List<string> sources = new List<string>(); |
107 | sources.Add(iniFile); | ||
108 | |||
109 | int sourceIndex = 1; | ||
110 | |||
111 | while (AddIncludes(Config, sources)) | ||
109 | { | 112 | { |
110 | if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && | 113 | for ( ; sourceIndex < sources.Count ; ++sourceIndex) |
111 | configUri.Scheme == Uri.UriSchemeHttp) | ||
112 | { | 114 | { |
113 | XmlReader r = XmlReader.Create(iniFile); | 115 | IConfigSource s = ReadConfigSource(sources[sourceIndex]); |
114 | Config = new XmlConfigSource(r); | 116 | Config.Merge(s); |
115 | } | 117 | } |
116 | else | ||
117 | { | ||
118 | Config = new IniConfigSource(iniFile); | ||
119 | } | ||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | System.Console.WriteLine("Error reading from config source. {0}", e.Message); | ||
124 | System.Diagnostics.Process.GetCurrentProcess().Kill(); | ||
125 | ///// Environment.Exit(1); | ||
126 | } | 118 | } |
127 | 119 | ||
128 | // Merge OpSys env vars | 120 | // Merge OpSys env vars |
129 | m_log.Info("[CONFIG]: Loading environment variables for Config"); | 121 | Console.WriteLine("[CONFIG]: Loading environment variables for Config"); |
130 | Util.MergeEnvironmentToConfig(Config); | 122 | Util.MergeEnvironmentToConfig(Config); |
131 | 123 | ||
132 | // Merge the configuration from the command line into the loaded file | 124 | // Merge the configuration from the command line into the loaded file |
133 | Config.Merge(argvConfig); | 125 | Config.Merge(argvConfig); |
134 | 126 | ||
@@ -140,10 +132,12 @@ namespace OpenSim.Server.Base | |||
140 | startupConfig = Config.Configs["Startup"]; | 132 | startupConfig = Config.Configs["Startup"]; |
141 | } | 133 | } |
142 | 134 | ||
143 | ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); | 135 | if (startupConfig != null) |
144 | 136 | { | |
145 | prompt = startupConfig.GetString("Prompt", prompt); | 137 | m_configDirectory = startupConfig.GetString("ConfigDirectory", m_configDirectory); |
146 | 138 | ||
139 | prompt = startupConfig.GetString("Prompt", prompt); | ||
140 | } | ||
147 | // Allow derived classes to load config before the console is opened. | 141 | // Allow derived classes to load config before the console is opened. |
148 | ReadConfig(); | 142 | ReadConfig(); |
149 | 143 | ||
@@ -193,6 +187,42 @@ namespace OpenSim.Server.Base | |||
193 | RegisterCommonCommands(); | 187 | RegisterCommonCommands(); |
194 | RegisterCommonComponents(Config); | 188 | RegisterCommonComponents(Config); |
195 | 189 | ||
190 | #if (_MONO) | ||
191 | Thread signal_thread = new Thread (delegate () | ||
192 | { | ||
193 | while (true) | ||
194 | { | ||
195 | // Wait for a signal to be delivered | ||
196 | int index = Mono.Unix.UnixSignal.WaitAny (signals, -1); | ||
197 | |||
198 | //Mono.Unix.Native.Signum signal = signals [index].Signum; | ||
199 | ShutdownSpecific(); | ||
200 | m_Running = false; | ||
201 | Environment.Exit(0); | ||
202 | } | ||
203 | }); | ||
204 | |||
205 | if(!Util.IsWindows()) | ||
206 | { | ||
207 | try | ||
208 | { | ||
209 | // linux mac os specifics | ||
210 | signals = new Mono.Unix.UnixSignal[] | ||
211 | { | ||
212 | new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM) | ||
213 | }; | ||
214 | ignal_thread.IsBackground = true; | ||
215 | signal_thread.Start(); | ||
216 | } | ||
217 | catch (Exception e) | ||
218 | { | ||
219 | m_log.Info("Could not set up UNIX signal handlers. SIGTERM will not"); | ||
220 | m_log.InfoFormat("shut down gracefully: {0}", e.Message); | ||
221 | m_log.Debug("Exception was: ", e); | ||
222 | } | ||
223 | } | ||
224 | #endif | ||
225 | |||
196 | // Allow derived classes to perform initialization that | 226 | // Allow derived classes to perform initialization that |
197 | // needs to be done after the console has opened | 227 | // needs to be done after the console has opened |
198 | Initialise(); | 228 | Initialise(); |
@@ -220,6 +250,9 @@ namespace OpenSim.Server.Base | |||
220 | } | 250 | } |
221 | } | 251 | } |
222 | 252 | ||
253 | MemoryWatchdog.Enabled = false; | ||
254 | Watchdog.Enabled = false; | ||
255 | WorkManager.Stop(); | ||
223 | RemovePIDFile(); | 256 | RemovePIDFile(); |
224 | 257 | ||
225 | return 0; | 258 | return 0; |
@@ -240,5 +273,114 @@ namespace OpenSim.Server.Base | |||
240 | protected virtual void Initialise() | 273 | protected virtual void Initialise() |
241 | { | 274 | { |
242 | } | 275 | } |
276 | |||
277 | /// <summary> | ||
278 | /// Adds the included files as ini configuration files | ||
279 | /// </summary> | ||
280 | /// <param name="sources">List of URL strings or filename strings</param> | ||
281 | private bool AddIncludes(IConfigSource configSource, List<string> sources) | ||
282 | { | ||
283 | bool sourcesAdded = false; | ||
284 | |||
285 | //loop over config sources | ||
286 | foreach (IConfig config in configSource.Configs) | ||
287 | { | ||
288 | // Look for Include-* in the key name | ||
289 | string[] keys = config.GetKeys(); | ||
290 | foreach (string k in keys) | ||
291 | { | ||
292 | if (k.StartsWith("Include-")) | ||
293 | { | ||
294 | // read the config file to be included. | ||
295 | string file = config.GetString(k); | ||
296 | if (IsUri(file)) | ||
297 | { | ||
298 | if (!sources.Contains(file)) | ||
299 | { | ||
300 | sourcesAdded = true; | ||
301 | sources.Add(file); | ||
302 | } | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | string basepath = Path.GetFullPath(m_configDirectory); | ||
307 | // Resolve relative paths with wildcards | ||
308 | string chunkWithoutWildcards = file; | ||
309 | string chunkWithWildcards = string.Empty; | ||
310 | int wildcardIndex = file.IndexOfAny(new char[] { '*', '?' }); | ||
311 | if (wildcardIndex != -1) | ||
312 | { | ||
313 | chunkWithoutWildcards = file.Substring(0, wildcardIndex); | ||
314 | chunkWithWildcards = file.Substring(wildcardIndex); | ||
315 | } | ||
316 | string path = Path.Combine(basepath, chunkWithoutWildcards); | ||
317 | path = Path.GetFullPath(path) + chunkWithWildcards; | ||
318 | string[] paths = Util.Glob(path); | ||
319 | |||
320 | // If the include path contains no wildcards, then warn the user that it wasn't found. | ||
321 | if (wildcardIndex == -1 && paths.Length == 0) | ||
322 | { | ||
323 | Console.WriteLine("[CONFIG]: Could not find include file {0}", path); | ||
324 | } | ||
325 | else | ||
326 | { | ||
327 | foreach (string p in paths) | ||
328 | { | ||
329 | if (!sources.Contains(p)) | ||
330 | { | ||
331 | sourcesAdded = true; | ||
332 | sources.Add(p); | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | } | ||
340 | |||
341 | return sourcesAdded; | ||
342 | } | ||
343 | |||
344 | /// <summary> | ||
345 | /// Check if we can convert the string to a URI | ||
346 | /// </summary> | ||
347 | /// <param name="file">String uri to the remote resource</param> | ||
348 | /// <returns>true if we can convert the string to a Uri object</returns> | ||
349 | bool IsUri(string file) | ||
350 | { | ||
351 | Uri configUri; | ||
352 | |||
353 | return Uri.TryCreate(file, UriKind.Absolute, | ||
354 | out configUri) && configUri.Scheme == Uri.UriSchemeHttp; | ||
355 | } | ||
356 | |||
357 | IConfigSource ReadConfigSource(string iniFile) | ||
358 | { | ||
359 | // Find out of the file name is a URI and remote load it if possible. | ||
360 | // Load it as a local file otherwise. | ||
361 | Uri configUri; | ||
362 | IConfigSource s = null; | ||
363 | |||
364 | try | ||
365 | { | ||
366 | if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && | ||
367 | configUri.Scheme == Uri.UriSchemeHttp) | ||
368 | { | ||
369 | XmlReader r = XmlReader.Create(iniFile); | ||
370 | s = new XmlConfigSource(r); | ||
371 | } | ||
372 | else | ||
373 | { | ||
374 | s = new IniConfigSource(iniFile); | ||
375 | } | ||
376 | } | ||
377 | catch (Exception e) | ||
378 | { | ||
379 | System.Console.WriteLine("Error reading from config source. {0}", e.Message); | ||
380 | Environment.Exit(1); | ||
381 | } | ||
382 | |||
383 | return s; | ||
384 | } | ||
243 | } | 385 | } |
244 | } | 386 | } |