diff --git a/settings.json b/settings.json index adfa219..688a11f 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,4 @@ { - "id": 1, "dateOfCreation": "1721381809090", "processes": [ { @@ -16,7 +15,7 @@ } }, { - "filename": "config-file.json", + "filename": "config-file", "src": "/home/vladislav/web/", "triggers": { "onDelete": "stop", @@ -53,8 +52,8 @@ ], "services": [ { - "hostname": "localhost", - "port": 6379, + "hostname": "google.com", + "port": 443, "triggers": { "wait": 14, "delay": 1, diff --git a/src/main.rs b/src/main.rs index aa08605..8214122 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ use serde_json; use tokio::time::{ Duration, Instant }; use tokio::sync::mpsc; use tokio::join; -// use tokio::io::{AsyncRead, AsyncWrite}; // fatal errors handler use core::panic; use std::borrow::BorrowMut; @@ -26,6 +25,7 @@ use log::{error, info, warn, LevelFilter}; use std::net::{TcpStream, ToSocketAddrs}; static CONFIG_PATH : &'static str = "settings.json"; +static GET_ID_CMD : &'static str = "cat /proc/self/mountinfo | grep '/docker/containers/' | head -1 | awk -F '/' '{print $5}'"; /// # an Error enum (nextly will be deleted and replaced) enum CustomError { @@ -40,8 +40,8 @@ enum ConfigActuality { /// > (needed in serialization and deserialization) #[derive(Debug, Serialize, Deserialize, Clone)] struct Processes { - #[serde(rename="id")] - runner_id: usize, + // #[serde(rename="id")] + // runner_id: usize, #[serde(rename="dateOfCreation")] date_of_creation : String, #[serde(default)] @@ -108,12 +108,12 @@ struct FIleTriggers { #[tokio::main(flavor = "multi_thread")] async fn main() { - // building logger with current output format Builder::new() - .format(|buf, record|{ + .format(move |buf, record|{ writeln!(buf, - "{} [{}] - {}", + "Container-{}| {} [{}] - {}", + get_container_id().unwrap_or("||undefined container id|".to_string()), Local::now().format("%d-%m-%Y %H:%M:%S"), record.level(), record.args(), @@ -830,4 +830,16 @@ async fn check_service(hostname: &str, port: &u32) -> Result<(), CustomError> { }, Err(_) => return Err(CustomError::Fatal), } +} + +// todo: cmd across cat /proc/self/mountinfo | grep "/docker/containers/" | head -1 | awk -F '/' '{print $5}' +fn get_container_id() -> Option { + match Command::new(GET_ID_CMD).output() { + Ok(output) => { + Some(String::from_utf8_lossy(&output.stdout).to_string()) + }, + Err(_) => { + None + }, + } } \ No newline at end of file