From 3e71c71cbffb0de454759e2bbd0ff840dfa480bc Mon Sep 17 00:00:00 2001 From: BlueWall Date: Wed, 3 Oct 2012 16:07:11 -0400 Subject: Add modular configuration for Robust connectors We can provide modular ini for connectors... look for our configuration in the following places... 1) in the default ini/-inifile 2) in the named file (ConfigName) located in the configured directory (see Robust[.HG].ini [Start] section for ConfigDirectory) 3) in the repository named in the connector (ConfigURL) In this case, the file will be written into the configured directory with the specified See example connector/service @ https://github.com/BlueWall/SlipStream for testing. --- OpenSim/Server/Base/ServerUtils.cs | 38 +++++++++++++++ OpenSim/Server/Base/ServicesServerBase.cs | 8 ++++ OpenSim/Server/Handlers/Base/ServerConnector.cs | 61 +++++++++++++++++++++++++ bin/Robust.HG.ini.example | 4 ++ bin/Robust.ini.example | 5 ++ 5 files changed, 116 insertions(+) diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 42c82cf..4a696c4 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs @@ -33,6 +33,7 @@ using System.Xml.Serialization; using System.Text; using System.Collections.Generic; using log4net; +using Nini.Config; using OpenSim.Framework; using OpenMetaverse; @@ -333,5 +334,42 @@ namespace OpenSim.Server.Base return ret; } + + public static IConfig GetConfig(string configFile, string configName) + { + IConfig config; + + if (File.Exists(configFile)) + { + IConfigSource configsource = new IniConfigSource(configFile); + config = configsource.Configs[configName]; + } + else + config = null; + + return config; + } + + public static IConfigSource LoadInitialConfig(string url) + { + IConfigSource source = new XmlConfigSource(); + m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", url); + + // The ini file path is a http URI + // Try to read it + try + { + XmlReader r = XmlReader.Create(url); + IConfigSource cs = new XmlConfigSource(r); + source.Merge(cs); + } + catch (Exception e) + { + m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), url); + Environment.Exit(1); + } + + return source; + } } } diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 0cff6ed..2f12288 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs @@ -64,6 +64,12 @@ namespace OpenSim.Server.Base get { return m_Config; } } + public string ConfigDirectory + { + get; + private set; + } + // Run flag // private bool m_Running = true; @@ -153,6 +159,8 @@ namespace OpenSim.Server.Base startupConfig = m_Config.Configs["Startup"]; } + ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); + prompt = startupConfig.GetString("Prompt", prompt); // Allow derived classes to load config before the console is diff --git a/OpenSim/Server/Handlers/Base/ServerConnector.cs b/OpenSim/Server/Handlers/Base/ServerConnector.cs index 71876da..951cd89 100644 --- a/OpenSim/Server/Handlers/Base/ServerConnector.cs +++ b/OpenSim/Server/Handlers/Base/ServerConnector.cs @@ -39,8 +39,69 @@ namespace OpenSim.Server.Handlers.Base public class ServiceConnector : IServiceConnector { + public virtual string ConfigURL + { + get; + protected set; + } + + public virtual string ConfigName + { + get; + protected set; + } + + public virtual string ConfigFile + { + get; + protected set; + } + + public virtual IConfigSource Config + { + get; + protected set; + } + public ServiceConnector(IConfigSource config, IHttpServer server, string configName) { } + + // We call this from our plugin module to get our configuration + public IConfig GetConfig() + { + IConfig config = null; + config = ServerUtils.GetConfig(ConfigFile, ConfigName); + + // Our file is not here? We can get one to bootstrap our plugin module + if ( config == null ) + { + IConfigSource remotesource = GetConfigSource(); + + if (remotesource != null) + { + IniConfigSource initialconfig = new IniConfigSource(); + initialconfig.Merge (remotesource); + initialconfig.Save(ConfigFile); + } + + config = remotesource.Configs[ConfigName]; + } + + return config; + } + + // We get our remote initial configuration for bootstrapping + private IConfigSource GetConfigSource() + { + IConfigSource source = null; + + source = ServerUtils.LoadInitialConfig(ConfigURL); + + if (source == null) + System.Console.WriteLine(String.Format ("Config Url: {0} Not found!", ConfigURL)); + + return source; + } } } diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index 18094b7..995f181 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -23,6 +23,10 @@ [Startup] ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003/OpenSim.Server.Handlers.dll:XInventoryInConnector,8004/OpenSim.Server.Handlers.dll:FreeswitchServerConnector,8003/OpenSim.Server.Handlers.dll:GridServiceConnector,8002/OpenSim.Server.Handlers.dll:GridInfoServerInConnector,8003/OpenSim.Server.Handlers.dll:AuthenticationServiceConnector,8002/OpenSim.Server.Handlers.dll:OpenIdServerConnector,8003/OpenSim.Server.Handlers.dll:AvatarServiceConnector,8002/OpenSim.Server.Handlers.dll:LLLoginServiceInConnector,8003/OpenSim.Server.Handlers.dll:PresenceServiceConnector,8003/OpenSim.Server.Handlers.dll:UserAccountServiceConnector,8003/OpenSim.Server.Handlers.dll:GridUserServiceConnector,8003/OpenSim.Server.Handlers.dll:FriendsServiceConnector,8002/OpenSim.Server.Handlers.dll:GatekeeperServiceInConnector,8002/OpenSim.Server.Handlers.dll:UserAgentServerConnector,HGInventoryService@8002/OpenSim.Server.Handlers.dll:XInventoryInConnector,HGAssetService@8002/OpenSim.Server.Handlers.dll:AssetServiceConnector,8002/OpenSim.Server.Handlers.dll:HeloServiceInConnector,8002/OpenSim.Server.Handlers.dll:HGFriendsServerConnector,8002/OpenSim.Server.Handlers.dll:InstantMessageServerConnector,8003/OpenSim.Server.Handlers.dll:MapAddServiceConnector,8002/OpenSim.Server.Handlers.dll:MapGetServiceConnector" +; Modular configurations +; Set path to directory for modular ini files... +ConfigDirectory = "/home/opensim/etc/Configs" + ; * This is common for all services, it's the network setup for the entire ; * server instance, if none is specified above ; * diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example index 5a9d613..7b8e83d 100644 --- a/bin/Robust.ini.example +++ b/bin/Robust.ini.example @@ -15,6 +15,11 @@ [Startup] ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003/OpenSim.Server.Handlers.dll:XInventoryInConnector,8004/OpenSim.Server.Handlers.dll:FreeswitchServerConnector,8003/OpenSim.Server.Handlers.dll:GridServiceConnector,8002/OpenSim.Server.Handlers.dll:GridInfoServerInConnector,8003/OpenSim.Server.Handlers.dll:AuthenticationServiceConnector,8002/OpenSim.Server.Handlers.dll:OpenIdServerConnector,8003/OpenSim.Server.Handlers.dll:AvatarServiceConnector,8002/OpenSim.Server.Handlers.dll:LLLoginServiceInConnector,8003/OpenSim.Server.Handlers.dll:PresenceServiceConnector,8003/OpenSim.Server.Handlers.dll:UserAccountServiceConnector,8003/OpenSim.Server.Handlers.dll:GridUserServiceConnector,8003/OpenSim.Server.Handlers.dll:FriendsServiceConnector,8003/OpenSim.Server.Handlers.dll:MapAddServiceConnector,8002/OpenSim.Server.Handlers.dll:MapGetServiceConnector" + +; Modular configurations +; Set path to directory for modular ini files... +ConfigDirectory = "/home/opensim/etc/Configs" + ; * This is common for all services, it's the network setup for the entire ; * server instance, if none is specified above ; * -- cgit v1.1