aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-11-22 05:48:41 +0000
committerJustin Clark-Casey (justincc)2012-11-22 05:48:41 +0000
commit9fcf3f1a3f3457debf0f59ba7659492b44172b99 (patch)
tree472df16756b48e774c83ab9402a3a3c95b3d4601 /OpenSim/Framework
parentFactor out common pid file creation and removal code. (diff)
downloadopensim-SC_OLD-9fcf3f1a3f3457debf0f59ba7659492b44172b99.zip
opensim-SC_OLD-9fcf3f1a3f3457debf0f59ba7659492b44172b99.tar.gz
opensim-SC_OLD-9fcf3f1a3f3457debf0f59ba7659492b44172b99.tar.bz2
opensim-SC_OLD-9fcf3f1a3f3457debf0f59ba7659492b44172b99.tar.xz
Make "config show/set/get/save" console commands available on all servers
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs140
1 files changed, 137 insertions, 3 deletions
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
44 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 public IConfigSource Config { get; protected set; }
48
47 /// <summary> 49 /// <summary>
48 /// Console to be used for any command line output. Can be null, in which case there should be no output. 50 /// Console to be used for any command line output. Can be null, in which case there should be no output.
49 /// </summary> 51 /// </summary>
@@ -175,6 +177,30 @@ namespace OpenSim.Framework.Servers
175 m_console.Commands.AddCommand( 177 m_console.Commands.AddCommand(
176 "General", false, "set log level", "set log level <level>", 178 "General", false, "set log level", "set log level <level>",
177 "Set the console logging level for this session.", HandleSetLogLevel); 179 "Set the console logging level for this session.", HandleSetLogLevel);
180
181 m_console.Commands.AddCommand(
182 "General", false, "config set",
183 "config set <section> <key> <value>",
184 "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);
185
186 m_console.Commands.AddCommand(
187 "General", false, "config get",
188 "config get [<section>] [<key>]",
189 "Synonym for config show",
190 HandleConfig);
191
192 m_console.Commands.AddCommand(
193 "General", false, "config show",
194 "config show [<section>] [<key>]",
195 "Show config information",
196 "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
197 + "If a section is given but not a field, then all fields in that section are printed.",
198 HandleConfig);
199
200 m_console.Commands.AddCommand(
201 "General", false, "config save",
202 "config save <path>",
203 "Save current configuration to a file at the given path", HandleConfig);
178 } 204 }
179 205
180 public virtual void HandleShow(string module, string[] cmd) 206 public virtual void HandleShow(string module, string[] cmd)
@@ -197,6 +223,115 @@ namespace OpenSim.Framework.Servers
197 } 223 }
198 } 224 }
199 225
226 /// <summary>
227 /// Change and load configuration file data.
228 /// </summary>
229 /// <param name="module"></param>
230 /// <param name="cmd"></param>
231 private void HandleConfig(string module, string[] cmd)
232 {
233 List<string> args = new List<string>(cmd);
234 args.RemoveAt(0);
235 string[] cmdparams = args.ToArray();
236
237 if (cmdparams.Length > 0)
238 {
239 string firstParam = cmdparams[0].ToLower();
240
241 switch (firstParam)
242 {
243 case "set":
244 if (cmdparams.Length < 4)
245 {
246 Notice("Syntax: config set <section> <key> <value>");
247 Notice("Example: config set ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
248 }
249 else
250 {
251 IConfig c;
252 IConfigSource source = new IniConfigSource();
253 c = source.AddConfig(cmdparams[1]);
254 if (c != null)
255 {
256 string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
257 c.Set(cmdparams[2], _value);
258 Config.Merge(source);
259
260 Notice("In section [{0}], set {1} = {2}", c.Name, cmdparams[2], _value);
261 }
262 }
263 break;
264
265 case "get":
266 case "show":
267 if (cmdparams.Length == 1)
268 {
269 foreach (IConfig config in Config.Configs)
270 {
271 Notice("[{0}]", config.Name);
272 string[] keys = config.GetKeys();
273 foreach (string key in keys)
274 Notice(" {0} = {1}", key, config.GetString(key));
275 }
276 }
277 else if (cmdparams.Length == 2 || cmdparams.Length == 3)
278 {
279 IConfig config = Config.Configs[cmdparams[1]];
280 if (config == null)
281 {
282 Notice("Section \"{0}\" does not exist.",cmdparams[1]);
283 break;
284 }
285 else
286 {
287 if (cmdparams.Length == 2)
288 {
289 Notice("[{0}]", config.Name);
290 foreach (string key in config.GetKeys())
291 Notice(" {0} = {1}", key, config.GetString(key));
292 }
293 else
294 {
295 Notice(
296 "config get {0} {1} : {2}",
297 cmdparams[1], cmdparams[2], config.GetString(cmdparams[2]));
298 }
299 }
300 }
301 else
302 {
303 Notice("Syntax: config {0} [<section>] [<key>]", firstParam);
304 Notice("Example: config {0} ScriptEngine.DotNetEngine NumberOfScriptThreads", firstParam);
305 }
306
307 break;
308
309 case "save":
310 if (cmdparams.Length < 2)
311 {
312 Notice("Syntax: config save <path>");
313 return;
314 }
315
316 string path = cmdparams[1];
317 Notice("Saving configuration file: {0}", path);
318
319 if (Config is IniConfigSource)
320 {
321 IniConfigSource iniCon = (IniConfigSource)Config;
322 iniCon.Save(path);
323 }
324 else if (Config is XmlConfigSource)
325 {
326 XmlConfigSource xmlCon = (XmlConfigSource)Config;
327 xmlCon.Save(path);
328 }
329
330 break;
331 }
332 }
333 }
334
200 private void HandleSetLogLevel(string module, string[] cmd) 335 private void HandleSetLogLevel(string module, string[] cmd)
201 { 336 {
202 if (cmd.Length != 4) 337 if (cmd.Length != 4)
@@ -220,9 +355,8 @@ namespace OpenSim.Framework.Servers
220 m_consoleAppender.Threshold = consoleLevel; 355 m_consoleAppender.Threshold = consoleLevel;
221 else 356 else
222 Notice( 357 Notice(
223 String.Format( 358 "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF",
224 "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF", 359 rawLevel);
225 rawLevel));
226 360
227 ShowLogLevel(); 361 ShowLogLevel();
228 } 362 }