aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Base/ServicesServerBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Base/ServicesServerBase.cs')
-rw-r--r--OpenSim/Server/Base/ServicesServerBase.cs138
1 files changed, 17 insertions, 121 deletions
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs
index b137c05..5b23149 100644
--- a/OpenSim/Server/Base/ServicesServerBase.cs
+++ b/OpenSim/Server/Base/ServicesServerBase.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.IO; 30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using System.Threading; 32using System.Threading;
@@ -33,6 +34,7 @@ using System.Text;
33using System.Xml; 34using System.Xml;
34using OpenSim.Framework; 35using OpenSim.Framework;
35using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
37using OpenSim.Framework.Servers;
36using log4net; 38using log4net;
37using log4net.Config; 39using log4net.Config;
38using log4net.Appender; 40using log4net.Appender;
@@ -42,7 +44,7 @@ using Nini.Config;
42 44
43namespace OpenSim.Server.Base 45namespace OpenSim.Server.Base
44{ 46{
45 public class ServicesServerBase 47 public class ServicesServerBase : ServerBase
46 { 48 {
47 // Logger 49 // Logger
48 // 50 //
@@ -54,26 +56,13 @@ namespace OpenSim.Server.Base
54 // 56 //
55 protected string[] m_Arguments; 57 protected string[] m_Arguments;
56 58
57 // Configuration
58 //
59 protected IConfigSource m_Config = null;
60
61 public IConfigSource Config
62 {
63 get { return m_Config; }
64 }
65
66 // Run flag 59 // Run flag
67 // 60 //
68 private bool m_Running = true; 61 private bool m_Running = true;
69 62
70 // PID file
71 //
72 private string m_pidFile = String.Empty;
73
74 // Handle all the automagical stuff 63 // Handle all the automagical stuff
75 // 64 //
76 public ServicesServerBase(string prompt, string[] args) 65 public ServicesServerBase(string prompt, string[] args) : base()
77 { 66 {
78 // Save raw arguments 67 // Save raw arguments
79 // 68 //
@@ -120,11 +109,11 @@ namespace OpenSim.Server.Base
120 configUri.Scheme == Uri.UriSchemeHttp) 109 configUri.Scheme == Uri.UriSchemeHttp)
121 { 110 {
122 XmlReader r = XmlReader.Create(iniFile); 111 XmlReader r = XmlReader.Create(iniFile);
123 m_Config = new XmlConfigSource(r); 112 Config = new XmlConfigSource(r);
124 } 113 }
125 else 114 else
126 { 115 {
127 m_Config = new IniConfigSource(iniFile); 116 Config = new IniConfigSource(iniFile);
128 } 117 }
129 } 118 }
130 catch (Exception e) 119 catch (Exception e)
@@ -136,13 +125,13 @@ namespace OpenSim.Server.Base
136 // Merge the configuration from the command line into the 125 // Merge the configuration from the command line into the
137 // loaded file 126 // loaded file
138 // 127 //
139 m_Config.Merge(argvConfig); 128 Config.Merge(argvConfig);
140 129
141 // Refresh the startupConfig post merge 130 // Refresh the startupConfig post merge
142 // 131 //
143 if (m_Config.Configs["Startup"] != null) 132 if (Config.Configs["Startup"] != null)
144 { 133 {
145 startupConfig = m_Config.Configs["Startup"]; 134 startupConfig = Config.Configs["Startup"];
146 } 135 }
147 136
148 prompt = startupConfig.GetString("Prompt", prompt); 137 prompt = startupConfig.GetString("Prompt", prompt);
@@ -172,6 +161,8 @@ namespace OpenSim.Server.Base
172 MainConsole.Instance = new LocalConsole(prompt); 161 MainConsole.Instance = new LocalConsole(prompt);
173 } 162 }
174 163
164 m_console = MainConsole.Instance;
165
175 // Configure the appenders for log4net 166 // Configure the appenders for log4net
176 // 167 //
177 OpenSimAppender consoleAppender = null; 168 OpenSimAppender consoleAppender = null;
@@ -187,54 +178,15 @@ namespace OpenSim.Server.Base
187 XmlConfigurator.Configure(); 178 XmlConfigurator.Configure();
188 } 179 }
189 180
190 ILoggerRepository repository = LogManager.GetRepository(); 181 RegisterCommonAppenders(startupConfig);
191 IAppender[] appenders = repository.GetAppenders();
192
193 foreach (IAppender appender in appenders)
194 {
195 if (appender.Name == "Console")
196 {
197 consoleAppender = (OpenSimAppender)appender;
198 }
199 if (appender.Name == "LogFileAppender")
200 {
201 fileAppender = (FileAppender)appender;
202 }
203 }
204
205 if (consoleAppender == null)
206 {
207 System.Console.WriteLine("No console appender found. Server can't start");
208 Thread.CurrentThread.Abort();
209 }
210 else
211 {
212 consoleAppender.Console = (ConsoleBase)MainConsole.Instance;
213
214 if (null == consoleAppender.Threshold)
215 consoleAppender.Threshold = Level.All;
216 }
217
218 // Set log file
219 //
220 if (fileAppender != null)
221 {
222 if (startupConfig != null)
223 {
224 string cfgFileName = startupConfig.GetString("logfile", null);
225 if (cfgFileName != null)
226 {
227 fileAppender.File = cfgFileName;
228 fileAppender.ActivateOptions();
229 }
230 }
231 }
232 182
233 if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) 183 if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
234 { 184 {
235 CreatePIDFile(startupConfig.GetString("PIDFile")); 185 CreatePIDFile(startupConfig.GetString("PIDFile"));
236 } 186 }
237 187
188 RegisterCommonCommands();
189
238 // Register the quit command 190 // Register the quit command
239 // 191 //
240 MainConsole.Instance.Commands.AddCommand("General", false, "quit", 192 MainConsole.Instance.Commands.AddCommand("General", false, "quit",
@@ -244,12 +196,6 @@ namespace OpenSim.Server.Base
244 MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", 196 MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
245 "shutdown", 197 "shutdown",
246 "Quit the application", HandleQuit); 198 "Quit the application", HandleQuit);
247
248 // Register a command to read other commands from a file
249 MainConsole.Instance.Commands.AddCommand("General", false, "command-script",
250 "command-script <script>",
251 "Run a command script from file", HandleScript);
252
253 199
254 // Allow derived classes to perform initialization that 200 // Allow derived classes to perform initialization that
255 // needs to be done after the console has opened 201 // needs to be done after the console has opened
@@ -276,8 +222,8 @@ namespace OpenSim.Server.Base
276 } 222 }
277 } 223 }
278 224
279 if (m_pidFile != String.Empty) 225 RemovePIDFile();
280 File.Delete(m_pidFile); 226
281 return 0; 227 return 0;
282 } 228 }
283 229
@@ -285,43 +231,9 @@ namespace OpenSim.Server.Base
285 { 231 {
286 m_Running = false; 232 m_Running = false;
287 m_log.Info("[CONSOLE] Quitting"); 233 m_log.Info("[CONSOLE] Quitting");
288 }
289
290 protected virtual void HandleScript(string module, string[] parms)
291 {
292 if (parms.Length != 2)
293 {
294 return;
295 }
296 RunCommandScript(parms[1]);
297 }
298
299 /// <summary>
300 /// Run an optional startup list of commands
301 /// </summary>
302 /// <param name="fileName"></param>
303 private void RunCommandScript(string fileName)
304 {
305 if (File.Exists(fileName))
306 {
307 m_log.Info("[COMMANDFILE]: Running " + fileName);
308 234
309 using (StreamReader readFile = File.OpenText(fileName))
310 {
311 string currentCommand;
312 while ((currentCommand = readFile.ReadLine()) != null)
313 {
314 if (currentCommand != String.Empty)
315 {
316 m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
317 MainConsole.Instance.RunCommand(currentCommand);
318 }
319 }
320 }
321 }
322 } 235 }
323 236
324
325 protected virtual void ReadConfig() 237 protected virtual void ReadConfig()
326 { 238 {
327 } 239 }
@@ -329,21 +241,5 @@ namespace OpenSim.Server.Base
329 protected virtual void Initialise() 241 protected virtual void Initialise()
330 { 242 {
331 } 243 }
332
333 protected void CreatePIDFile(string path)
334 {
335 try
336 {
337 string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
338 FileStream fs = File.Create(path);
339 Byte[] buf = Encoding.ASCII.GetBytes(pidstring);
340 fs.Write(buf, 0, buf.Length);
341 fs.Close();
342 m_pidFile = path;
343 }
344 catch (Exception)
345 {
346 }
347 }
348 } 244 }
349} 245} \ No newline at end of file