From 9fcf3f1a3f3457debf0f59ba7659492b44172b99 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Nov 2012 05:48:41 +0000 Subject: Make "config show/set/get/save" console commands available on all servers --- OpenSim/Framework/Servers/ServerBase.cs | 140 +++++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/ServerBase.cs') diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index 645b43a..27cfc9b 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(); } -- cgit v1.1