OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
BaseOpenSimServer.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using System.Text;
33 using System.Text.RegularExpressions;
34 using System.Threading;
35 using System.Timers;
36 using log4net;
37 using log4net.Appender;
38 using log4net.Core;
39 using log4net.Repository;
40 using OpenMetaverse;
41 using OpenMetaverse.StructuredData;
42 using OpenSim.Framework;
43 using OpenSim.Framework.Console;
44 using OpenSim.Framework.Monitoring;
45 using OpenSim.Framework.Servers;
46 using OpenSim.Framework.Servers.HttpServer;
48 using Nini.Config;
49 
50 namespace OpenSim.Framework.Servers
51 {
55  public abstract class BaseOpenSimServer : ServerBase
56  {
57  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 
62  public bool SuppressExit { get; set; }
63 
68 
69  private int m_periodDiagnosticTimerMS = 60 * 60 * 1000;
70  private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
71 
75  protected string m_osSecret = String.Empty;
76 
78  public BaseHttpServer HttpServer
79  {
80  get { return m_httpServer; }
81  }
82 
83  public BaseOpenSimServer() : base()
84  {
85  // Random uuid for private data
86  m_osSecret = UUID.Random().ToString();
87  }
88 
92  protected virtual void StartupSpecific()
93  {
94  StatsManager.SimExtraStats = new SimExtraStatsCollector();
95  RegisterCommonCommands();
96  RegisterCommonComponents(Config);
97 
98  IConfig startupConfig = Config.Configs["Startup"];
99  int logShowStatsSeconds = startupConfig.GetInt("LogShowStatsSeconds", m_periodDiagnosticTimerMS / 1000);
100  m_periodDiagnosticTimerMS = logShowStatsSeconds * 1000;
101  m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
102  if (m_periodDiagnosticTimerMS != 0)
103  {
104  m_periodicDiagnosticsTimer.Interval = m_periodDiagnosticTimerMS;
105  m_periodicDiagnosticsTimer.Enabled = true;
106  }
107  }
108 
109  protected override void ShutdownSpecific()
110  {
111  m_log.Info("[SHUTDOWN]: Shutdown processing on main thread complete. Exiting...");
112 
113  RemovePIDFile();
114 
115  base.ShutdownSpecific();
116 
117  if (!SuppressExit)
118  Environment.Exit(0);
119  }
120 
129  protected virtual List<string> GetHelpTopics() { return new List<string>(); }
130 
134  protected void LogDiagnostics(object source, ElapsedEventArgs e)
135  {
136  StringBuilder sb = new StringBuilder("DIAGNOSTICS\n\n");
137  sb.Append(GetUptimeReport());
138  sb.Append(StatsManager.SimExtraStats.Report());
139  sb.Append(Environment.NewLine);
140  sb.Append(GetThreadsReport());
141 
142  m_log.Debug(sb);
143  }
144 
148  public virtual void Startup()
149  {
150  m_log.Info("[STARTUP]: Beginning startup processing");
151 
152  m_log.Info("[STARTUP]: version: " + m_version + Environment.NewLine);
153  // clr version potentially is more confusing than helpful, since it doesn't tell us if we're running under Mono/MS .NET and
154  // the clr version number doesn't match the project version number under Mono.
155  //m_log.Info("[STARTUP]: Virtual machine runtime version: " + Environment.Version + Environment.NewLine);
156  m_log.InfoFormat(
157  "[STARTUP]: Operating system version: {0}, .NET platform {1}, {2}-bit\n",
158  Environment.OSVersion, Environment.OSVersion.Platform, Util.Is64BitProcess() ? "64" : "32");
159 
160  StartupSpecific();
161 
162  TimeSpan timeTaken = DateTime.Now - m_startuptime;
163 
164 // MainConsole.Instance.OutputFormat(
165 // "PLEASE WAIT FOR LOGINS TO BE ENABLED ON REGIONS ONCE SCRIPTS HAVE STARTED. Non-script portion of startup took {0}m {1}s.",
166 // timeTaken.Minutes, timeTaken.Seconds);
167  }
168 
169  public string osSecret
170  {
171  // Secret uuid for the simulator
172  get { return m_osSecret; }
173  }
174 
175  public string StatReport(IOSHttpRequest httpRequest)
176  {
177  // If we catch a request for "callback", wrap the response in the value for jsonp
178  if (httpRequest.Query.ContainsKey("callback"))
179  {
180  return httpRequest.Query["callback"].ToString() + "(" + StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version) + ");";
181  }
182  else
183  {
184  return StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version);
185  }
186  }
187  }
188 }
virtual List< string > GetHelpTopics()
Provides a list of help topics that are available. Overriding classes should append their topics to t...
string StatReport(IOSHttpRequest httpRequest)
void LogDiagnostics(object source, ElapsedEventArgs e)
Print statistics to the logfile, if they are active
Collects sim statistics which aren't already being collected for the linden viewer's statistics pane ...
System.Timers.Timer Timer
virtual void Startup()
Performs initialisation of the scene, such as loading configuration from disk.
Common base for the main OpenSimServers (user, grid, inventory, region, etc)
Interactive OpenSim region server
Definition: OpenSim.cs:55
override void ShutdownSpecific()
Should be overriden and referenced by descendents if they need to perform extra shutdown processing ...
virtual void StartupSpecific()
Must be overriden by child classes for their own server specific startup behaviour.