From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- OpenSim/Server/Base/ServicesServerBase.cs | 202 +++++++++++++++++++++++++----- 1 file changed, 172 insertions(+), 30 deletions(-) (limited to 'OpenSim/Server/Base/ServicesServerBase.cs') 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 // protected string[] m_Arguments; - public string ConfigDirectory - { - get; - private set; - } + protected string m_configDirectory = "."; // Run flag // private bool m_Running = true; +#if (_MONO) + private static Mono.Unix.UnixSignal[] signals; +#endif + // Handle all the automagical stuff // public ServicesServerBase(string prompt, string[] args) : base() @@ -85,7 +85,7 @@ namespace OpenSim.Server.Base string fileName = ""; if (Assembly.GetEntryAssembly() != null) fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location); - string iniFile = "../config/" + fileName + ".ini"; + string iniFile = fileName + ".ini"; string logConfig = null; IConfig startupConfig = argvConfig.Configs["Startup"]; @@ -96,39 +96,31 @@ namespace OpenSim.Server.Base // Check if a prompt was given on the command line prompt = startupConfig.GetString("prompt", prompt); - + // Check for a Log4Net config file on the command line logConfig =startupConfig.GetString("logconfig", logConfig); } - // Find out of the file name is a URI and remote load it if possible. - // Load it as a local file otherwise. - Uri configUri; + Config = ReadConfigSource(iniFile); - try + List sources = new List(); + sources.Add(iniFile); + + int sourceIndex = 1; + + while (AddIncludes(Config, sources)) { - if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && - configUri.Scheme == Uri.UriSchemeHttp) + for ( ; sourceIndex < sources.Count ; ++sourceIndex) { - XmlReader r = XmlReader.Create(iniFile); - Config = new XmlConfigSource(r); + IConfigSource s = ReadConfigSource(sources[sourceIndex]); + Config.Merge(s); } - else - { - Config = new IniConfigSource(iniFile); - } - } - catch (Exception e) - { - System.Console.WriteLine("Error reading from config source. {0}", e.Message); - System.Diagnostics.Process.GetCurrentProcess().Kill(); -///// Environment.Exit(1); } // Merge OpSys env vars - m_log.Info("[CONFIG]: Loading environment variables for Config"); + Console.WriteLine("[CONFIG]: Loading environment variables for Config"); Util.MergeEnvironmentToConfig(Config); - + // Merge the configuration from the command line into the loaded file Config.Merge(argvConfig); @@ -140,10 +132,12 @@ namespace OpenSim.Server.Base startupConfig = Config.Configs["Startup"]; } - ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); - - prompt = startupConfig.GetString("Prompt", prompt); + if (startupConfig != null) + { + m_configDirectory = startupConfig.GetString("ConfigDirectory", m_configDirectory); + prompt = startupConfig.GetString("Prompt", prompt); + } // Allow derived classes to load config before the console is opened. ReadConfig(); @@ -193,6 +187,42 @@ namespace OpenSim.Server.Base RegisterCommonCommands(); RegisterCommonComponents(Config); +#if (_MONO) + Thread signal_thread = new Thread (delegate () + { + while (true) + { + // Wait for a signal to be delivered + int index = Mono.Unix.UnixSignal.WaitAny (signals, -1); + + //Mono.Unix.Native.Signum signal = signals [index].Signum; + ShutdownSpecific(); + m_Running = false; + Environment.Exit(0); + } + }); + + if(!Util.IsWindows()) + { + try + { + // linux mac os specifics + signals = new Mono.Unix.UnixSignal[] + { + new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM) + }; + ignal_thread.IsBackground = true; + signal_thread.Start(); + } + catch (Exception e) + { + m_log.Info("Could not set up UNIX signal handlers. SIGTERM will not"); + m_log.InfoFormat("shut down gracefully: {0}", e.Message); + m_log.Debug("Exception was: ", e); + } + } +#endif + // Allow derived classes to perform initialization that // needs to be done after the console has opened Initialise(); @@ -220,6 +250,9 @@ namespace OpenSim.Server.Base } } + MemoryWatchdog.Enabled = false; + Watchdog.Enabled = false; + WorkManager.Stop(); RemovePIDFile(); return 0; @@ -240,5 +273,114 @@ namespace OpenSim.Server.Base protected virtual void Initialise() { } + + /// + /// Adds the included files as ini configuration files + /// + /// List of URL strings or filename strings + private bool AddIncludes(IConfigSource configSource, List sources) + { + bool sourcesAdded = false; + + //loop over config sources + foreach (IConfig config in configSource.Configs) + { + // Look for Include-* in the key name + string[] keys = config.GetKeys(); + foreach (string k in keys) + { + if (k.StartsWith("Include-")) + { + // read the config file to be included. + string file = config.GetString(k); + if (IsUri(file)) + { + if (!sources.Contains(file)) + { + sourcesAdded = true; + sources.Add(file); + } + } + else + { + string basepath = Path.GetFullPath(m_configDirectory); + // Resolve relative paths with wildcards + string chunkWithoutWildcards = file; + string chunkWithWildcards = string.Empty; + int wildcardIndex = file.IndexOfAny(new char[] { '*', '?' }); + if (wildcardIndex != -1) + { + chunkWithoutWildcards = file.Substring(0, wildcardIndex); + chunkWithWildcards = file.Substring(wildcardIndex); + } + string path = Path.Combine(basepath, chunkWithoutWildcards); + path = Path.GetFullPath(path) + chunkWithWildcards; + string[] paths = Util.Glob(path); + + // If the include path contains no wildcards, then warn the user that it wasn't found. + if (wildcardIndex == -1 && paths.Length == 0) + { + Console.WriteLine("[CONFIG]: Could not find include file {0}", path); + } + else + { + foreach (string p in paths) + { + if (!sources.Contains(p)) + { + sourcesAdded = true; + sources.Add(p); + } + } + } + } + } + } + } + + return sourcesAdded; + } + + /// + /// Check if we can convert the string to a URI + /// + /// String uri to the remote resource + /// true if we can convert the string to a Uri object + bool IsUri(string file) + { + Uri configUri; + + return Uri.TryCreate(file, UriKind.Absolute, + out configUri) && configUri.Scheme == Uri.UriSchemeHttp; + } + + IConfigSource ReadConfigSource(string iniFile) + { + // Find out of the file name is a URI and remote load it if possible. + // Load it as a local file otherwise. + Uri configUri; + IConfigSource s = null; + + try + { + if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && + configUri.Scheme == Uri.UriSchemeHttp) + { + XmlReader r = XmlReader.Create(iniFile); + s = new XmlConfigSource(r); + } + else + { + s = new IniConfigSource(iniFile); + } + } + catch (Exception e) + { + System.Console.WriteLine("Error reading from config source. {0}", e.Message); + Environment.Exit(1); + } + + return s; + } } } -- cgit v1.1