aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDev Random2014-02-25 08:24:22 -0500
committerJustin Clark-Casey (justincc)2014-02-26 23:39:45 +0000
commit6955190c7db2563927bc53fd47ed0b47094be45c (patch)
treef1194c1d68f79887df86abf766bcad104516879d
parentAdd some regression tests for previous commit 0e23374 (diff)
downloadopensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.zip
opensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.tar.gz
opensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.tar.bz2
opensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.tar.xz
Add Util method to load OpSys env vars
-rw-r--r--OpenSim/Framework/Util.cs170
-rw-r--r--OpenSim/Region/Application/ConfigurationLoader.cs24
-rw-r--r--OpenSim/Server/Base/ServicesServerBase.cs34
3 files changed, 104 insertions, 124 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index c7377b8..65cf177 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -946,11 +946,12 @@ namespace OpenSim.Framework
946 } 946 }
947 947
948 #region Nini (config) related Methods 948 #region Nini (config) related Methods
949
949 public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName) 950 public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName)
950 { 951 {
951 if (!File.Exists(fileName)) 952 if (!File.Exists(fileName))
952 { 953 {
953 //create new file 954 // create new file
954 } 955 }
955 XmlConfigSource config = new XmlConfigSource(fileName); 956 XmlConfigSource config = new XmlConfigSource(fileName);
956 AddDataRowToConfig(config, row); 957 AddDataRowToConfig(config, row);
@@ -968,25 +969,6 @@ namespace OpenSim.Framework
968 } 969 }
969 } 970 }
970 971
971 public static string GetConfigVarWithDefaultSection(IConfigSource config, string varname, string section)
972 {
973 // First, check the Startup section, the default section
974 IConfig cnf = config.Configs["Startup"];
975 if (cnf == null)
976 return string.Empty;
977 string val = cnf.GetString(varname, string.Empty);
978
979 // Then check for an overwrite of the default in the given section
980 if (!string.IsNullOrEmpty(section))
981 {
982 cnf = config.Configs[section];
983 if (cnf != null)
984 val = cnf.GetString(varname, val);
985 }
986
987 return val;
988 }
989
990 /// <summary> 972 /// <summary>
991 /// Gets the value of a configuration variable by looking into 973 /// Gets the value of a configuration variable by looking into
992 /// multiple sections in order. The latter sections overwrite 974 /// multiple sections in order. The latter sections overwrite
@@ -1039,6 +1021,91 @@ namespace OpenSim.Framework
1039 return (T)val; 1021 return (T)val;
1040 } 1022 }
1041 1023
1024 public static void MergeEnvironmentToConfig(IConfigSource ConfigSource)
1025 {
1026 IConfig enVars = ConfigSource.Configs["Environment"];
1027 // if section does not exist then user isn't expecting them, so don't bother.
1028 if( enVars != null )
1029 {
1030 // load the values from the environment
1031 EnvConfigSource envConfigSource = new EnvConfigSource();
1032 // add the requested keys
1033 string[] env_keys = enVars.GetKeys();
1034 foreach ( string key in env_keys )
1035 {
1036 envConfigSource.AddEnv(key, string.Empty);
1037 }
1038 // load the values from environment
1039 envConfigSource.LoadEnv();
1040 // add them in to the master
1041 ConfigSource.Merge(envConfigSource);
1042 ConfigSource.ExpandKeyValues();
1043 }
1044 }
1045
1046 public static T ReadSettingsFromIniFile<T>(IConfig config, T settingsClass)
1047 {
1048 Type settingsType = settingsClass.GetType();
1049
1050 FieldInfo[] fieldInfos = settingsType.GetFields();
1051 foreach (FieldInfo fieldInfo in fieldInfos)
1052 {
1053 if (!fieldInfo.IsStatic)
1054 {
1055 if (fieldInfo.FieldType == typeof(System.String))
1056 {
1057 fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass)));
1058 }
1059 else if (fieldInfo.FieldType == typeof(System.Boolean))
1060 {
1061 fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass)));
1062 }
1063 else if (fieldInfo.FieldType == typeof(System.Int32))
1064 {
1065 fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass)));
1066 }
1067 else if (fieldInfo.FieldType == typeof(System.Single))
1068 {
1069 fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass)));
1070 }
1071 else if (fieldInfo.FieldType == typeof(System.UInt32))
1072 {
1073 fieldInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
1074 }
1075 }
1076 }
1077
1078 PropertyInfo[] propertyInfos = settingsType.GetProperties();
1079 foreach (PropertyInfo propInfo in propertyInfos)
1080 {
1081 if ((propInfo.CanRead) && (propInfo.CanWrite))
1082 {
1083 if (propInfo.PropertyType == typeof(System.String))
1084 {
1085 propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null);
1086 }
1087 else if (propInfo.PropertyType == typeof(System.Boolean))
1088 {
1089 propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null);
1090 }
1091 else if (propInfo.PropertyType == typeof(System.Int32))
1092 {
1093 propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null);
1094 }
1095 else if (propInfo.PropertyType == typeof(System.Single))
1096 {
1097 propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
1098 }
1099 if (propInfo.PropertyType == typeof(System.UInt32))
1100 {
1101 propInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
1102 }
1103 }
1104 }
1105
1106 return settingsClass;
1107 }
1108
1042 #endregion 1109 #endregion
1043 1110
1044 public static float Clip(float x, float min, float max) 1111 public static float Clip(float x, float min, float max)
@@ -1411,69 +1478,6 @@ namespace OpenSim.Framework
1411 return displayConnectionString; 1478 return displayConnectionString;
1412 } 1479 }
1413 1480
1414 public static T ReadSettingsFromIniFile<T>(IConfig config, T settingsClass)
1415 {
1416 Type settingsType = settingsClass.GetType();
1417
1418 FieldInfo[] fieldInfos = settingsType.GetFields();
1419 foreach (FieldInfo fieldInfo in fieldInfos)
1420 {
1421 if (!fieldInfo.IsStatic)
1422 {
1423 if (fieldInfo.FieldType == typeof(System.String))
1424 {
1425 fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass)));
1426 }
1427 else if (fieldInfo.FieldType == typeof(System.Boolean))
1428 {
1429 fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass)));
1430 }
1431 else if (fieldInfo.FieldType == typeof(System.Int32))
1432 {
1433 fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass)));
1434 }
1435 else if (fieldInfo.FieldType == typeof(System.Single))
1436 {
1437 fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass)));
1438 }
1439 else if (fieldInfo.FieldType == typeof(System.UInt32))
1440 {
1441 fieldInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
1442 }
1443 }
1444 }
1445
1446 PropertyInfo[] propertyInfos = settingsType.GetProperties();
1447 foreach (PropertyInfo propInfo in propertyInfos)
1448 {
1449 if ((propInfo.CanRead) && (propInfo.CanWrite))
1450 {
1451 if (propInfo.PropertyType == typeof(System.String))
1452 {
1453 propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null);
1454 }
1455 else if (propInfo.PropertyType == typeof(System.Boolean))
1456 {
1457 propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null);
1458 }
1459 else if (propInfo.PropertyType == typeof(System.Int32))
1460 {
1461 propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null);
1462 }
1463 else if (propInfo.PropertyType == typeof(System.Single))
1464 {
1465 propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
1466 }
1467 if (propInfo.PropertyType == typeof(System.UInt32))
1468 {
1469 propInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
1470 }
1471 }
1472 }
1473
1474 return settingsClass;
1475 }
1476
1477 public static string Base64ToString(string str) 1481 public static string Base64ToString(string str)
1478 { 1482 {
1479 Decoder utf8Decode = Encoding.UTF8.GetDecoder(); 1483 Decoder utf8Decode = Encoding.UTF8.GetDecoder();
diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs
index 52e520c..06ce145 100644
--- a/OpenSim/Region/Application/ConfigurationLoader.cs
+++ b/OpenSim/Region/Application/ConfigurationLoader.cs
@@ -82,8 +82,7 @@ namespace OpenSim
82 82
83 List<string> sources = new List<string>(); 83 List<string> sources = new List<string>();
84 84
85 string masterFileName = 85 string masterFileName = startupConfig.GetString("inimaster", "OpenSimDefaults.ini");
86 startupConfig.GetString("inimaster", "OpenSimDefaults.ini");
87 86
88 if (masterFileName == "none") 87 if (masterFileName == "none")
89 masterFileName = String.Empty; 88 masterFileName = String.Empty;
@@ -207,26 +206,13 @@ namespace OpenSim
207 Environment.Exit(1); 206 Environment.Exit(1);
208 } 207 }
209 208
209 // Merge OpSys env vars
210 m_log.Info("[CONFIG]: Loading environment variables for Config");
211 Util.MergeEnvironmentToConfig(m_config.Source);
212
210 // Make sure command line options take precedence 213 // Make sure command line options take precedence
211 m_config.Source.Merge(argvSource); 214 m_config.Source.Merge(argvSource);
212 215
213 IConfig enVars = m_config.Source.Configs["Environment"];
214
215 if( enVars != null )
216 {
217 string[] env_keys = enVars.GetKeys();
218
219 foreach ( string key in env_keys )
220 {
221 envConfigSource.AddEnv(key, string.Empty);
222 }
223
224 envConfigSource.LoadEnv();
225 m_config.Source.Merge(envConfigSource);
226 }
227
228 m_config.Source.ExpandKeyValues();
229
230 ReadConfigSettings(); 216 ReadConfigSettings();
231 217
232 return m_config; 218 return m_config;
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs
index 667cef8..8352ee2 100644
--- a/OpenSim/Server/Base/ServicesServerBase.cs
+++ b/OpenSim/Server/Base/ServicesServerBase.cs
@@ -49,9 +49,7 @@ namespace OpenSim.Server.Base
49 { 49 {
50 // Logger 50 // Logger
51 // 51 //
52 private static readonly ILog m_log = 52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 LogManager.GetLogger(
54 MethodBase.GetCurrentMethod().DeclaringType);
55 53
56 // Command line args 54 // Command line args
57 // 55 //
@@ -72,11 +70,9 @@ namespace OpenSim.Server.Base
72 public ServicesServerBase(string prompt, string[] args) : base() 70 public ServicesServerBase(string prompt, string[] args) : base()
73 { 71 {
74 // Save raw arguments 72 // Save raw arguments
75 //
76 m_Arguments = args; 73 m_Arguments = args;
77 74
78 // Read command line 75 // Read command line
79 //
80 ArgvConfigSource argvConfig = new ArgvConfigSource(args); 76 ArgvConfigSource argvConfig = new ArgvConfigSource(args);
81 77
82 argvConfig.AddSwitch("Startup", "console", "c"); 78 argvConfig.AddSwitch("Startup", "console", "c");
@@ -86,7 +82,6 @@ namespace OpenSim.Server.Base
86 argvConfig.AddSwitch("Startup", "logconfig", "g"); 82 argvConfig.AddSwitch("Startup", "logconfig", "g");
87 83
88 // Automagically create the ini file name 84 // Automagically create the ini file name
89 //
90 string fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location); 85 string fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
91 string iniFile = fileName + ".ini"; 86 string iniFile = fileName + ".ini";
92 string logConfig = null; 87 string logConfig = null;
@@ -95,19 +90,17 @@ namespace OpenSim.Server.Base
95 if (startupConfig != null) 90 if (startupConfig != null)
96 { 91 {
97 // Check if a file name was given on the command line 92 // Check if a file name was given on the command line
98 //
99 iniFile = startupConfig.GetString("inifile", iniFile); 93 iniFile = startupConfig.GetString("inifile", iniFile);
100 // 94
101 // Check if a prompt was given on the command line 95 // Check if a prompt was given on the command line
102 prompt = startupConfig.GetString("prompt", prompt); 96 prompt = startupConfig.GetString("prompt", prompt);
103 // 97
104 // Check for a Log4Net config file on the command line 98 // Check for a Log4Net config file on the command line
105 logConfig =startupConfig.GetString("logconfig",logConfig); 99 logConfig =startupConfig.GetString("logconfig", logConfig);
106 } 100 }
107 101
108 // Find out of the file name is a URI and remote load it 102 // Find out of the file name is a URI and remote load it if possible.
109 // if it's possible. Load it as a local file otherwise. 103 // Load it as a local file otherwise.
110 //
111 Uri configUri; 104 Uri configUri;
112 105
113 try 106 try
@@ -129,13 +122,14 @@ namespace OpenSim.Server.Base
129 Environment.Exit(1); 122 Environment.Exit(1);
130 } 123 }
131 124
132 // Merge the configuration from the command line into the 125 // Merge OpSys env vars
133 // loaded file 126 m_log.Info("[CONFIG]: Loading environment variables for Config");
134 // 127 Util.MergeEnvironmentToConfig(Config);
128
129 // Merge the configuration from the command line into the loaded file
135 Config.Merge(argvConfig); 130 Config.Merge(argvConfig);
136 131
137 // Refresh the startupConfig post merge 132 // Refresh the startupConfig post merge
138 //
139 if (Config.Configs["Startup"] != null) 133 if (Config.Configs["Startup"] != null)
140 { 134 {
141 startupConfig = Config.Configs["Startup"]; 135 startupConfig = Config.Configs["Startup"];
@@ -145,13 +139,10 @@ namespace OpenSim.Server.Base
145 139
146 prompt = startupConfig.GetString("Prompt", prompt); 140 prompt = startupConfig.GetString("Prompt", prompt);
147 141
148 // Allow derived classes to load config before the console is 142 // Allow derived classes to load config before the console is opened.
149 // opened.
150 //
151 ReadConfig(); 143 ReadConfig();
152 144
153 // Create main console 145 // Create main console
154 //
155 string consoleType = "local"; 146 string consoleType = "local";
156 if (startupConfig != null) 147 if (startupConfig != null)
157 consoleType = startupConfig.GetString("console", consoleType); 148 consoleType = startupConfig.GetString("console", consoleType);
@@ -195,7 +186,6 @@ namespace OpenSim.Server.Base
195 186
196 // Allow derived classes to perform initialization that 187 // Allow derived classes to perform initialization that
197 // needs to be done after the console has opened 188 // needs to be done after the console has opened
198 //
199 Initialise(); 189 Initialise();
200 } 190 }
201 191