31 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Console;
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
71 public static void Main(
string[] args)
74 AppDomain.CurrentDomain.UnhandledException +=
75 new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
77 ServicePointManager.DefaultConnectionLimit = 12;
78 ServicePointManager.UseNagleAlgorithm =
false;
81 ArgvConfigSource configSource =
new ArgvConfigSource(args);
84 configSource.AddSwitch(
"Startup",
"logconfig");
85 string logConfigFile = configSource.Configs[
"Startup"].GetString(
"logconfig", String.Empty);
86 if (logConfigFile != String.Empty)
88 XmlConfigurator.Configure(
new System.IO.FileInfo(logConfigFile));
89 m_log.InfoFormat(
"[OPENSIM MAIN]: configured log4net using \"{0}\" as configuration file",
94 XmlConfigurator.Configure();
95 m_log.Info(
"[OPENSIM MAIN]: configured log4net using default OpenSim.exe.config");
99 "[OPENSIM MAIN]: System Locale is {0}", System.Threading.Thread.CurrentThread.CurrentCulture);
101 string monoThreadsPerCpu = System.Environment.GetEnvironmentVariable(
"MONO_THREADS_PER_CPU");
104 "[OPENSIM MAIN]: Environment variable MONO_THREADS_PER_CPU is {0}", monoThreadsPerCpu ??
"unset");
113 int workerThreadsMin = 500;
114 int workerThreadsMax = 1000;
115 int iocpThreadsMin = 1000;
116 int iocpThreadsMax = 2000;
119 int currentMinWorkerThreads, currentMinIocpThreads;
120 System.Threading.ThreadPool.GetMinThreads(out currentMinWorkerThreads, out currentMinIocpThreads);
122 "[OPENSIM MAIN]: Runtime gave us {0} min worker threads and {1} min IOCP threads",
123 currentMinWorkerThreads, currentMinIocpThreads);
126 int workerThreads, iocpThreads;
127 System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
128 m_log.InfoFormat(
"[OPENSIM MAIN]: Runtime gave us {0} max worker threads and {1} max IOCP threads", workerThreads, iocpThreads);
130 if (workerThreads < workerThreadsMin)
132 workerThreads = workerThreadsMin;
133 m_log.InfoFormat(
"[OPENSIM MAIN]: Bumping up max worker threads to {0}",workerThreads);
135 if (workerThreads > workerThreadsMax)
137 workerThreads = workerThreadsMax;
138 m_log.InfoFormat(
"[OPENSIM MAIN]: Limiting max worker threads to {0}",workerThreads);
143 if (iocpThreads < iocpThreadsMin)
145 iocpThreads = iocpThreadsMin;
146 m_log.InfoFormat(
"[OPENSIM MAIN]: Bumping up max IOCP threads to {0}",iocpThreads);
149 if ( iocpThreads > iocpThreadsMax )
151 iocpThreads = iocpThreadsMax;
152 m_log.InfoFormat(
"[OPENSIM MAIN]: Limiting max IOCP completion threads to {0}",iocpThreads);
155 if ( System.Threading.ThreadPool.SetMaxThreads(workerThreads, iocpThreads) )
158 "[OPENSIM MAIN]: Threadpool set to {0} max worker threads and {1} max IOCP threads",
159 workerThreads, iocpThreads);
163 m_log.Warn(
"[OPENSIM MAIN]: Threadpool reconfiguration failed, runtime defaults still in effect.");
168 string supported = String.Empty;
169 if (Util.IsEnvironmentSupported(ref supported))
171 m_log.Info(
"[OPENSIM MAIN]: Environment is supported by OpenSimulator.");
175 m_log.Warn(
"[OPENSIM MAIN]: Environment is not supported by OpenSimulator (" + supported +
")\n");
179 Culture.SetCurrentCulture();
288 configSource.Alias.AddAlias(
"On",
true);
289 configSource.Alias.AddAlias(
"Off",
false);
290 configSource.Alias.AddAlias(
"True",
true);
291 configSource.Alias.AddAlias(
"False",
false);
292 configSource.Alias.AddAlias(
"Yes",
true);
293 configSource.Alias.AddAlias(
"No",
false);
295 configSource.AddSwitch(
"Startup",
"background");
296 configSource.AddSwitch(
"Startup",
"inifile");
297 configSource.AddSwitch(
"Startup",
"inimaster");
298 configSource.AddSwitch(
"Startup",
"inidirectory");
299 configSource.AddSwitch(
"Startup",
"physics");
300 configSource.AddSwitch(
"Startup",
"gui");
301 configSource.AddSwitch(
"Startup",
"console");
302 configSource.AddSwitch(
"Startup",
"save_crashes");
303 configSource.AddSwitch(
"Startup",
"crash_dir");
305 configSource.AddConfig(
"StandAlone");
306 configSource.AddConfig(
"Network");
309 bool background = configSource.Configs[
"Startup"].GetBoolean(
"background",
false);
312 m_saveCrashDumps = configSource.Configs[
"Startup"].GetBoolean(
"save_crashes",
false);
333 MainConsole.Instance.Prompt();
337 m_log.ErrorFormat(
"Command error: {0}", e);
343 private static bool _IsHandlingException =
false;
350 private static void CurrentDomain_UnhandledException(
object sender, UnhandledExceptionEventArgs e)
352 if (_IsHandlingException)
357 _IsHandlingException =
true;
361 string msg = String.Empty;
363 msg +=
"APPLICATION EXCEPTION DETECTED: " + e.ToString() +
"\r\n";
366 msg +=
"Exception: " + e.ExceptionObject.ToString() +
"\r\n";
367 Exception ex = (Exception) e.ExceptionObject;
368 if (ex.InnerException != null)
370 msg +=
"InnerException: " + ex.InnerException.ToString() +
"\r\n";
374 msg +=
"Application is terminating: " + e.IsTerminating.ToString() +
"\r\n";
376 m_log.ErrorFormat(
"[APPLICATION]: {0}", msg);
387 string log = Util.GetUniqueFilename(ex.GetType() +
".txt");
388 using (StreamWriter m_crashLog =
new StreamWriter(Path.Combine(
m_crashDir, log)))
390 m_crashLog.WriteLine(msg);
393 File.Copy(
"OpenSim.ini", Path.Combine(
m_crashDir, log +
"_OpenSim.ini"),
true);
397 m_log.ErrorFormat(
"[CRASH LOGGER CRASHED]: {0}", e2);
401 _IsHandlingException =
false;
static void Main(string[] args)
Starting class for the OpenSimulator Region
static string m_crashDir
Directory to save crash reports to. Relative to bin/
Consoleless OpenSimulator region server
static OpenSimBase m_sim
Instance of the OpenSim class. This could be OpenSim or OpenSimBackground depending on the configurat...
static bool m_saveCrashDumps
Save Crashes in the bin/crashes folder. Configurable with m_crashDir
Interactive OpenSim region server
static string iniFilePath
Path to the main ini Configuration file
Common OpenSimulator simulator code