mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 11:49:39 -05:00
cli to start up periphery as daemon
This commit is contained in:
@@ -15,8 +15,9 @@ use serde::Serialize;
|
||||
|
||||
use crate::types::{CoreConfig, MongoConfig, PeripheryConfig, RestartMode};
|
||||
|
||||
const CORE_IMAGE_NAME: &str = "mbecker20/monitor-core";
|
||||
const PERIPHERY_IMAGE_NAME: &str = "mbecker20/monitor-periphery";
|
||||
const CORE_IMAGE_NAME: &str = "mbecker20/monitor_core";
|
||||
const PERIPHERY_IMAGE_NAME: &str = "mbecker20/monitor_periphery";
|
||||
const PERIPHERY_CRATE: &str = "monitor_periphery";
|
||||
|
||||
pub fn gen_core_config(sub_matches: &ArgMatches) {
|
||||
let host = sub_matches
|
||||
@@ -295,7 +296,62 @@ pub fn gen_periphery_config(sub_matches: &ArgMatches) {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn start_periphery(sub_matches: &ArgMatches) {
|
||||
pub fn start_periphery_daemon(sub_matches: &ArgMatches) {
|
||||
let config_path = sub_matches
|
||||
.get_one::<String>("config_path")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("~/.monitor/periphery.config.toml")
|
||||
.to_string();
|
||||
|
||||
let stdout = sub_matches
|
||||
.get_one::<String>("stdout")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("~/.monitor/periphery.log.out")
|
||||
.to_string();
|
||||
|
||||
let stderr = sub_matches
|
||||
.get_one::<String>("stderr")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("~/.monitor/periphery.log.err")
|
||||
.to_string();
|
||||
|
||||
println!(
|
||||
"\n========================\n {} \n========================\n",
|
||||
"periphery config".bold()
|
||||
);
|
||||
println!("{}: {config_path}", "config path".dimmed());
|
||||
println!("{}: {stdout}", "stdout".dimmed());
|
||||
println!("{}: {stderr}", "stderr".dimmed());
|
||||
|
||||
println!(
|
||||
"\npress {} to start {}. {}",
|
||||
"ENTER".green().bold(),
|
||||
"monitor periphery".bold(),
|
||||
"(ctrl-c to cancel)".dimmed()
|
||||
);
|
||||
|
||||
let buffer = &mut [0u8];
|
||||
let res = std::io::stdin().read_exact(buffer);
|
||||
|
||||
if res.is_err() {
|
||||
println!("pressed another button, exiting");
|
||||
}
|
||||
|
||||
let command = format!("");
|
||||
|
||||
let output = run_command_pipe_to_terminal(&command);
|
||||
|
||||
if output.success() {
|
||||
println!(
|
||||
"\n✅ {} has been started up ✅\n",
|
||||
"monitor periphery".bold()
|
||||
)
|
||||
} else {
|
||||
eprintln!("\n❌ there was some {} on startup ❌\n", "error".red())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_periphery_container(sub_matches: &ArgMatches) {
|
||||
let config_path = sub_matches
|
||||
.get_one::<String>("config_path")
|
||||
.map(|p| p.as_str())
|
||||
|
||||
@@ -80,7 +80,7 @@ fn cli() -> Command {
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("start")
|
||||
.about("start up monitor core")
|
||||
.about("start up monitor core in container")
|
||||
.arg(
|
||||
arg!(--name <NAME> "specify the name of the monitor core container. default is monitor-core")
|
||||
)
|
||||
@@ -132,25 +132,45 @@ fn cli() -> Command {
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("start")
|
||||
.about("start up monitor periphery")
|
||||
.arg(
|
||||
arg!(--name <NAME> "specify the name of the monitor periphery container. default is monitor-periphery")
|
||||
.about("tools to start periphery as daemon or container")
|
||||
.subcommand(
|
||||
Command::new("daemon")
|
||||
.about("start up monitor periphery daemon")
|
||||
.arg(
|
||||
arg!(--config_path <PATH> "specify the file path to use for config. default is ~/.monitor/periphery.config.toml")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--stdout <PATH> "specify the file path for periphery to log stdout to. default is ~/.monitor/periphery.log.out")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--stderr <PATH> "specify the file path for periphery to log stderr to. default is ~/.monitor/periphery.log.err")
|
||||
.required(false)
|
||||
)
|
||||
)
|
||||
.arg(
|
||||
arg!(--config_path <PATH> "specify the file path to use for config. default is ~/.monitor/periphery.config.toml")
|
||||
.required(false)
|
||||
)
|
||||
.arg(arg!(--repo_dir <PATH> "specify the folder on host to clone repos into. default is ~/.monitor/repos"))
|
||||
.arg(
|
||||
arg!(--port <PORT> "sets port monitor periphery will run on. default is 8000")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--network <NETWORK> "sets docker network of monitor periphery container. default is bridge")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--restart <RESTART> "sets docker restart mode of monitor periphery container. default is unless-stopped")
|
||||
.subcommand(
|
||||
Command::new("container")
|
||||
.about("start up monitor periphery in docker container")
|
||||
.arg(
|
||||
arg!(--name <NAME> "specify the name of the monitor periphery container. default is monitor-periphery")
|
||||
)
|
||||
.arg(
|
||||
arg!(--config_path <PATH> "specify the file path to use for config. default is ~/.monitor/periphery.config.toml")
|
||||
.required(false)
|
||||
)
|
||||
.arg(arg!(--repo_dir <PATH> "specify the folder on host to clone repos into. default is ~/.monitor/repos"))
|
||||
.arg(
|
||||
arg!(--port <PORT> "sets port monitor periphery will run on. default is 8000")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--network <NETWORK> "sets docker network of monitor periphery container. default is bridge")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--restart <RESTART> "sets docker restart mode of monitor periphery container. default is unless-stopped")
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
@@ -177,12 +197,19 @@ fn main() {
|
||||
);
|
||||
match periphery_command {
|
||||
("gen_config", sub_matches) => gen_periphery_config(sub_matches),
|
||||
("start", sub_matches) => start_periphery(sub_matches),
|
||||
("start", sub_matches) => {
|
||||
let periphery_start_command = sub_matches.subcommand().expect("\n❌ invalid call, should be 'monitor_cli periphery start <daemon, container> <flags>' ❌\n");
|
||||
match periphery_start_command {
|
||||
("daemon", sub_matches) => start_periphery_daemon(sub_matches),
|
||||
("container", sub_matches) => start_periphery_container(sub_matches),
|
||||
_ => println!("\n❌ invalid call, should be 'monitor_cli periphery start <daemon, container> <flags>' ❌\n")
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
println!("\n❌ invalid call, should be 'monitor_cli periphery <gen_config, start> <flags>' ❌\n")
|
||||
println!("\n❌ invalid call, should be 'monitor_cli periphery <gen_config, start>...' ❌\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
_ => println!("\n❌ invalid call, should be 'monitor_cli <core, periphery> ...' ❌\n"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ impl State {
|
||||
|
||||
let deploy_log = match self.periphery.deploy(&server, &deployment).await {
|
||||
Ok(log) => log,
|
||||
Err(e) => Log::error("deploy container", format!("{e:#?}"))
|
||||
Err(e) => Log::error("deploy container", format!("{e:#?}")),
|
||||
};
|
||||
|
||||
update.success = deploy_log.success;
|
||||
|
||||
@@ -55,9 +55,21 @@ pub fn load() -> (Args, u16, PeripheryConfigExtension) {
|
||||
fn print_startup_log(config_path: &str, args: &Args, config: &PeripheryConfig) {
|
||||
println!("\nconfig path: {config_path}");
|
||||
let mut config = config.clone();
|
||||
config.github_accounts = config.github_accounts.into_iter().map(|(a, _)| (a, "<SECRET>".to_string())).collect();
|
||||
config.docker_accounts = config.docker_accounts.into_iter().map(|(a, _)| (a, "<SECRET>".to_string())).collect();
|
||||
config.secrets = config.secrets.into_iter().map(|(s, _)| (s, "<SECRET>".to_string())).collect();
|
||||
config.github_accounts = config
|
||||
.github_accounts
|
||||
.into_iter()
|
||||
.map(|(a, _)| (a, "<SECRET>".to_string()))
|
||||
.collect();
|
||||
config.docker_accounts = config
|
||||
.docker_accounts
|
||||
.into_iter()
|
||||
.map(|(a, _)| (a, "<SECRET>".to_string()))
|
||||
.collect();
|
||||
config.secrets = config
|
||||
.secrets
|
||||
.into_iter()
|
||||
.map(|(s, _)| (s, "<SECRET>".to_string()))
|
||||
.collect();
|
||||
println!("{config:#?}");
|
||||
if args.daemon {
|
||||
println!("daemon mode enabled");
|
||||
|
||||
Reference in New Issue
Block a user