From 9f33396f9586b235113323aec517c33349e5393b Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 4 Sep 2024 10:56:13 +0300 Subject: [PATCH] get cont id fn moved to utils.rs --- src/main.rs | 17 +---------------- src/utils.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 73a13bb..a7a9261 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ mod utils; mod services; use tokio::sync::mpsc; -use std::process::Command; use std::sync::Arc; use std::io::Write; use chrono::Local; @@ -16,8 +15,6 @@ use structs::*; use config::*; 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")] async fn main() { @@ -77,16 +74,4 @@ async fn main() { i.await.unwrap(); } return; -} - -// 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 diff --git a/src/utils.rs b/src/utils.rs index f899086..0d166b4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use crate::structs::TrackingProcess; use tokio::sync::mpsc; use inotify::Inotify; +use std::process::Command; use crate::files::create_watcher; use log::{error, warn}; use crate::prcs::{ @@ -18,6 +19,8 @@ use tokio::join; use crate::files::file_handler; use crate::services::service_handler; +static GET_ID_CMD : &'static str = "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 ) /// > hint : give mpsc with capacity 1 to jump over potential errors during running process /// ** 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::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 { + match Command::new(GET_ID_CMD).output() { + Ok(output) => { + Some(String::from_utf8_lossy(&output.stdout).to_string()) + }, + Err(_) => { + None + }, + } +}