Compare commits
3 Commits
41f98bc850
...
8617a105e2
| Author | SHA1 | Date |
|---|---|---|
|
|
8617a105e2 | |
|
|
31bc8f1618 | |
|
|
492459b468 |
|
|
@ -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" ]
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
24
src/main.rs
24
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(),
|
||||
|
|
@ -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
|
||||
},
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue