Compare commits

...

2 Commits

Author SHA1 Message Date
prplV 56a20eb65c preboot fix work with config params + refactor 2024-12-16 11:44:34 +03:00
prplV 2dbfb4a93a preboot fix work with params 2024-12-16 11:34:09 +03:00
2 changed files with 19 additions and 17 deletions

View File

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