parent
dbb49de09c
commit
af12a1fef1
|
|
@ -3,7 +3,7 @@ mod utils;
|
|||
|
||||
use clap::Parser;
|
||||
use log::{error, info};
|
||||
use options::config::*;
|
||||
use options::{config::*, preboot};
|
||||
use options::logger::setup_logger;
|
||||
use options::signals::set_valid_destructor;
|
||||
use options::structs::Processes;
|
||||
|
|
@ -18,6 +18,10 @@ use options::preboot::PrebootParams;
|
|||
async fn main() {
|
||||
let preboot = PrebootParams::parse().validate();
|
||||
|
||||
if let Err(_) = preboot {
|
||||
return;
|
||||
}
|
||||
|
||||
let _ = setup_logger();
|
||||
|
||||
info!("Runner is configurating...");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
// module to handle pre-boot params of the monitor
|
||||
use anyhow::{Result, Ok};
|
||||
use anyhow::{Result, Ok, Error};
|
||||
use clap::Parser;
|
||||
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(clap::ValueEnum, Debug, Clone)]
|
||||
enum MetricsPrebootParams {
|
||||
|
|
@ -28,41 +27,96 @@ impl std::fmt::Display for MetricsPrebootParams {
|
|||
#[derive(Debug, Parser)]
|
||||
pub struct PrebootParams {
|
||||
// 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,
|
||||
#[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,
|
||||
#[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,
|
||||
#[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,
|
||||
#[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,
|
||||
|
||||
// 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")]
|
||||
socket_path : Option<String>,
|
||||
#[arg(long = "log-to", default_value=None, conflicts_with="no_logs", help="To set a path to logs directory")]
|
||||
log_to : Option<String>,
|
||||
#[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")]
|
||||
#[arg(
|
||||
long = "socket-path",
|
||||
default_value="/var/run/enode/hostagent.sock",
|
||||
conflicts_with="no_hostagent",
|
||||
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,
|
||||
#[arg(long = "config", short, default_value="settings.json", help="To set local config file path")]
|
||||
config : String,
|
||||
#[arg(
|
||||
long = "config",
|
||||
short,
|
||||
default_value="settings.json",
|
||||
help="To set local config file path"
|
||||
)]
|
||||
config : PathBuf,
|
||||
|
||||
// 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,
|
||||
}
|
||||
|
||||
impl PrebootParams {
|
||||
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 sock file
|
||||
|
||||
if !self.log_to.exists() {
|
||||
eprintln!("Log directory {} doesn't exist", &self.log_to.display());
|
||||
return Err(Error::msg("Log Directory Not Found. Cannot start"));
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue