diff options
author | Melanie Thielker | 2009-01-02 12:57:21 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-01-02 12:57:21 +0000 |
commit | b175e8f6cd70dc3de0b837eedf2f243c7acfbfb7 (patch) | |
tree | 6cff3913be562c2e19a0e2b0a4480a56a48323f5 /OpenSim/Region/Application | |
parent | Add the ability to read the ini file from a URI. If the -inifile option (diff) | |
download | opensim-SC_OLD-b175e8f6cd70dc3de0b837eedf2f243c7acfbfb7.zip opensim-SC_OLD-b175e8f6cd70dc3de0b837eedf2f243c7acfbfb7.tar.gz opensim-SC_OLD-b175e8f6cd70dc3de0b837eedf2f243c7acfbfb7.tar.bz2 opensim-SC_OLD-b175e8f6cd70dc3de0b837eedf2f243c7acfbfb7.tar.xz |
Fixes Mantis #2945
Committing the above patch with changes. Thank you, Gerhard. Removed
unneccessary verbosity in case of no error, added more output for errors.
Added support for HTTP Uri fetching which I had added in my last commit.
Converted the Console.WriteLines to log4net.
Diffstat (limited to 'OpenSim/Region/Application')
-rw-r--r-- | OpenSim/Region/Application/ConfigurationLoader.cs | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index d55ad32..7ee4062 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs | |||
@@ -35,6 +35,10 @@ using OpenSim.Framework; | |||
35 | using Nini; | 35 | using Nini; |
36 | using Nini.Config; | 36 | using Nini.Config; |
37 | 37 | ||
38 | using System.Reflection; | ||
39 | using log4net; | ||
40 | |||
41 | |||
38 | namespace OpenSim | 42 | namespace OpenSim |
39 | { | 43 | { |
40 | public class ConfigurationLoader | 44 | public class ConfigurationLoader |
@@ -43,6 +47,8 @@ namespace OpenSim | |||
43 | protected OpenSimConfigSource m_config; | 47 | protected OpenSimConfigSource m_config; |
44 | protected NetworkServersInfo m_networkServersInfo; | 48 | protected NetworkServersInfo m_networkServersInfo; |
45 | 49 | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
46 | public ConfigurationLoader() | 52 | public ConfigurationLoader() |
47 | { | 53 | { |
48 | } | 54 | } |
@@ -65,14 +71,41 @@ namespace OpenSim | |||
65 | m_config.Source = new IniConfigSource(); | 71 | m_config.Source = new IniConfigSource(); |
66 | m_config.Source.Merge(DefaultConfig()); | 72 | m_config.Source.Merge(DefaultConfig()); |
67 | 73 | ||
68 | //check for .INI file (either default or name passed in command line) | 74 | m_log.Info("Reading in config files now"); |
69 | if (File.Exists(masterfilePath)) | 75 | |
76 | //check for master .INI file (name passed in command line, no default) | ||
77 | if (masterFileName.Length != 0) // If a master file name is given ... | ||
78 | { | ||
79 | m_log.InfoFormat("[CONFIG] Reading config master file {0}", Path.GetFullPath(masterfilePath)); | ||
80 | if (File.Exists(masterfilePath)) | ||
81 | { | ||
82 | m_config.Source.Merge(new IniConfigSource(masterfilePath)); | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | // IF(!) a master file is given it must exist, be readable, ...... | ||
87 | // Otherwise the application will hickup | ||
88 | m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath); | ||
89 | Environment.Exit(1); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | // Check for .INI file (either default or name passed on command | ||
94 | // line) or XML config source | ||
95 | // | ||
96 | String xmlPath = Path.Combine(Util.configDir(), "OpenSim.xml"); | ||
97 | bool isUri = false; | ||
98 | Uri configUri; | ||
99 | |||
100 | if (Uri.TryCreate(startupConfig.GetString("inifile", "OpenSim.ini"), UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp) | ||
70 | { | 101 | { |
71 | m_config.Source.Merge(new IniConfigSource(masterfilePath)); | 102 | isUri = true; |
72 | } | 103 | } |
73 | 104 | ||
74 | if (File.Exists(Application.iniFilePath)) | 105 | if (!isUri && File.Exists(Application.iniFilePath)) |
75 | { | 106 | { |
107 | m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(Application.iniFilePath)); | ||
108 | |||
76 | iniFileExists = true; | 109 | iniFileExists = true; |
77 | 110 | ||
78 | // From reading Nini's code, it seems that later merged keys replace earlier ones. | 111 | // From reading Nini's code, it seems that later merged keys replace earlier ones. |
@@ -80,11 +113,9 @@ namespace OpenSim | |||
80 | } | 113 | } |
81 | else | 114 | else |
82 | { | 115 | { |
83 | Uri configUri; | 116 | if (isUri) |
84 | |||
85 | if (Uri.TryCreate(startupConfig.GetString("inifile", "OpenSim.ini"), UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp) | ||
86 | { | 117 | { |
87 | Console.WriteLine("[CONFIG] {0} is a URI, fetching ...", startupConfig.GetString("inifile", "OpenSim.ini")); | 118 | m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", startupConfig.GetString("inifile", "OpenSim.ini")); |
88 | 119 | ||
89 | // The ini file path is a http URI | 120 | // The ini file path is a http URI |
90 | // Try to read it | 121 | // Try to read it |
@@ -96,20 +127,23 @@ namespace OpenSim | |||
96 | m_config.Source.Merge(cs); | 127 | m_config.Source.Merge(cs); |
97 | 128 | ||
98 | iniFileExists = true; | 129 | iniFileExists = true; |
99 | Console.WriteLine("[CONFIG] Uri fetch complete"); | 130 | m_log.InfoFormat("[CONFIG] Loaded config from {0}", startupConfig.GetString("inifile", "OpenSim.ini")); |
100 | } | 131 | } |
101 | catch (Exception e) | 132 | catch (Exception e) |
102 | { | 133 | { |
103 | Console.WriteLine("Exception {0} reading config from URI {1}", e.ToString(), startupConfig.GetString("inifile", "OpenSim.ini")); | 134 | m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), startupConfig.GetString("inifile", "OpenSim.ini")); |
135 | Environment.Exit(1); | ||
104 | } | 136 | } |
105 | } | 137 | } |
106 | else | 138 | else |
107 | { | 139 | { |
108 | // check for a xml config file | 140 | // check for a xml config file |
109 | Application.iniFilePath = Path.Combine(Util.configDir(), "OpenSim.xml"); | ||
110 | 141 | ||
111 | if (File.Exists(Application.iniFilePath)) | 142 | if (File.Exists(xmlPath)) |
112 | { | 143 | { |
144 | Application.iniFilePath = xmlPath; | ||
145 | |||
146 | m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath)); | ||
113 | iniFileExists = true; | 147 | iniFileExists = true; |
114 | 148 | ||
115 | m_config.Source = new XmlConfigSource(); | 149 | m_config.Source = new XmlConfigSource(); |
@@ -121,7 +155,17 @@ namespace OpenSim | |||
121 | m_config.Source.Merge(configSource); | 155 | m_config.Source.Merge(configSource); |
122 | 156 | ||
123 | if (!iniFileExists) | 157 | if (!iniFileExists) |
124 | m_config.Save("OpenSim.ini"); | 158 | { |
159 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); | ||
160 | if (!isUri) | ||
161 | m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(Application.iniFilePath)); | ||
162 | else | ||
163 | m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", startupConfig.GetString("inifile", "OpenSim.ini")); | ||
164 | m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath)); | ||
165 | |||
166 | m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); | ||
167 | Environment.Exit(1); | ||
168 | } | ||
125 | 169 | ||
126 | ReadConfigSettings(); | 170 | ReadConfigSettings(); |
127 | 171 | ||