Compare commits
2 Commits
7be46d4373
...
939bdc6676
| Author | SHA1 | Date |
|---|---|---|
|
|
939bdc6676 | |
|
|
97bc91ffcd |
|
|
@ -6,7 +6,19 @@ use std::{borrow::BorrowMut, net::{IpAddr, Ipv4Addr}};
|
||||||
// use std::io::BufReader;
|
// use std::io::BufReader;
|
||||||
use tokio::io::{BufReader, AsyncWriteExt, AsyncBufReadExt};
|
use tokio::io::{BufReader, AsyncWriteExt, AsyncBufReadExt};
|
||||||
|
|
||||||
|
/// # Fn `init_cli_pipeline`
|
||||||
|
/// ## for catching all input requests from CLI
|
||||||
|
///
|
||||||
|
/// *input* : -
|
||||||
|
///
|
||||||
|
/// *output* : `anyhow::Result<()>` to wrap errors
|
||||||
|
///
|
||||||
|
/// *initiator* : fn `main`
|
||||||
|
///
|
||||||
|
/// *managing* : `TcpListener` object to handle requests
|
||||||
|
///
|
||||||
|
/// *depends on* : -
|
||||||
|
///
|
||||||
pub async fn init_cli_pipeline() -> DynResult<()> {
|
pub async fn init_cli_pipeline() -> DynResult<()> {
|
||||||
return match init_listener().await {
|
return match init_listener().await {
|
||||||
Some(list) => {
|
Some(list) => {
|
||||||
|
|
@ -27,6 +39,19 @@ pub async fn init_cli_pipeline() -> DynResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Fn `init_listener`
|
||||||
|
/// ## for creating TCP-listener for communicating with CLI
|
||||||
|
///
|
||||||
|
/// *input* : -
|
||||||
|
///
|
||||||
|
/// *output* : `Some<TcpListener>` if port 7753 was opened | None if not
|
||||||
|
///
|
||||||
|
/// *initiator* : fn `init_cli_pipeline`
|
||||||
|
///
|
||||||
|
/// *managing* : `TcpListener` object to handle requests
|
||||||
|
///
|
||||||
|
/// *depends on* : `tokio::net::TcpListener`
|
||||||
|
///
|
||||||
async fn init_listener() -> Option<TcpListener> {
|
async fn init_listener() -> Option<TcpListener> {
|
||||||
return match TcpListener::bind("127.0.0.1:7753").await {
|
return match TcpListener::bind("127.0.0.1:7753").await {
|
||||||
Ok(listener) => {
|
Ok(listener) => {
|
||||||
|
|
@ -40,6 +65,19 @@ async fn init_listener() -> Option<TcpListener> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Fn `process_connection`
|
||||||
|
/// ## for processing input CLI requests
|
||||||
|
///
|
||||||
|
/// *input* : mut stream: `TcpStream`
|
||||||
|
///
|
||||||
|
/// *output* : -
|
||||||
|
///
|
||||||
|
/// *initiator* : fn `init_cli_pipeline`
|
||||||
|
///
|
||||||
|
/// *managing* : mutable object of `TcpStream`
|
||||||
|
///
|
||||||
|
/// *depends on* : `tokio::net::TcpStream`
|
||||||
|
///
|
||||||
async fn process_connection(mut stream: TcpStream) {
|
async fn process_connection(mut stream: TcpStream) {
|
||||||
// loop{
|
// loop{
|
||||||
// stream.
|
// stream.
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,18 @@ use anyhow::{Result, Ok, Error};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
/// # Enum `MetricsPrebootParams`
|
||||||
|
/// ## for setting up metrics mode as preboot param from command prompt
|
||||||
|
///
|
||||||
|
/// examples:
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --metrics full
|
||||||
|
/// noxis-rs ... --metrics system
|
||||||
|
/// noxis-rs ... --metrics processes
|
||||||
|
/// noxis-rs ... --metrics net
|
||||||
|
/// noxis-rs ... --metrics none
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
#[derive(clap::ValueEnum, Debug, Clone)]
|
#[derive(clap::ValueEnum, Debug, Clone)]
|
||||||
pub enum MetricsPrebootParams {
|
pub enum MetricsPrebootParams {
|
||||||
Full,
|
Full,
|
||||||
|
|
@ -13,6 +25,8 @@ pub enum MetricsPrebootParams {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # `std::fmt::Display` implementation for `MetricsPrebootParams`
|
||||||
|
/// ## to enable parsing object to String
|
||||||
impl std::fmt::Display for MetricsPrebootParams {
|
impl std::fmt::Display for MetricsPrebootParams {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -25,6 +39,71 @@ impl std::fmt::Display for MetricsPrebootParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # struct `PrebootParams`
|
||||||
|
/// ## to parse and set up all modes as preboot params from command prompt
|
||||||
|
///
|
||||||
|
/// ### args :
|
||||||
|
///
|
||||||
|
/// `--no-hagent` - to disable hagent work module and set up work mode as autonomous
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --no-hagent ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// `--no-logs` - to disable logging at all
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --no-logs ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--refresh-logs` - to truncate logs directory
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --refresh-logs ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--no-remote-config` - to disable work with Redis as config producer
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --no-remote-config ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--no-sub` - to disable Redis subscribtion mechanism
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --no-sub ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--socket-path` - to set Unix Domain Socket file's directory
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --no-sub ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--log-to` - to set directory for logs
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --log-to /dir/to/logs/ ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--remote-server-url` - to set Redis Server
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --remote-server-url 192.168.28.12 ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--config` - to set Noxis' config full path
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --config /etc/enode/settings.json ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// `--metrics` - to set metrics mode
|
||||||
|
/// ### usage :
|
||||||
|
/// ```
|
||||||
|
/// noxis-rs ... --metrics full ...
|
||||||
|
/// ```
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct PrebootParams {
|
pub struct PrebootParams {
|
||||||
// actions
|
// actions
|
||||||
|
|
@ -102,6 +181,8 @@ pub struct PrebootParams {
|
||||||
pub metrics: MetricsPrebootParams,
|
pub metrics: MetricsPrebootParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # implementation for `MetricsPrebootParams`
|
||||||
|
/// ## to enable validation mechanism
|
||||||
impl PrebootParams {
|
impl PrebootParams {
|
||||||
pub fn validate(mut self) -> Result<Self> {
|
pub fn validate(mut self) -> Result<Self> {
|
||||||
if !self.socket_path.exists() && !self.no_hostagent {
|
if !self.socket_path.exists() && !self.no_hostagent {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue