Compare commits

..

No commits in common. "56a20eb65c7c2b0163b0324e49ef3be912e1f1e4" and "77a1e24a47734397338518acb923742d91b6c2dc" have entirely different histories.

2 changed files with 17 additions and 19 deletions

View File

@ -7,11 +7,10 @@ use std::os::unix::process::CommandExt;
use std::process::Command; use std::process::Command;
use std::sync::Arc; use std::sync::Arc;
use std::{env, fs}; use std::{env, fs};
use std::fmt::format; use tokio::time::Duration;
use super::preboot::PrebootParams; use super::preboot::PrebootParams;
use tokio::time::{Duration, sleep};
// const CONFIG_PATH: &str = "settings.json"; const CONFIG_PATH: &str = "settings.json";
/// # Fn `load_processes` /// # Fn `load_processes`
/// ## for reading and parsing *local* storing config /// ## for reading and parsing *local* storing config
@ -71,7 +70,7 @@ pub async fn get_actual_config(params : Arc<PrebootParams>) -> Option<Processes>
} }
ConfigActuality::Remote => { ConfigActuality::Remote => {
info!("Pulled config is more actual. Saving changes!"); info!("Pulled config is more actual. Saving changes!");
if save_new_config(&remote_conf, config_path).is_err() { if save_new_config(&remote_conf, CONFIG_PATH).is_err() {
error!("Saving changes process failed due to unexpected error...") error!("Saving changes process failed due to unexpected error...")
} }
Some(remote_conf) Some(remote_conf)
@ -84,10 +83,11 @@ pub async fn get_actual_config(params : Arc<PrebootParams>) -> Option<Processes>
None => { None => {
warn!("No local valid conf was found. Trying to pull remote one..."); warn!("No local valid conf was found. Trying to pull remote one...");
if !params.no_remote_config { if !params.no_remote_config {
let mut conn = get_connection_watcher(&open_watcher(&format!("redis://{}/", &params.remote_server_url))); let mut conn = get_connection_watcher(&open_watcher("redis://localhost/"));
if let Some(conf) = get_remote_conf_watcher(&mut conn).await { let remote_config = get_remote_conf_watcher(&mut conn).await;
if let Some(conf) = remote_config {
info!("Config {} was pulled from Redis-Server. Starting...", &conf.date_of_creation); info!("Config {} was pulled from Redis-Server. Starting...", &conf.date_of_creation);
let _ = save_new_config(&conf, config_path); let _ = save_new_config(&conf, CONFIG_PATH);
return Some(conf); return Some(conf);
} }
} }
@ -189,23 +189,23 @@ fn once_get_remote_configuration(serv_info: &str) -> Option<Processes> {
if remote.is_none() { if remote.is_none() {
error!("Pulled config is invalid. Check it in Redis Server"); error!("Pulled config is invalid. Check it in Redis Server");
} }
remote return remote;
}, },
Err(_) => { Err(_) => {
error!("Cannot extract payload from new message. Check Redis Server state"); error!("Cannot extract payload from new message. Check Redis Server state");
None return None;
}, },
} }
}, },
Err(_) => { Err(_) => {
warn!("Cannot get config from Redis Server. Empty channel"); warn!("Cannot get config from Redis Server. Empty channel");
None return None;
}, },
} }
}, },
Err(_) => { Err(_) => {
error!("Redis subscription process failed. Check Redis configuration!"); error!("Redis subscription process failed. Check Redis configuration!");
None return None;
} }
} }
} }
@ -319,8 +319,6 @@ fn restart_main_thread() -> std::io::Result<()> {
/// *depends on* : `Processes` /// *depends on* : `Processes`
/// ///
pub async fn subscribe_config_stream(actual_prcs: Arc<Processes>, params: Arc<PrebootParams>) -> Result<(), CustomError> { pub async fn subscribe_config_stream(actual_prcs: Arc<Processes>, params: Arc<PrebootParams>) -> Result<(), CustomError> {
let config_path = params.config.to_str().unwrap_or_else(|| "settings.json");
if params.no_sub || params.no_remote_config { if params.no_sub || params.no_remote_config {
return Err(CustomError::Fatal); return Err(CustomError::Fatal);
} }
@ -342,8 +340,8 @@ pub async fn subscribe_config_stream(actual_prcs: Arc<Processes>, params: Arc<Pr
match config_comparing(&actual_prcs, &remote_config) { match config_comparing(&actual_prcs, &remote_config) {
ConfigActuality::Remote => { ConfigActuality::Remote => {
warn!("Pulled config is actual. Saving and restarting..."); warn!("Pulled config is actual. Saving and restarting...");
if save_new_config(&remote_config, config_path).is_err() { if save_new_config(&remote_config, CONFIG_PATH).is_err() {
error!("Error with saving new config to {}. Stopping sub mechanism...", config_path); error!("Error with saving new config to {}. Stopping sub mechanism...", &CONFIG_PATH);
return Err(CustomError::Fatal); return Err(CustomError::Fatal);
} }
if restart_main_thread().is_err() { if restart_main_thread().is_err() {
@ -364,7 +362,7 @@ pub async fn subscribe_config_stream(actual_prcs: Arc<Processes>, params: Arc<Pr
}, },
} }
} }
sleep(Duration::from_secs(30)).await; tokio::time::sleep(tokio::time::Duration::from_secs(30)).await;
} }
} else { } else {
error!("Cannot subscribe channel {}. Check Redis Server status", &channel_name); error!("Cannot subscribe channel {}. Check Redis Server status", &channel_name);
@ -445,7 +443,7 @@ fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomEr
Err(_) => Err(CustomError::Fatal), Err(_) => Err(CustomError::Fatal),
} }
} }
Err(_) => Err(CustomError::Fatal), Err(_) => return Err(CustomError::Fatal),
} }
} }
Err(_) => Err(CustomError::Fatal), Err(_) => Err(CustomError::Fatal),

View File

@ -103,11 +103,11 @@ pub struct PrebootParams {
impl PrebootParams { impl PrebootParams {
pub fn validate(self) -> Result<Self> { pub fn validate(self) -> Result<Self> {
if !self.socket_path.exists() && !self.no_hostagent { if !self.socket_path.exists() {
return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start")); return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start"));
} }
// existing log dir // existing log dir
if !self.log_to.exists() && !self.no_logs { if !self.log_to.exists() {
return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start")); return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start"));
} }
// existing sock file // existing sock file