Compare commits

..

3 Commits

Author SHA1 Message Date
Vladislav Drozdov 8617a105e2
Merge pull request #8 from prplV/feature/EN-4
Feature/en 4 merging
2024-09-03 15:32:32 +03:00
prplV 31bc8f1618 added files for dummy ci 2024-09-03 15:29:25 +03:00
prplV 492459b468 +getter id container and new view of logs 2024-09-03 15:20:30 +03:00
4 changed files with 41 additions and 10 deletions

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM ubuntu
RUN mkdir -p /usr/src/kii/
WORKDIR /usr/src/kii/
RUN mkdir monitor/
RUN mkdir -p services/temp-process/
RUN touch services/temp-process/dep.txt
RUN touch services/temp-process/run.sh
RUN echo "./services/temp-process/temp-process" >> services/temp-process/run.sh
COPY runner-rs monitor/
COPY settings.json .
COPY temp-process services/temp-process/
RUN chmod +x services/temp-process/temp-process
RUN chmod +x monitor/runner-rs
ENTRYPOINT [ "/usr/src/kii/monitor/runner-rs" ]

View File

@ -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,

View File

@ -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(),
@ -831,3 +831,15 @@ 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<String> {
match Command::new(GET_ID_CMD).output() {
Ok(output) => {
Some(String::from_utf8_lossy(&output.stdout).to_string())
},
Err(_) => {
None
},
}
}

BIN
temp-process Executable file

Binary file not shown.