parent
dbb49de09c
commit
af12a1fef1
|
|
@ -3,7 +3,7 @@ mod utils;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use options::config::*;
|
use options::{config::*, preboot};
|
||||||
use options::logger::setup_logger;
|
use options::logger::setup_logger;
|
||||||
use options::signals::set_valid_destructor;
|
use options::signals::set_valid_destructor;
|
||||||
use options::structs::Processes;
|
use options::structs::Processes;
|
||||||
|
|
@ -18,6 +18,10 @@ use options::preboot::PrebootParams;
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let preboot = PrebootParams::parse().validate();
|
let preboot = PrebootParams::parse().validate();
|
||||||
|
|
||||||
|
if let Err(_) = preboot {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let _ = setup_logger();
|
let _ = setup_logger();
|
||||||
|
|
||||||
info!("Runner is configurating...");
|
info!("Runner is configurating...");
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
// module to handle pre-boot params of the monitor
|
// module to handle pre-boot params of the monitor
|
||||||
use anyhow::{Result, Ok};
|
use anyhow::{Result, Ok, Error};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Debug, Clone)]
|
#[derive(clap::ValueEnum, Debug, Clone)]
|
||||||
enum MetricsPrebootParams {
|
enum MetricsPrebootParams {
|
||||||
|
|
@ -28,41 +27,96 @@ impl std::fmt::Display for MetricsPrebootParams {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct PrebootParams {
|
pub struct PrebootParams {
|
||||||
// actions
|
// actions
|
||||||
#[arg(long = "no-hagent", action, conflicts_with="socket_path", help="To disable work with host-agent")]
|
#[arg(
|
||||||
|
long = "no-hagent",
|
||||||
|
action,
|
||||||
|
conflicts_with="socket_path",
|
||||||
|
help="To disable work with host-agent"
|
||||||
|
)]
|
||||||
pub no_hostagent : bool,
|
pub no_hostagent : bool,
|
||||||
#[arg(long = "no-logs", action, conflicts_with="log_to", help="To disable logs")]
|
#[arg(
|
||||||
|
long = "no-logs",
|
||||||
|
action,
|
||||||
|
conflicts_with="log_to",
|
||||||
|
help="To disable logs"
|
||||||
|
)]
|
||||||
pub no_logs: bool,
|
pub no_logs: bool,
|
||||||
#[arg(long = "refresh-logs", action, conflicts_with="no_logs", help="To clear logs directory")]
|
#[arg(
|
||||||
|
long = "refresh-logs",
|
||||||
|
action,
|
||||||
|
conflicts_with="no_logs",
|
||||||
|
help="To clear logs directory"
|
||||||
|
)]
|
||||||
pub refresh_logs : bool,
|
pub refresh_logs : bool,
|
||||||
#[arg(long = "no-remote-config", action, help="To disable work with remote config server", conflicts_with="no_sub")]
|
#[arg(
|
||||||
|
long = "no-remote-config",
|
||||||
|
action,
|
||||||
|
help="To disable work with remote config server",
|
||||||
|
conflicts_with="no_sub")]
|
||||||
pub no_remote_config : bool,
|
pub no_remote_config : bool,
|
||||||
#[arg(long = "no-sub", action, help="To disable subscription mechanism", conflicts_with="no_remote_config")]
|
#[arg(
|
||||||
|
long = "no-sub",
|
||||||
|
action,
|
||||||
|
help="To disable subscription mechanism",
|
||||||
|
conflicts_with="no_remote_config")]
|
||||||
pub no_sub : bool,
|
pub no_sub : bool,
|
||||||
|
|
||||||
// params (socket_path, log_to, remote_server_url, config)
|
// params (socket_path, log_to, remote_server_url, config)
|
||||||
#[arg(long = "socket-path", default_value=None, conflicts_with="no_hostagent", help="To set .sock file's path used in communication with host-agent")]
|
#[arg(
|
||||||
socket_path : Option<String>,
|
long = "socket-path",
|
||||||
#[arg(long = "log-to", default_value=None, conflicts_with="no_logs", help="To set a path to logs directory")]
|
default_value="/var/run/enode/hostagent.sock",
|
||||||
log_to : Option<String>,
|
conflicts_with="no_hostagent",
|
||||||
#[arg(long = "remote-server-url", default_value="redis://localhost", conflicts_with="no_remote_config", help = "To set url of remote config server using in remote config pulling mechanism")]
|
help="To set .sock file's path used in communication with host-agent"
|
||||||
|
)]
|
||||||
|
socket_path : PathBuf,
|
||||||
|
#[arg(
|
||||||
|
long = "log-to",
|
||||||
|
default_value="./",
|
||||||
|
conflicts_with="no_logs",
|
||||||
|
help="To set a path to logs directory"
|
||||||
|
)]
|
||||||
|
log_to : PathBuf,
|
||||||
|
#[arg(
|
||||||
|
long = "remote-server-url",
|
||||||
|
default_value="redis://localhost",
|
||||||
|
conflicts_with="no_remote_config",
|
||||||
|
help = "To set url of remote config server using in remote config pulling mechanism"
|
||||||
|
)]
|
||||||
remote_server_url : String,
|
remote_server_url : String,
|
||||||
#[arg(long = "config", short, default_value="settings.json", help="To set local config file path")]
|
#[arg(
|
||||||
config : String,
|
long = "config",
|
||||||
|
short,
|
||||||
|
default_value="settings.json",
|
||||||
|
help="To set local config file path"
|
||||||
|
)]
|
||||||
|
config : PathBuf,
|
||||||
|
|
||||||
// value enum params (metrics)
|
// value enum params (metrics)
|
||||||
#[arg(long = "metrics", short, default_value_t=MetricsPrebootParams::Full, help="To set metrics grubbing mode")]
|
#[arg(
|
||||||
|
long = "metrics",
|
||||||
|
short,
|
||||||
|
default_value_t=MetricsPrebootParams::Full,
|
||||||
|
help="To set metrics grubbing mode"
|
||||||
|
)]
|
||||||
metrics: MetricsPrebootParams,
|
metrics: MetricsPrebootParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrebootParams {
|
impl PrebootParams {
|
||||||
pub fn validate(self) -> Result<Self> {
|
pub fn validate(self) -> Result<Self> {
|
||||||
// existing sock file
|
if !self.socket_path.exists() {
|
||||||
|
eprintln!("Socket-file {} doesn't exist. Cannot start", &self.socket_path.display());
|
||||||
|
return Err(Error::msg("Socket-file Not Found"));
|
||||||
|
}
|
||||||
// existing log dir
|
// existing log dir
|
||||||
|
if !self.log_to.exists() {
|
||||||
// existing sock file
|
eprintln!("Log directory {} doesn't exist", &self.log_to.display());
|
||||||
|
return Err(Error::msg("Log Directory Not Found. Cannot start"));
|
||||||
|
}
|
||||||
// existing sock file
|
// existing sock file
|
||||||
|
if !self.config.exists() {
|
||||||
|
eprintln!("Local config file {} doesn't exist", &self.config.display());
|
||||||
|
return Err(Error::msg("Local Config Not Found. Cannot start"));
|
||||||
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue