From 8d207fd8e600d04746157181b1d085957706baba Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 22 Nov 2012 05:48:41 +0000 Subject: [PATCH] Make "config show/set/get/save" console commands available on all servers --- OpenSim/Framework/Servers/ServerBase.cs | 140 +++++++++++++++++- .../Region/Application/ConfigurationLoader.cs | 1 - OpenSim/Region/Application/OpenSim.cs | 134 +---------------- OpenSim/Region/Application/OpenSimBase.cs | 65 +++----- OpenSim/Server/Base/HttpServerBase.cs | 2 +- OpenSim/Server/Base/ServicesServerBase.cs | 19 +-- 6 files changed, 172 insertions(+), 189 deletions(-) diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index 645b43aed0..27cfc9bd6c 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs @@ -44,6 +44,8 @@ namespace OpenSim.Framework.Servers { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public IConfigSource Config { get; protected set; } + /// /// Console to be used for any command line output. Can be null, in which case there should be no output. /// @@ -175,6 +177,30 @@ namespace OpenSim.Framework.Servers m_console.Commands.AddCommand( "General", false, "set log level", "set log level ", "Set the console logging level for this session.", HandleSetLogLevel); + + m_console.Commands.AddCommand( + "General", false, "config set", + "config set
", + "Set a config option. In most cases this is not useful since changed parameters are not dynamically reloaded. Neither do changed parameters persist - you will have to change a config file manually and restart.", HandleConfig); + + m_console.Commands.AddCommand( + "General", false, "config get", + "config get [
] []", + "Synonym for config show", + HandleConfig); + + m_console.Commands.AddCommand( + "General", false, "config show", + "config show [
] []", + "Show config information", + "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine + + "If a section is given but not a field, then all fields in that section are printed.", + HandleConfig); + + m_console.Commands.AddCommand( + "General", false, "config save", + "config save ", + "Save current configuration to a file at the given path", HandleConfig); } public virtual void HandleShow(string module, string[] cmd) @@ -197,6 +223,115 @@ namespace OpenSim.Framework.Servers } } + /// + /// Change and load configuration file data. + /// + /// + /// + private void HandleConfig(string module, string[] cmd) + { + List args = new List(cmd); + args.RemoveAt(0); + string[] cmdparams = args.ToArray(); + + if (cmdparams.Length > 0) + { + string firstParam = cmdparams[0].ToLower(); + + switch (firstParam) + { + case "set": + if (cmdparams.Length < 4) + { + Notice("Syntax: config set
"); + Notice("Example: config set ScriptEngine.DotNetEngine NumberOfScriptThreads 5"); + } + else + { + IConfig c; + IConfigSource source = new IniConfigSource(); + c = source.AddConfig(cmdparams[1]); + if (c != null) + { + string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3); + c.Set(cmdparams[2], _value); + Config.Merge(source); + + Notice("In section [{0}], set {1} = {2}", c.Name, cmdparams[2], _value); + } + } + break; + + case "get": + case "show": + if (cmdparams.Length == 1) + { + foreach (IConfig config in Config.Configs) + { + Notice("[{0}]", config.Name); + string[] keys = config.GetKeys(); + foreach (string key in keys) + Notice(" {0} = {1}", key, config.GetString(key)); + } + } + else if (cmdparams.Length == 2 || cmdparams.Length == 3) + { + IConfig config = Config.Configs[cmdparams[1]]; + if (config == null) + { + Notice("Section \"{0}\" does not exist.",cmdparams[1]); + break; + } + else + { + if (cmdparams.Length == 2) + { + Notice("[{0}]", config.Name); + foreach (string key in config.GetKeys()) + Notice(" {0} = {1}", key, config.GetString(key)); + } + else + { + Notice( + "config get {0} {1} : {2}", + cmdparams[1], cmdparams[2], config.GetString(cmdparams[2])); + } + } + } + else + { + Notice("Syntax: config {0} [
] []", firstParam); + Notice("Example: config {0} ScriptEngine.DotNetEngine NumberOfScriptThreads", firstParam); + } + + break; + + case "save": + if (cmdparams.Length < 2) + { + Notice("Syntax: config save "); + return; + } + + string path = cmdparams[1]; + Notice("Saving configuration file: {0}", path); + + if (Config is IniConfigSource) + { + IniConfigSource iniCon = (IniConfigSource)Config; + iniCon.Save(path); + } + else if (Config is XmlConfigSource) + { + XmlConfigSource xmlCon = (XmlConfigSource)Config; + xmlCon.Save(path); + } + + break; + } + } + } + private void HandleSetLogLevel(string module, string[] cmd) { if (cmd.Length != 4) @@ -220,9 +355,8 @@ namespace OpenSim.Framework.Servers m_consoleAppender.Threshold = consoleLevel; else Notice( - String.Format( - "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF", - rawLevel)); + "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF", + rawLevel); ShowLogLevel(); } diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index 8d95c41ca2..fc3999f7a6 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs @@ -188,7 +188,6 @@ namespace OpenSim // Make sure command line options take precedence m_config.Source.Merge(argvSource); - IConfig enVars = m_config.Source.Configs["Environment"]; if( enVars != null ) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 70374b8dc8..6b36c2a721 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -82,8 +82,8 @@ namespace OpenSim { base.ReadExtraConfigSettings(); - IConfig startupConfig = m_config.Source.Configs["Startup"]; - IConfig networkConfig = m_config.Source.Configs["Network"]; + IConfig startupConfig = Config.Configs["Startup"]; + IConfig networkConfig = Config.Configs["Network"]; int stpMaxThreads = 15; @@ -148,7 +148,7 @@ namespace OpenSim break; case "rest": m_console = new RemoteConsole("Region"); - ((RemoteConsole)m_console).ReadConfig(m_config.Source); + ((RemoteConsole)m_console).ReadConfig(Config); break; default: m_console = new LocalConsole("Region"); @@ -158,7 +158,7 @@ namespace OpenSim MainConsole.Instance = m_console; - RegisterCommonAppenders(m_config.Source.Configs["Startup"]); + RegisterCommonAppenders(Config.Configs["Startup"]); RegisterConsoleCommands(); base.StartupSpecific(); @@ -356,26 +356,6 @@ namespace OpenSim "restart", "Restart all sims in this instance", RunCommand); - m_console.Commands.AddCommand("General", false, "config set", - "config set
", - "Set a config option. In most cases this is not useful since changed parameters are not dynamically reloaded. Neither do changed parameters persist - you will have to change a config file manually and restart.", HandleConfig); - - m_console.Commands.AddCommand("General", false, "config get", - "config get [
] []", - "Synonym for config show", - HandleConfig); - - m_console.Commands.AddCommand("General", false, "config show", - "config show [
] []", - "Show config information", - "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine - + "If a section is given but not a field, then all fields in that section are printed.", - HandleConfig); - - m_console.Commands.AddCommand("General", false, "config save", - "config save ", - "Save current configuration to a file at the given path", HandleConfig); - m_console.Commands.AddCommand("General", false, "command-script", "command-script