diff options
author | Melanie Thielker | 2009-05-05 01:34:41 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-05-05 01:34:41 +0000 |
commit | f28b380c4a713eac4a813d57be9c62245b8eea60 (patch) | |
tree | 35981d913222c5aa04349f753239a8722f588c08 /OpenSim/Servers/Base | |
parent | * Attempting to find cause of NotSupportedException in Asset subsystem. (diff) | |
download | opensim-SC-f28b380c4a713eac4a813d57be9c62245b8eea60.zip opensim-SC-f28b380c4a713eac4a813d57be9c62245b8eea60.tar.gz opensim-SC-f28b380c4a713eac4a813d57be9c62245b8eea60.tar.bz2 opensim-SC-f28b380c4a713eac4a813d57be9c62245b8eea60.tar.xz |
Committing the new server base
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Servers/Base/ServicesServerBase.cs | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/OpenSim/Servers/Base/ServicesServerBase.cs b/OpenSim/Servers/Base/ServicesServerBase.cs new file mode 100644 index 0000000..cc9b778 --- /dev/null +++ b/OpenSim/Servers/Base/ServicesServerBase.cs | |||
@@ -0,0 +1,225 @@ | |||
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 OpenSim 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.Xml; | ||
30 | using System.Threading; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Framework.Console; | ||
33 | using log4net; | ||
34 | using log4net.Config; | ||
35 | using log4net.Appender; | ||
36 | using log4net.Core; | ||
37 | using log4net.Repository; | ||
38 | using Nini.Config; | ||
39 | |||
40 | namespace OpenSim.Servers.Base | ||
41 | { | ||
42 | public class ServicesServerBase | ||
43 | { | ||
44 | // Logger | ||
45 | // | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | // Command line args | ||
51 | // | ||
52 | protected string[] m_Arguments; | ||
53 | |||
54 | // Configuration | ||
55 | // | ||
56 | IConfigSource m_Config = null; | ||
57 | |||
58 | // Run flag | ||
59 | // | ||
60 | private bool m_Running = true; | ||
61 | |||
62 | // Handle all the automagical stuff | ||
63 | // | ||
64 | public ServicesServerBase(string prompt, string[] args) | ||
65 | { | ||
66 | // Save raw arguments | ||
67 | // | ||
68 | m_Arguments = args; | ||
69 | |||
70 | // Read command line | ||
71 | // | ||
72 | ArgvConfigSource argvConfig = new ArgvConfigSource(args); | ||
73 | |||
74 | argvConfig.AddSwitch("Startup", "console", "c"); | ||
75 | argvConfig.AddSwitch("Startup", "logfile", "l"); | ||
76 | argvConfig.AddSwitch("Startup", "inifile", "i"); | ||
77 | |||
78 | // Automagically create the ini file name | ||
79 | // | ||
80 | string fullName = Assembly.GetEntryAssembly().FullName; | ||
81 | AssemblyName assemblyName = new AssemblyName(fullName); | ||
82 | |||
83 | string iniFile = assemblyName.Name + ".ini"; | ||
84 | |||
85 | // Check if a file name was given on the command line | ||
86 | // | ||
87 | IConfig startupConfig = argvConfig.Configs["Startup"]; | ||
88 | if (startupConfig != null) | ||
89 | iniFile = startupConfig.GetString("inifile", iniFile); | ||
90 | |||
91 | // Find out of the file name is a URI and remote load it | ||
92 | // if it's possible. Load it as a local file otherwise. | ||
93 | // | ||
94 | Uri configUri; | ||
95 | |||
96 | try | ||
97 | { | ||
98 | if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && | ||
99 | configUri.Scheme == Uri.UriSchemeHttp) | ||
100 | { | ||
101 | XmlReader r = XmlReader.Create(iniFile); | ||
102 | m_Config = new XmlConfigSource(r); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | m_Config = new IniConfigSource(iniFile); | ||
107 | } | ||
108 | } | ||
109 | catch (Exception) | ||
110 | { | ||
111 | System.Console.WriteLine("Error reading from config source {0}", | ||
112 | iniFile); | ||
113 | Thread.CurrentThread.Abort(); | ||
114 | } | ||
115 | |||
116 | // Merge the configuration from the command line into the | ||
117 | // loaded file | ||
118 | // | ||
119 | m_Config.Merge(argvConfig); | ||
120 | |||
121 | // Refresh the startupConfig post merge | ||
122 | // | ||
123 | startupConfig = argvConfig.Configs["Startup"]; | ||
124 | |||
125 | // Allow derived classes to load config before the console is | ||
126 | // opened. | ||
127 | // | ||
128 | ReadConfig(); | ||
129 | |||
130 | // Create main console | ||
131 | // | ||
132 | string consoleType = "local"; | ||
133 | if (startupConfig != null) | ||
134 | consoleType = startupConfig.GetString("console", consoleType); | ||
135 | |||
136 | if (consoleType == "basic") | ||
137 | { | ||
138 | MainConsole.Instance = new CommandConsole(prompt); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | MainConsole.Instance = new LocalConsole(prompt); | ||
143 | } | ||
144 | |||
145 | // Configure the appenders for log4net | ||
146 | // | ||
147 | OpenSimAppender consoleAppender = null; | ||
148 | FileAppender fileAppender = null; | ||
149 | |||
150 | XmlConfigurator.Configure(); | ||
151 | |||
152 | ILoggerRepository repository = LogManager.GetRepository(); | ||
153 | IAppender[] appenders = repository.GetAppenders(); | ||
154 | |||
155 | foreach (IAppender appender in appenders) | ||
156 | { | ||
157 | if (appender.Name == "Console") | ||
158 | { | ||
159 | consoleAppender = (OpenSimAppender)appender; | ||
160 | } | ||
161 | if (appender.Name == "LogFileAppender") | ||
162 | { | ||
163 | fileAppender = (FileAppender)appender; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | if (consoleAppender == null) | ||
168 | { | ||
169 | System.Console.WriteLine("No console appender found. Server can't start"); | ||
170 | Thread.CurrentThread.Abort(); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | consoleAppender.Console = MainConsole.Instance; | ||
175 | |||
176 | if (null == consoleAppender.Threshold) | ||
177 | consoleAppender.Threshold = Level.All; | ||
178 | } | ||
179 | |||
180 | // Set log file | ||
181 | // | ||
182 | if (fileAppender != null) | ||
183 | { | ||
184 | if (startupConfig != null) | ||
185 | fileAppender.File = startupConfig.GetString("logfile", | ||
186 | assemblyName.Name + ".log"); | ||
187 | } | ||
188 | |||
189 | // Register the quit command | ||
190 | // | ||
191 | MainConsole.Instance.Commands.AddCommand("base", false, "quit", | ||
192 | "quit", | ||
193 | "Quit the application", HandleQuit); | ||
194 | |||
195 | // Allow derived classes to perform initialization that | ||
196 | // needs to be done after the console has opened | ||
197 | // | ||
198 | Initialise(); | ||
199 | } | ||
200 | |||
201 | public virtual int Run() | ||
202 | { | ||
203 | while (m_Running) | ||
204 | { | ||
205 | MainConsole.Instance.Prompt(); | ||
206 | } | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | protected virtual void HandleQuit(string module, string[] args) | ||
212 | { | ||
213 | m_Running = false; | ||
214 | m_log.Info("[CONSOLE] Quitting"); | ||
215 | } | ||
216 | |||
217 | protected virtual void ReadConfig() | ||
218 | { | ||
219 | } | ||
220 | |||
221 | protected virtual void Initialise() | ||
222 | { | ||
223 | } | ||
224 | } | ||
225 | } | ||