Compare commits
No commits in common. "56769f54b97858ef62f4a1961dc186555ff7bd77" and "1c6729daab13ff4c34f25eaea01cb7c19e543309" have entirely different histories.
56769f54b9
...
1c6729daab
|
|
@ -1,3 +0,0 @@
|
||||||
mod cli;
|
|
||||||
|
|
||||||
pub use cli::*;
|
|
||||||
|
|
@ -3,16 +3,14 @@ mod utils;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use options::config::*;
|
use options::{config::*, preboot};
|
||||||
use options::logger::setup_logger;
|
use options::logger::setup_logger;
|
||||||
use options::signals::set_valid_destructor;
|
use options::signals::set_valid_destructor;
|
||||||
use options::structs::Processes;
|
use options::structs::Processes;
|
||||||
use options::cli_pipeline::init_cli_pipeline;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use utils::*;
|
use utils::*;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use options::preboot::PrebootParams;
|
use options::preboot::PrebootParams;
|
||||||
|
|
||||||
|
|
@ -89,11 +87,6 @@ async fn main() {
|
||||||
let _ = subscribe_config_stream(Arc::new(processes)).await;
|
let _ = subscribe_config_stream(Arc::new(processes)).await;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// cli pipeline
|
|
||||||
handler.push(tokio::spawn(async move {
|
|
||||||
let _ = init_cli_pipeline().await;
|
|
||||||
}));
|
|
||||||
|
|
||||||
for i in handler {
|
for i in handler {
|
||||||
let _ = i.await;
|
let _ = i.await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,3 @@ pub mod logger;
|
||||||
pub mod signals;
|
pub mod signals;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
pub mod preboot;
|
pub mod preboot;
|
||||||
pub mod cli_pipeline;
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
use log::{error, info, warn};
|
|
||||||
use tokio::net::{TcpListener, TcpStream};
|
|
||||||
use anyhow::{Result as DynResult, Error};
|
|
||||||
use tokio::time::{sleep, Duration};
|
|
||||||
use std::{borrow::BorrowMut, net::{IpAddr, Ipv4Addr}};
|
|
||||||
// use std::io::BufReader;
|
|
||||||
use tokio::io::{BufReader, AsyncWriteExt, AsyncBufReadExt};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn init_cli_pipeline() -> DynResult<()> {
|
|
||||||
return match init_listener().await {
|
|
||||||
Some(list) => {
|
|
||||||
loop {
|
|
||||||
if let Ok((socket, addr)) = list.accept().await {
|
|
||||||
// isolation
|
|
||||||
if IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)) != addr.ip() {
|
|
||||||
warn!("Declined attempt to connect TCP-socket from {}", addr);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
process_connection(socket).await;
|
|
||||||
}
|
|
||||||
sleep(Duration::from_millis(500)).await;
|
|
||||||
}
|
|
||||||
// Ok(())
|
|
||||||
},
|
|
||||||
None => Err(Error::msg("Addr 127.0.0.1:7753 is already in use"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn init_listener() -> Option<TcpListener> {
|
|
||||||
return match TcpListener::bind("127.0.0.1:7753").await {
|
|
||||||
Ok(listener) => {
|
|
||||||
info!("Runner is listening localhost:7753");
|
|
||||||
Some(listener)
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
error!("Cannot create TCP listener for CLI");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn process_connection(mut stream: TcpStream) {
|
|
||||||
// loop{
|
|
||||||
// stream.
|
|
||||||
// }
|
|
||||||
let buf_reader = BufReader::new(stream.borrow_mut());
|
|
||||||
let mut rqst = buf_reader.lines();
|
|
||||||
|
|
||||||
while let Ok(Some(line)) = rqst.next_line().await {
|
|
||||||
if line.is_empty() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
println!("{}", line);
|
|
||||||
}
|
|
||||||
// .map(|result| result.unwrap())
|
|
||||||
// .take_while(|line| !line.is_empty())
|
|
||||||
// .collect();
|
|
||||||
let response = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\nContent-Type: text/plain\r\n\r\nHello, World!";
|
|
||||||
stream.write_all(response.as_bytes()).await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
@ -117,7 +117,6 @@ impl PrebootParams {
|
||||||
eprintln!("Local config file {} doesn't exist", &self.config.display());
|
eprintln!("Local config file {} doesn't exist", &self.config.display());
|
||||||
return Err(Error::msg("Local Config Not Found. Cannot start"));
|
return Err(Error::msg("Local Config Not Found. Cannot start"));
|
||||||
}
|
}
|
||||||
// redis server check
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ pub mod metrics;
|
||||||
pub mod prcs;
|
pub mod prcs;
|
||||||
pub mod services;
|
pub mod services;
|
||||||
|
|
||||||
// TODO : saving current flags state
|
//
|
||||||
|
|
||||||
use crate::options::structs::CustomError;
|
|
||||||
use crate::options::structs::TrackingProcess;
|
use crate::options::structs::TrackingProcess;
|
||||||
use files::create_watcher;
|
use files::create_watcher;
|
||||||
use files::file_handler;
|
use files::file_handler;
|
||||||
|
|
@ -61,27 +60,17 @@ pub async fn run_daemons(
|
||||||
loop {
|
loop {
|
||||||
let run_hand = running_handler(proc.clone(), tx.clone(), watchers_clone.clone());
|
let run_hand = running_handler(proc.clone(), tx.clone(), watchers_clone.clone());
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = run_hand => continue,
|
_ = run_hand => {},
|
||||||
_val = rx.recv() => {
|
_val = rx.recv() => {
|
||||||
if process_protocol_symbol(proc.clone(), _val.unwrap()).await.is_err() {
|
match _val.unwrap() {
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
tokio::task::yield_now().await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn process_protocol_symbol(proc: Arc<TrackingProcess>, val: u8) -> Result<(), CustomError>{
|
|
||||||
match val {
|
|
||||||
// 1 - File-dependency handling error -> terminating (after waiting)
|
// 1 - File-dependency handling error -> terminating (after waiting)
|
||||||
1 => {
|
1 => {
|
||||||
if is_active(&proc.name).await {
|
if is_active(&proc.name).await {
|
||||||
error!("File-dependency handling error: Terminating {} process ..." , &proc.name);
|
error!("File-dependency handling error: Terminating {} process ..." , &proc.name);
|
||||||
terminate_process(&proc.name).await;
|
terminate_process(&proc.name).await;
|
||||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
// return;
|
return;
|
||||||
},
|
},
|
||||||
// 2 - File-dependency handling error -> holding (after waiting)
|
// 2 - File-dependency handling error -> holding (after waiting)
|
||||||
2 => {
|
2 => {
|
||||||
|
|
@ -94,7 +83,7 @@ async fn process_protocol_symbol(proc: Arc<TrackingProcess>, val: u8) -> Result<
|
||||||
// 3 - Running process error
|
// 3 - Running process error
|
||||||
3 => {
|
3 => {
|
||||||
error!("Error due to starting {} process", &proc.name);
|
error!("Error due to starting {} process", &proc.name);
|
||||||
return Err(CustomError::Fatal)
|
break;
|
||||||
},
|
},
|
||||||
// 4 - Timeout of waiting service-dependency -> staying (after waiting)
|
// 4 - Timeout of waiting service-dependency -> staying (after waiting)
|
||||||
4 => {
|
4 => {
|
||||||
|
|
@ -106,7 +95,7 @@ async fn process_protocol_symbol(proc: Arc<TrackingProcess>, val: u8) -> Result<
|
||||||
if is_active(&proc.name).await {
|
if is_active(&proc.name).await {
|
||||||
error!("Timeout of waiting service-dependency: Terminating {} process ..." , &proc.name);
|
error!("Timeout of waiting service-dependency: Terminating {} process ..." , &proc.name);
|
||||||
terminate_process(&proc.name).await;
|
terminate_process(&proc.name).await;
|
||||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
tokio::time::sleep(Duration::from_millis(1000)).await;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 6 - Timeout of waiting service-dependency -> holding (after waiting)
|
// 6 - Timeout of waiting service-dependency -> holding (after waiting)
|
||||||
|
|
@ -123,7 +112,7 @@ async fn process_protocol_symbol(proc: Arc<TrackingProcess>, val: u8) -> Result<
|
||||||
error!("File-dependency warning (file changed). Terminating {} process...", &proc.name);
|
error!("File-dependency warning (file changed). Terminating {} process...", &proc.name);
|
||||||
terminate_process(&proc.name).await;
|
terminate_process(&proc.name).await;
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
return Err(CustomError::Fatal)
|
return;
|
||||||
},
|
},
|
||||||
// // 8 - File-dependency change -> restarting (after check)
|
// // 8 - File-dependency change -> restarting (after check)
|
||||||
8 => {
|
8 => {
|
||||||
|
|
@ -160,14 +149,14 @@ async fn process_protocol_symbol(proc: Arc<TrackingProcess>, val: u8) -> Result<
|
||||||
if is_active(&proc.name).await {
|
if is_active(&proc.name).await {
|
||||||
terminate_process(&proc.name).await;
|
terminate_process(&proc.name).await;
|
||||||
}
|
}
|
||||||
return Err(CustomError::Fatal)
|
break;
|
||||||
},
|
},
|
||||||
//
|
//
|
||||||
// 121 - Cannot create valid watcher for file dependency
|
// 121 - Cannot create valid watcher for file dependency
|
||||||
121 => {
|
121 => {
|
||||||
error!("Cannot create valid watcher for {}'s file dependency. Terminating thread...", proc.name);
|
error!("Cannot create valid watcher for {}'s file dependency. Terminating thread...", proc.name);
|
||||||
let _ = terminate_process("runner-rs").await;
|
let _ = terminate_process("runner-rs").await;
|
||||||
return Err(CustomError::Fatal)
|
break;
|
||||||
},
|
},
|
||||||
// 111 - global thread termination with killing current child in a face
|
// 111 - global thread termination with killing current child in a face
|
||||||
// of a current process
|
// of a current process
|
||||||
|
|
@ -181,10 +170,15 @@ async fn process_protocol_symbol(proc: Arc<TrackingProcess>, val: u8) -> Result<
|
||||||
log::info!("Process {} is already terminated!", proc.name);
|
log::info!("Process {} is already terminated!", proc.name);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
Ok(())
|
},
|
||||||
|
}
|
||||||
|
tokio::task::yield_now().await;
|
||||||
|
}
|
||||||
|
tokio::task::yield_now().await;
|
||||||
}
|
}
|
||||||
// check process status daemon
|
// check process status daemon
|
||||||
/// # Fn `run_daemons`
|
/// # Fn `run_daemons`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue