local logs (nw)

pull/9/head
prplV 2024-09-04 15:52:57 +03:00
parent d1adc6baf0
commit e2d2100ce9
4 changed files with 23 additions and 21 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
.idea

View File

@ -1,13 +0,0 @@
#!/bin/bash
hostname=$1
port=$2
if nc -z -w1 $hostname $port > /dev/null 2>&1; then
echo "Service $hostname:$port is running"
exit 0
else
echo "Service $hostname:$port is unreachable"
exit 1
fi

View File

@ -5,9 +5,12 @@ mod prcs;
mod utils; mod utils;
mod services; mod services;
// use tokio::fs::File;
use std::fs::{File, OpenOptions};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use std::sync::Arc; use std::sync::Arc;
use std::io::Write; use std::io::Write;
use std::process::Command;
use chrono::Local; use chrono::Local;
use env_logger::Builder; use env_logger::Builder;
use log::{error, LevelFilter}; use log::{error, LevelFilter};
@ -19,7 +22,16 @@ use utils::*;
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() { async fn main() {
// building logger with current output format if Command::new("sh").args(["-c", "'mkdir /var/log/runner-rs/'"]).output().is_err() {
println!("Error: Run runner in sudo mode");
}
let log_target = Box::new(OpenOptions::new().create_new(true).append(true).open("/var/log/runner-rs/runner.log").unwrap_or_else(|_| {
println!("Error: Cannot create local log-file in /var/log/runner-rs, returning...");
std::process::exit(1);
}));
// building logger with current output format
Builder::new() Builder::new()
.format(move |buf, record|{ .format(move |buf, record|{
writeln!(buf, writeln!(buf,
@ -30,18 +42,20 @@ async fn main() {
record.args(), record.args(),
) )
}) })
.target(env_logger::Target::Stdout)
.target(env_logger::Target::Pipe(log_target))
.filter(None, LevelFilter::Info) .filter(None, LevelFilter::Info)
.init(); .init();
log::info!("Runner is configurating..."); log::info!("Runner is configurating...");
// setting up redis connection \ // setting up redis connection \
// then conf checks to choose the most actual \ // then conf checks to choose the most actual \
let processes: Processes = get_actual_config().unwrap_or_else(|| { let processes: Processes = get_actual_config().unwrap_or_else(|| {
error!("No actual configuration for runner. Stopping..."); error!("No actual configuration for runner. Stopping...");
std::process::exit(101); std::process::exit(101);
}); });
log::info!("Current runner configuration: {}", &processes.date_of_creation); log::info!("Current runner configuration: {}", &processes.date_of_creation);
log::info!("Runner is ready. Initializing..."); log::info!("Runner is ready. Initializing...");
@ -53,13 +67,13 @@ async fn main() {
for proc in processes.processes.iter() { for proc in processes.processes.iter() {
log::info!("Process '{}' on stage: {}. Depends on {} file(s), {} service(s)", log::info!("Process '{}' on stage: {}. Depends on {} file(s), {} service(s)",
proc.name, proc.name,
proc.path, proc.path,
proc.dependencies.files.len(), proc.dependencies.files.len(),
proc.dependencies.services.len() proc.dependencies.services.len()
); );
// creating msg channel // creating msg channel
// can or should be executed in new thread // can or should be executed in new thread
let (tx, mut rx) = mpsc::channel::<u8>(1); let (tx, mut rx) = mpsc::channel::<u8>(1);

View File

@ -21,7 +21,7 @@ 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}'"; 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 it's more like tree-form than classical 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") **
pub async fn run_daemons( pub async fn run_daemons(