diff options
author | Melanie | 2012-11-22 13:37:27 +0000 |
---|---|---|
committer | Melanie | 2012-11-22 13:37:27 +0000 |
commit | 3c1a58c67a9162480054674ae8c83f5b501576db (patch) | |
tree | 7864eb3dd4aea66bd41b49a43a810c6c623c2485 /OpenSim/Server | |
parent | Merge branch 'avination' into careminster (diff) | |
parent | Factor out command script code. (diff) | |
download | opensim-SC_OLD-3c1a58c67a9162480054674ae8c83f5b501576db.zip opensim-SC_OLD-3c1a58c67a9162480054674ae8c83f5b501576db.tar.gz opensim-SC_OLD-3c1a58c67a9162480054674ae8c83f5b501576db.tar.bz2 opensim-SC_OLD-3c1a58c67a9162480054674ae8c83f5b501576db.tar.xz |
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Server')
-rw-r--r-- | OpenSim/Server/Base/HttpServerBase.cs | 2 | ||||
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 150 |
2 files changed, 13 insertions, 139 deletions
diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs index 29b1c00..954783c 100644 --- a/OpenSim/Server/Base/HttpServerBase.cs +++ b/OpenSim/Server/Base/HttpServerBase.cs | |||
@@ -52,7 +52,7 @@ namespace OpenSim.Server.Base | |||
52 | 52 | ||
53 | protected override void ReadConfig() | 53 | protected override void ReadConfig() |
54 | { | 54 | { |
55 | IConfig networkConfig = m_Config.Configs["Network"]; | 55 | IConfig networkConfig = Config.Configs["Network"]; |
56 | 56 | ||
57 | if (networkConfig == null) | 57 | if (networkConfig == null) |
58 | { | 58 | { |
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 56bb7ae..5b23149 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs | |||
@@ -56,23 +56,10 @@ namespace OpenSim.Server.Base | |||
56 | // | 56 | // |
57 | protected string[] m_Arguments; | 57 | protected string[] m_Arguments; |
58 | 58 | ||
59 | // Configuration | ||
60 | // | ||
61 | protected IConfigSource m_Config = null; | ||
62 | |||
63 | public IConfigSource Config | ||
64 | { | ||
65 | get { return m_Config; } | ||
66 | } | ||
67 | |||
68 | // Run flag | 59 | // Run flag |
69 | // | 60 | // |
70 | private bool m_Running = true; | 61 | private bool m_Running = true; |
71 | 62 | ||
72 | // PID file | ||
73 | // | ||
74 | private string m_pidFile = String.Empty; | ||
75 | |||
76 | // Handle all the automagical stuff | 63 | // Handle all the automagical stuff |
77 | // | 64 | // |
78 | public ServicesServerBase(string prompt, string[] args) : base() | 65 | public ServicesServerBase(string prompt, string[] args) : base() |
@@ -122,11 +109,11 @@ namespace OpenSim.Server.Base | |||
122 | configUri.Scheme == Uri.UriSchemeHttp) | 109 | configUri.Scheme == Uri.UriSchemeHttp) |
123 | { | 110 | { |
124 | XmlReader r = XmlReader.Create(iniFile); | 111 | XmlReader r = XmlReader.Create(iniFile); |
125 | m_Config = new XmlConfigSource(r); | 112 | Config = new XmlConfigSource(r); |
126 | } | 113 | } |
127 | else | 114 | else |
128 | { | 115 | { |
129 | m_Config = new IniConfigSource(iniFile); | 116 | Config = new IniConfigSource(iniFile); |
130 | } | 117 | } |
131 | } | 118 | } |
132 | catch (Exception e) | 119 | catch (Exception e) |
@@ -138,13 +125,13 @@ namespace OpenSim.Server.Base | |||
138 | // Merge the configuration from the command line into the | 125 | // Merge the configuration from the command line into the |
139 | // loaded file | 126 | // loaded file |
140 | // | 127 | // |
141 | m_Config.Merge(argvConfig); | 128 | Config.Merge(argvConfig); |
142 | 129 | ||
143 | // Refresh the startupConfig post merge | 130 | // Refresh the startupConfig post merge |
144 | // | 131 | // |
145 | if (m_Config.Configs["Startup"] != null) | 132 | if (Config.Configs["Startup"] != null) |
146 | { | 133 | { |
147 | startupConfig = m_Config.Configs["Startup"]; | 134 | startupConfig = Config.Configs["Startup"]; |
148 | } | 135 | } |
149 | 136 | ||
150 | prompt = startupConfig.GetString("Prompt", prompt); | 137 | prompt = startupConfig.GetString("Prompt", prompt); |
@@ -174,6 +161,8 @@ namespace OpenSim.Server.Base | |||
174 | MainConsole.Instance = new LocalConsole(prompt); | 161 | MainConsole.Instance = new LocalConsole(prompt); |
175 | } | 162 | } |
176 | 163 | ||
164 | m_console = MainConsole.Instance; | ||
165 | |||
177 | // Configure the appenders for log4net | 166 | // Configure the appenders for log4net |
178 | // | 167 | // |
179 | OpenSimAppender consoleAppender = null; | 168 | OpenSimAppender consoleAppender = null; |
@@ -189,54 +178,15 @@ namespace OpenSim.Server.Base | |||
189 | XmlConfigurator.Configure(); | 178 | XmlConfigurator.Configure(); |
190 | } | 179 | } |
191 | 180 | ||
192 | ILoggerRepository repository = LogManager.GetRepository(); | 181 | RegisterCommonAppenders(startupConfig); |
193 | IAppender[] appenders = repository.GetAppenders(); | ||
194 | |||
195 | foreach (IAppender appender in appenders) | ||
196 | { | ||
197 | if (appender.Name == "Console") | ||
198 | { | ||
199 | consoleAppender = (OpenSimAppender)appender; | ||
200 | } | ||
201 | if (appender.Name == "LogFileAppender") | ||
202 | { | ||
203 | fileAppender = (FileAppender)appender; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | if (consoleAppender == null) | ||
208 | { | ||
209 | System.Console.WriteLine("No console appender found. Server can't start"); | ||
210 | Thread.CurrentThread.Abort(); | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | consoleAppender.Console = (ConsoleBase)MainConsole.Instance; | ||
215 | |||
216 | if (null == consoleAppender.Threshold) | ||
217 | consoleAppender.Threshold = Level.All; | ||
218 | } | ||
219 | |||
220 | // Set log file | ||
221 | // | ||
222 | if (fileAppender != null) | ||
223 | { | ||
224 | if (startupConfig != null) | ||
225 | { | ||
226 | string cfgFileName = startupConfig.GetString("logfile", null); | ||
227 | if (cfgFileName != null) | ||
228 | { | ||
229 | fileAppender.File = cfgFileName; | ||
230 | fileAppender.ActivateOptions(); | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | 182 | ||
235 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) | 183 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) |
236 | { | 184 | { |
237 | CreatePIDFile(startupConfig.GetString("PIDFile")); | 185 | CreatePIDFile(startupConfig.GetString("PIDFile")); |
238 | } | 186 | } |
239 | 187 | ||
188 | RegisterCommonCommands(); | ||
189 | |||
240 | // Register the quit command | 190 | // Register the quit command |
241 | // | 191 | // |
242 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", | 192 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", |
@@ -246,16 +196,6 @@ namespace OpenSim.Server.Base | |||
246 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", | 196 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", |
247 | "shutdown", | 197 | "shutdown", |
248 | "Quit the application", HandleQuit); | 198 | "Quit the application", HandleQuit); |
249 | |||
250 | // Register a command to read other commands from a file | ||
251 | MainConsole.Instance.Commands.AddCommand("General", false, "command-script", | ||
252 | "command-script <script>", | ||
253 | "Run a command script from file", HandleScript); | ||
254 | |||
255 | MainConsole.Instance.Commands.AddCommand("General", false, "show uptime", | ||
256 | "show uptime", | ||
257 | "Show server uptime", HandleShow); | ||
258 | |||
259 | 199 | ||
260 | // Allow derived classes to perform initialization that | 200 | // Allow derived classes to perform initialization that |
261 | // needs to be done after the console has opened | 201 | // needs to be done after the console has opened |
@@ -282,8 +222,8 @@ namespace OpenSim.Server.Base | |||
282 | } | 222 | } |
283 | } | 223 | } |
284 | 224 | ||
285 | if (m_pidFile != String.Empty) | 225 | RemovePIDFile(); |
286 | File.Delete(m_pidFile); | 226 | |
287 | return 0; | 227 | return 0; |
288 | } | 228 | } |
289 | 229 | ||
@@ -291,43 +231,9 @@ namespace OpenSim.Server.Base | |||
291 | { | 231 | { |
292 | m_Running = false; | 232 | m_Running = false; |
293 | m_log.Info("[CONSOLE] Quitting"); | 233 | m_log.Info("[CONSOLE] Quitting"); |
294 | } | ||
295 | 234 | ||
296 | protected virtual void HandleScript(string module, string[] parms) | ||
297 | { | ||
298 | if (parms.Length != 2) | ||
299 | { | ||
300 | return; | ||
301 | } | ||
302 | RunCommandScript(parms[1]); | ||
303 | } | 235 | } |
304 | 236 | ||
305 | /// <summary> | ||
306 | /// Run an optional startup list of commands | ||
307 | /// </summary> | ||
308 | /// <param name="fileName"></param> | ||
309 | private void RunCommandScript(string fileName) | ||
310 | { | ||
311 | if (File.Exists(fileName)) | ||
312 | { | ||
313 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
314 | |||
315 | using (StreamReader readFile = File.OpenText(fileName)) | ||
316 | { | ||
317 | string currentCommand; | ||
318 | while ((currentCommand = readFile.ReadLine()) != null) | ||
319 | { | ||
320 | if (currentCommand != String.Empty) | ||
321 | { | ||
322 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
323 | MainConsole.Instance.RunCommand(currentCommand); | ||
324 | } | ||
325 | } | ||
326 | } | ||
327 | } | ||
328 | } | ||
329 | |||
330 | |||
331 | protected virtual void ReadConfig() | 237 | protected virtual void ReadConfig() |
332 | { | 238 | { |
333 | } | 239 | } |
@@ -335,37 +241,5 @@ namespace OpenSim.Server.Base | |||
335 | protected virtual void Initialise() | 241 | protected virtual void Initialise() |
336 | { | 242 | { |
337 | } | 243 | } |
338 | |||
339 | protected void CreatePIDFile(string path) | ||
340 | { | ||
341 | try | ||
342 | { | ||
343 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | ||
344 | FileStream fs = File.Create(path); | ||
345 | Byte[] buf = Encoding.ASCII.GetBytes(pidstring); | ||
346 | fs.Write(buf, 0, buf.Length); | ||
347 | fs.Close(); | ||
348 | m_pidFile = path; | ||
349 | } | ||
350 | catch (Exception) | ||
351 | { | ||
352 | } | ||
353 | } | ||
354 | |||
355 | public virtual void HandleShow(string module, string[] cmd) | ||
356 | { | ||
357 | List<string> args = new List<string>(cmd); | ||
358 | |||
359 | args.RemoveAt(0); | ||
360 | |||
361 | string[] showParams = args.ToArray(); | ||
362 | |||
363 | switch (showParams[0]) | ||
364 | { | ||
365 | case "uptime": | ||
366 | MainConsole.Instance.Output(GetUptimeReport()); | ||
367 | break; | ||
368 | } | ||
369 | } | ||
370 | } | 244 | } |
371 | } \ No newline at end of file | 245 | } \ No newline at end of file |