Compare commits

..

2 Commits

Author SHA1 Message Date
prplV d1adc6baf0 fix get cont id fn 2024-09-04 11:43:09 +03:00
prplV 9f33396f95 get cont id fn moved to utils.rs 2024-09-04 10:56:13 +03:00
2 changed files with 17 additions and 16 deletions

View File

@ -6,7 +6,6 @@ mod utils;
mod services; mod services;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use std::process::Command;
use std::sync::Arc; use std::sync::Arc;
use std::io::Write; use std::io::Write;
use chrono::Local; use chrono::Local;
@ -16,8 +15,6 @@ use structs::*;
use config::*; use config::*;
use utils::*; use utils::*;
static GET_ID_CMD : &'static str = "cat /proc/self/mountinfo | grep '/docker/containers/' | head -1 | awk -F '/' '{print $6}'";
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() { async fn main() {
@ -78,15 +75,3 @@ async fn main() {
} }
return; return;
} }
// todo: cmd across cat /proc/self/mountinfo | grep "/docker/containers/" | head -1 | awk -F '/' '{print $5}'
fn get_container_id() -> Option<String> {
match Command::new(GET_ID_CMD).output() {
Ok(output) => {
Some(String::from_utf8_lossy(&output.stdout).to_string())
},
Err(_) => {
None
},
}
}

View File

@ -2,6 +2,7 @@ use std::sync::Arc;
use crate::structs::TrackingProcess; use crate::structs::TrackingProcess;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use inotify::Inotify; use inotify::Inotify;
use std::process::Command;
use crate::files::create_watcher; use crate::files::create_watcher;
use log::{error, warn}; use log::{error, warn};
use crate::prcs::{ use crate::prcs::{
@ -18,6 +19,8 @@ use tokio::join;
use crate::files::file_handler; use crate::files::file_handler;
use crate::services::service_handler; use crate::services::service_handler;
static GET_ID_CMD : &'static str = r"cat /proc/self/mountinfo | grep '/docker/containers/' | head -1 | awk -F '/' '{print \$6}'";
/// # async func to run 3 main daemons (now its more like tree-form than classiacl 0.1.0 form ) /// # async func to run 3 main daemons (now its more like tree-form than classiacl 0.1.0 form )
/// > hint : give mpsc with capacity 1 to jump over potential errors during running process /// > hint : give mpsc with capacity 1 to jump over potential errors during running process
/// ** in [developing](https://github.com/prplV/runner-rs "REPOSITORY") ** /// ** in [developing](https://github.com/prplV/runner-rs "REPOSITORY") **
@ -157,3 +160,16 @@ pub async fn running_handler
tokio::time::sleep(Duration::from_millis(100)).await; tokio::time::sleep(Duration::from_millis(100)).await;
tokio::task::yield_now().await; tokio::task::yield_now().await;
} }
// todo: cmd across cat /proc/self/mountinfo | grep "/docker/containers/" | head -1 | awk -F '/' '{print $5}'
pub fn get_container_id() -> Option<String> {
match Command::new("sh -c").arg(GET_ID_CMD).output() {
Ok(output) => {
Some(String::from_utf8_lossy(&output.stdout).to_string())
},
Err(_) => {
None
},
}
}