Second environment variable override option. Set LQOS_CONFIG to the location of a .conf file, and that one will be loaded instead of the hard-coded path. This is also intended to help with multiple instances.

This commit is contained in:
Herbert Wolverson 2024-05-06 16:05:09 -05:00
parent 297bdcd58e
commit bb75727940

View File

@ -19,17 +19,23 @@ static CONFIG: Mutex<Option<Config>> = Mutex::new(None);
/// Load the configuration from `/etc/lqos.conf`.
pub fn load_config() -> Result<Config, LibreQoSConfigError> {
let mut config_location = "/etc/lqos.conf".to_string();
if let Ok(lqos_config) = std::env::var("LQOS_CONFIG") {
config_location = lqos_config;
log::info!("Overriding lqos.conf location from environment variable.");
}
let mut lock = CONFIG.lock().unwrap();
if lock.is_none() {
log::info!("Loading configuration file /etc/lqos.conf");
log::info!("Loading configuration file {config_location}");
migrate_if_needed().map_err(|e| {
log::error!("Unable to migrate configuration: {:?}", e);
LibreQoSConfigError::FileNotFoud
})?;
let file_result = std::fs::read_to_string("/etc/lqos.conf");
let file_result = std::fs::read_to_string(&config_location);
if file_result.is_err() {
log::error!("Unable to open /etc/lqos.conf");
log::error!("Unable to open {config_location}");
return Err(LibreQoSConfigError::FileNotFoud);
}
let raw = file_result.unwrap();