diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 175 |
1 files changed, 15 insertions, 160 deletions
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 2f12288..ecd69b0 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,15 +56,6 @@ 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 | public string ConfigDirectory | 59 | public string ConfigDirectory |
68 | { | 60 | { |
69 | get; | 61 | get; |
@@ -74,21 +66,10 @@ namespace OpenSim.Server.Base | |||
74 | // | 66 | // |
75 | private bool m_Running = true; | 67 | private bool m_Running = true; |
76 | 68 | ||
77 | // PID file | ||
78 | // | ||
79 | private string m_pidFile = String.Empty; | ||
80 | |||
81 | /// <summary> | ||
82 | /// Time at which this server was started | ||
83 | /// </summary> | ||
84 | protected DateTime m_startuptime; | ||
85 | |||
86 | // Handle all the automagical stuff | 69 | // Handle all the automagical stuff |
87 | // | 70 | // |
88 | public ServicesServerBase(string prompt, string[] args) | 71 | public ServicesServerBase(string prompt, string[] args) : base() |
89 | { | 72 | { |
90 | m_startuptime = DateTime.Now; | ||
91 | |||
92 | // Save raw arguments | 73 | // Save raw arguments |
93 | // | 74 | // |
94 | m_Arguments = args; | 75 | m_Arguments = args; |
@@ -134,11 +115,11 @@ namespace OpenSim.Server.Base | |||
134 | configUri.Scheme == Uri.UriSchemeHttp) | 115 | configUri.Scheme == Uri.UriSchemeHttp) |
135 | { | 116 | { |
136 | XmlReader r = XmlReader.Create(iniFile); | 117 | XmlReader r = XmlReader.Create(iniFile); |
137 | m_Config = new XmlConfigSource(r); | 118 | Config = new XmlConfigSource(r); |
138 | } | 119 | } |
139 | else | 120 | else |
140 | { | 121 | { |
141 | m_Config = new IniConfigSource(iniFile); | 122 | Config = new IniConfigSource(iniFile); |
142 | } | 123 | } |
143 | } | 124 | } |
144 | catch (Exception e) | 125 | catch (Exception e) |
@@ -150,13 +131,13 @@ namespace OpenSim.Server.Base | |||
150 | // Merge the configuration from the command line into the | 131 | // Merge the configuration from the command line into the |
151 | // loaded file | 132 | // loaded file |
152 | // | 133 | // |
153 | m_Config.Merge(argvConfig); | 134 | Config.Merge(argvConfig); |
154 | 135 | ||
155 | // Refresh the startupConfig post merge | 136 | // Refresh the startupConfig post merge |
156 | // | 137 | // |
157 | if (m_Config.Configs["Startup"] != null) | 138 | if (Config.Configs["Startup"] != null) |
158 | { | 139 | { |
159 | startupConfig = m_Config.Configs["Startup"]; | 140 | startupConfig = Config.Configs["Startup"]; |
160 | } | 141 | } |
161 | 142 | ||
162 | ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); | 143 | ConfigDirectory = startupConfig.GetString("ConfigDirectory", "."); |
@@ -188,6 +169,8 @@ namespace OpenSim.Server.Base | |||
188 | MainConsole.Instance = new LocalConsole(prompt); | 169 | MainConsole.Instance = new LocalConsole(prompt); |
189 | } | 170 | } |
190 | 171 | ||
172 | m_console = MainConsole.Instance; | ||
173 | |||
191 | // Configure the appenders for log4net | 174 | // Configure the appenders for log4net |
192 | // | 175 | // |
193 | OpenSimAppender consoleAppender = null; | 176 | OpenSimAppender consoleAppender = null; |
@@ -203,54 +186,15 @@ namespace OpenSim.Server.Base | |||
203 | XmlConfigurator.Configure(); | 186 | XmlConfigurator.Configure(); |
204 | } | 187 | } |
205 | 188 | ||
206 | ILoggerRepository repository = LogManager.GetRepository(); | 189 | RegisterCommonAppenders(startupConfig); |
207 | IAppender[] appenders = repository.GetAppenders(); | ||
208 | |||
209 | foreach (IAppender appender in appenders) | ||
210 | { | ||
211 | if (appender.Name == "Console") | ||
212 | { | ||
213 | consoleAppender = (OpenSimAppender)appender; | ||
214 | } | ||
215 | if (appender.Name == "LogFileAppender") | ||
216 | { | ||
217 | fileAppender = (FileAppender)appender; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | if (consoleAppender == null) | ||
222 | { | ||
223 | System.Console.WriteLine("No console appender found. Server can't start"); | ||
224 | Thread.CurrentThread.Abort(); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | consoleAppender.Console = (ConsoleBase)MainConsole.Instance; | ||
229 | |||
230 | if (null == consoleAppender.Threshold) | ||
231 | consoleAppender.Threshold = Level.All; | ||
232 | } | ||
233 | |||
234 | // Set log file | ||
235 | // | ||
236 | if (fileAppender != null) | ||
237 | { | ||
238 | if (startupConfig != null) | ||
239 | { | ||
240 | string cfgFileName = startupConfig.GetString("logfile", null); | ||
241 | if (cfgFileName != null) | ||
242 | { | ||
243 | fileAppender.File = cfgFileName; | ||
244 | fileAppender.ActivateOptions(); | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | 190 | ||
249 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) | 191 | if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) |
250 | { | 192 | { |
251 | CreatePIDFile(startupConfig.GetString("PIDFile")); | 193 | CreatePIDFile(startupConfig.GetString("PIDFile")); |
252 | } | 194 | } |
253 | 195 | ||
196 | RegisterCommonCommands(); | ||
197 | |||
254 | // Register the quit command | 198 | // Register the quit command |
255 | // | 199 | // |
256 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", | 200 | MainConsole.Instance.Commands.AddCommand("General", false, "quit", |
@@ -260,16 +204,6 @@ namespace OpenSim.Server.Base | |||
260 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", | 204 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", |
261 | "shutdown", | 205 | "shutdown", |
262 | "Quit the application", HandleQuit); | 206 | "Quit the application", HandleQuit); |
263 | |||
264 | // Register a command to read other commands from a file | ||
265 | MainConsole.Instance.Commands.AddCommand("General", false, "command-script", | ||
266 | "command-script <script>", | ||
267 | "Run a command script from file", HandleScript); | ||
268 | |||
269 | MainConsole.Instance.Commands.AddCommand("General", false, "show uptime", | ||
270 | "show uptime", | ||
271 | "Show server uptime", HandleShow); | ||
272 | |||
273 | 207 | ||
274 | // Allow derived classes to perform initialization that | 208 | // Allow derived classes to perform initialization that |
275 | // needs to be done after the console has opened | 209 | // needs to be done after the console has opened |
@@ -296,8 +230,8 @@ namespace OpenSim.Server.Base | |||
296 | } | 230 | } |
297 | } | 231 | } |
298 | 232 | ||
299 | if (m_pidFile != String.Empty) | 233 | RemovePIDFile(); |
300 | File.Delete(m_pidFile); | 234 | |
301 | return 0; | 235 | return 0; |
302 | } | 236 | } |
303 | 237 | ||
@@ -305,43 +239,9 @@ namespace OpenSim.Server.Base | |||
305 | { | 239 | { |
306 | m_Running = false; | 240 | m_Running = false; |
307 | m_log.Info("[CONSOLE] Quitting"); | 241 | m_log.Info("[CONSOLE] Quitting"); |
308 | } | ||
309 | 242 | ||
310 | protected virtual void HandleScript(string module, string[] parms) | ||
311 | { | ||
312 | if (parms.Length != 2) | ||
313 | { | ||
314 | return; | ||
315 | } | ||
316 | RunCommandScript(parms[1]); | ||
317 | } | 243 | } |
318 | 244 | ||
319 | /// <summary> | ||
320 | /// Run an optional startup list of commands | ||
321 | /// </summary> | ||
322 | /// <param name="fileName"></param> | ||
323 | private void RunCommandScript(string fileName) | ||
324 | { | ||
325 | if (File.Exists(fileName)) | ||
326 | { | ||
327 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
328 | |||
329 | using (StreamReader readFile = File.OpenText(fileName)) | ||
330 | { | ||
331 | string currentCommand; | ||
332 | while ((currentCommand = readFile.ReadLine()) != null) | ||
333 | { | ||
334 | if (currentCommand != String.Empty) | ||
335 | { | ||
336 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
337 | MainConsole.Instance.RunCommand(currentCommand); | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | |||
344 | |||
345 | protected virtual void ReadConfig() | 245 | protected virtual void ReadConfig() |
346 | { | 246 | { |
347 | } | 247 | } |
@@ -349,50 +249,5 @@ namespace OpenSim.Server.Base | |||
349 | protected virtual void Initialise() | 249 | protected virtual void Initialise() |
350 | { | 250 | { |
351 | } | 251 | } |
352 | |||
353 | protected void CreatePIDFile(string path) | ||
354 | { | ||
355 | try | ||
356 | { | ||
357 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | ||
358 | FileStream fs = File.Create(path); | ||
359 | Byte[] buf = Encoding.ASCII.GetBytes(pidstring); | ||
360 | fs.Write(buf, 0, buf.Length); | ||
361 | fs.Close(); | ||
362 | m_pidFile = path; | ||
363 | } | ||
364 | catch (Exception) | ||
365 | { | ||
366 | } | ||
367 | } | ||
368 | |||
369 | public virtual void HandleShow(string module, string[] cmd) | ||
370 | { | ||
371 | List<string> args = new List<string>(cmd); | ||
372 | |||
373 | args.RemoveAt(0); | ||
374 | |||
375 | string[] showParams = args.ToArray(); | ||
376 | |||
377 | switch (showParams[0]) | ||
378 | { | ||
379 | case "uptime": | ||
380 | MainConsole.Instance.Output(GetUptimeReport()); | ||
381 | break; | ||
382 | } | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Return a report about the uptime of this server | ||
387 | /// </summary> | ||
388 | /// <returns></returns> | ||
389 | protected string GetUptimeReport() | ||
390 | { | ||
391 | StringBuilder sb = new StringBuilder(String.Format("Time now is {0}\n", DateTime.Now)); | ||
392 | sb.Append(String.Format("Server has been running since {0}, {1}\n", m_startuptime.DayOfWeek, m_startuptime)); | ||
393 | sb.Append(String.Format("That is an elapsed time of {0}\n", DateTime.Now - m_startuptime)); | ||
394 | |||
395 | return sb.ToString(); | ||
396 | } | ||
397 | } | 252 | } |
398 | } | 253 | } |