diff options
Diffstat (limited to 'OpenSim/Server/Base/ServicesServerBase.cs')
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 177 |
1 files changed, 16 insertions, 161 deletions
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 0cff6ed..5b23149 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs | |||
@@ -34,6 +34,7 @@ using System.Text; | |||
34 | using System.Xml; | 34 | using System.Xml; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Console; | 36 | using OpenSim.Framework.Console; |
37 | using OpenSim.Framework.Servers; | ||
37 | using log4net; | 38 | using log4net; |
38 | using log4net.Config; | 39 | using log4net.Config; |
39 | using log4net.Appender; | 40 | using log4net.Appender; |
@@ -43,7 +44,7 @@ using Nini.Config; | |||
43 | 44 | ||
44 | namespace OpenSim.Server.Base | 45 | namespace OpenSim.Server.Base |
45 | { | 46 | { |
46 | public class ServicesServerBase | 47 | public class ServicesServerBase : ServerBase |
47 | { | 48 | { |
48 | // Logger | 49 | // Logger |
49 | // | 50 | // |
@@ -55,34 +56,14 @@ namespace OpenSim.Server.Base | |||
55 | // | 56 | // |
56 | protected string[] m_Arguments; | 57 | protected string[] m_Arguments; |
57 | 58 | ||
58 | // Configuration | ||
59 | // | ||
60 | protected IConfigSource m_Config = null; | ||
61 | |||
62 | public IConfigSource Config | ||
63 | { | ||
64 | get { return m_Config; } | ||
65 | } | ||
66 | |||
67 | // Run flag | 59 | // Run flag |
68 | // | 60 | // |
69 | private bool m_Running = true; | 61 | private bool m_Running = true; |
70 | 62 | ||
71 | // PID file | ||
72 | // | ||
73 | private string m_pidFile = String.Empty; | ||
74 | |||
75 | /// <summary> | ||
76 | /// Time at which this server was started | ||
77 | /// </summary> | ||
78 | protected DateTime m_startuptime; | ||
79 | |||
80 | // Handle all the automagical stuff | 63 | // Handle all the automagical stuff |
81 | // | 64 | // |
82 | public ServicesServerBase(string prompt, string[] args) | 65 | public ServicesServerBase(string prompt, string[] args) : base() |
83 | { | 66 | { |
84 | m_startuptime = DateTime.Now; | ||
85 | |||
86 | // Save raw arguments | 67 | // Save raw arguments |
87 | // | 68 | // |
88 | m_Arguments = args; | 69 | m_Arguments = args; |
@@ -128,11 +109,11 @@ namespace OpenSim.Server.Base | |||
128 | configUri.Scheme == Uri.UriSchemeHttp) | 109 | configUri.Scheme == Uri.UriSchemeHttp) |
129 | { | 110 | { |
130 | XmlReader r = XmlReader.Create(iniFile); | 111 | XmlReader r = XmlReader.Create(iniFile); |
131 | m_Config = new XmlConfigSource(r); | 112 | Config = new XmlConfigSource(r); |
132 | } | 113 | } |
133 | else | 114 | else |
134 | { | 115 | { |
135 | m_Config = new IniConfigSource(iniFile); | 116 | Config = new IniConfigSource(iniFile); |
136 | } | 117 | } |
137 | } | 118 | } |
138 | catch (Exception e) | 119 | catch (Exception e) |
@@ -144,13 +125,13 @@ namespace OpenSim.Server.Base | |||
144 | // Merge the configuration from the command line into the | 125 | // Merge the configuration from the command line into the |
145 | // loaded file | 126 | // loaded file |
146 | // | 127 | // |
147 | m_Config.Merge(argvConfig); | 128 | Config.Merge(argvConfig); |
148 | 129 | ||
149 | // Refresh the startupConfig post merge | 130 | // Refresh the startupConfig post merge |
150 | // | 131 | // |
151 | if (m_Config.Configs["Startup"] != null) | 132 | if (Config.Configs["Startup"] != null) |
152 | { | 133 | { |
153 | startupConfig = m_Config.Configs["Startup"]; | 134 | startupConfig = Config.Configs["Startup"]; |
154 | } | 135 | } |
155 | 136 | ||
156 | prompt = startupConfig.GetString("Prompt", prompt); | 137 | prompt = startupConfig.GetString("Prompt", prompt); |
@@ -180,6 +161,8 @@ namespace OpenSim.Server.Base | |||
180 | MainConsole.Instance = new LocalConsole(prompt); | 161 | MainConsole.Instance = new LocalConsole(prompt); |
181 | } | 162 | } |
182 | 163 | ||
164 | m_console = MainConsole.Instance; | ||
165 | |||
183 | // Configure the appenders for log4net | 166 | // Configure the appenders for log4net |
184 | // | 167 | // |
185 | OpenSimAppender consoleAppender = null; | 168 | OpenSimAppender consoleAppender = null; |
@@ -195,54 +178,15 @@ namespace OpenSim.Server.Base | |||
195 | XmlConfigurator.Configure(); | 178 | XmlConfigurator.Configure(); |
196 | } | 179 | } |
197 | 180 | ||
198 | ILoggerRepository repository = LogManager.GetRepository(); | 181 | RegisterCommonAppenders(startupConfig); |
199 | IAppender[] appenders = repository.GetAppenders(); | ||
200 | |||
201 | foreach (IAppender appender in appenders) | ||
202 | { | ||
203 | if (appender.Name == "Console") | ||
204 | { | ||
205 | consoleAppender = (OpenSimAppender)appender; | ||
206 | } | ||
207 | if (appender.Name == "LogFileAppender") | ||
208 | { | ||
209 | fileAppender = (FileAppender)appender; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | if (consoleAppender == null) | ||
214 | { | ||
215 | System.Console.WriteLine("No console appender found. Server can't start"); | ||
216 | Thread.CurrentThread.Abort(); | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | consoleAppender.Console = (ConsoleBase)MainConsole.Instance; | ||
221 | |||
222 | if (null == consoleAppender.Threshold) | ||
223 | consoleAppender.Threshold = Level.All; | ||
224 | } | ||
225 | |||
226 | // Set log file | ||
227 | // | ||
228 | if (fileAppender != null) | ||
229 | { | ||
230 | if (startupConfig != null) | ||
231 | { | ||
232 | string cfgFileName = startupConfig.GetString("logfile", null); | ||
233 | if (cfgFileName != null) | ||
234 | { | ||
235 | fileAppender.File = cfgFileName; | ||
236 | fileAppender.ActivateOptions(); | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | 182 | ||
241 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) | 183 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) |
242 | { | 184 | { |
243 | CreatePIDFile(startupConfig.GetString("PIDFile")); | 185 | CreatePIDFile(startupConfig.GetString("PIDFile")); |
244 | } | 186 | } |
245 | 187 | ||
188 | RegisterCommonCommands(); | ||
189 | |||
246 | // Register the quit command | 190 | // Register the quit command |
247 | // | 191 | // |
248 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", | 192 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", |
@@ -252,16 +196,6 @@ namespace OpenSim.Server.Base | |||
252 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", | 196 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", |
253 | "shutdown", | 197 | "shutdown", |
254 | "Quit the application", HandleQuit); | 198 | "Quit the application", HandleQuit); |
255 | |||
256 | // Register a command to read other commands from a file | ||
257 | MainConsole.Instance.Commands.AddCommand("General", false, "command-script", | ||
258 | "command-script <script>", | ||
259 | "Run a command script from file", HandleScript); | ||
260 | |||
261 | MainConsole.Instance.Commands.AddCommand("General", false, "show uptime", | ||
262 | "show uptime", | ||
263 | "Show server uptime", HandleShow); | ||
264 | |||
265 | 199 | ||
266 | // Allow derived classes to perform initialization that | 200 | // Allow derived classes to perform initialization that |
267 | // needs to be done after the console has opened | 201 | // needs to be done after the console has opened |
@@ -288,8 +222,8 @@ namespace OpenSim.Server.Base | |||
288 | } | 222 | } |
289 | } | 223 | } |
290 | 224 | ||
291 | if (m_pidFile != String.Empty) | 225 | RemovePIDFile(); |
292 | File.Delete(m_pidFile); | 226 | |
293 | return 0; | 227 | return 0; |
294 | } | 228 | } |
295 | 229 | ||
@@ -297,43 +231,9 @@ namespace OpenSim.Server.Base | |||
297 | { | 231 | { |
298 | m_Running = false; | 232 | m_Running = false; |
299 | m_log.Info("[CONSOLE] Quitting"); | 233 | m_log.Info("[CONSOLE] Quitting"); |
300 | } | ||
301 | 234 | ||
302 | protected virtual void HandleScript(string module, string[] parms) | ||
303 | { | ||
304 | if (parms.Length != 2) | ||
305 | { | ||
306 | return; | ||
307 | } | ||
308 | RunCommandScript(parms[1]); | ||
309 | } | 235 | } |
310 | 236 | ||
311 | /// <summary> | ||
312 | /// Run an optional startup list of commands | ||
313 | /// </summary> | ||
314 | /// <param name="fileName"></param> | ||
315 | private void RunCommandScript(string fileName) | ||
316 | { | ||
317 | if (File.Exists(fileName)) | ||
318 | { | ||
319 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
320 | |||
321 | using (StreamReader readFile = File.OpenText(fileName)) | ||
322 | { | ||
323 | string currentCommand; | ||
324 | while ((currentCommand = readFile.ReadLine()) != null) | ||
325 | { | ||
326 | if (currentCommand != String.Empty) | ||
327 | { | ||
328 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
329 | MainConsole.Instance.RunCommand(currentCommand); | ||
330 | } | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | |||
336 | |||
337 | protected virtual void ReadConfig() | 237 | protected virtual void ReadConfig() |
338 | { | 238 | { |
339 | } | 239 | } |
@@ -341,50 +241,5 @@ namespace OpenSim.Server.Base | |||
341 | protected virtual void Initialise() | 241 | protected virtual void Initialise() |
342 | { | 242 | { |
343 | } | 243 | } |
344 | |||
345 | protected void CreatePIDFile(string path) | ||
346 | { | ||
347 | try | ||
348 | { | ||
349 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | ||
350 | FileStream fs = File.Create(path); | ||
351 | Byte[] buf = Encoding.ASCII.GetBytes(pidstring); | ||
352 | fs.Write(buf, 0, buf.Length); | ||
353 | fs.Close(); | ||
354 | m_pidFile = path; | ||
355 | } | ||
356 | catch (Exception) | ||
357 | { | ||
358 | } | ||
359 | } | ||
360 | |||
361 | public virtual void HandleShow(string module, string[] cmd) | ||
362 | { | ||
363 | List<string> args = new List<string>(cmd); | ||
364 | |||
365 | args.RemoveAt(0); | ||
366 | |||
367 | string[] showParams = args.ToArray(); | ||
368 | |||
369 | switch (showParams[0]) | ||
370 | { | ||
371 | case "uptime": | ||
372 | MainConsole.Instance.Output(GetUptimeReport()); | ||
373 | break; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | /// <summary> | ||
378 | /// Return a report about the uptime of this server | ||
379 | /// </summary> | ||
380 | /// <returns></returns> | ||
381 | protected string GetUptimeReport() | ||
382 | { | ||
383 | StringBuilder sb = new StringBuilder(String.Format("Time now is {0}\n", DateTime.Now)); | ||
384 | sb.Append(String.Format("Server has been running since {0}, {1}\n", m_startuptime.DayOfWeek, m_startuptime)); | ||
385 | sb.Append(String.Format("That is an elapsed time of {0}\n", DateTime.Now - m_startuptime)); | ||
386 | |||
387 | return sb.ToString(); | ||
388 | } | ||
389 | } | 244 | } |
390 | } | 245 | } \ No newline at end of file |