mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 11:49:39 -05:00
cli specify restart mode
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1329,6 +1329,8 @@ dependencies = [
|
||||
"run_command",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"toml",
|
||||
]
|
||||
|
||||
|
||||
@@ -13,4 +13,6 @@ serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
toml = "0.5"
|
||||
run_command = "0.0.5"
|
||||
colored = "2"
|
||||
colored = "2"
|
||||
strum = "0.24"
|
||||
strum_macros = "0.24"
|
||||
@@ -12,7 +12,7 @@ use rand::{distributions::Alphanumeric, Rng};
|
||||
use run_command::run_command_pipe_to_terminal;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::types::{CoreConfig, MongoConfig, PeripheryConfig};
|
||||
use crate::types::{CoreConfig, MongoConfig, PeripheryConfig, RestartMode};
|
||||
|
||||
const CORE_IMAGE_NAME: &str = "mbecker20/monitor-core";
|
||||
const PERIPHERY_IMAGE_NAME: &str = "mbecker20/monitor-periphery";
|
||||
@@ -117,6 +117,13 @@ pub fn start_mongo(sub_matches: &ArgMatches) {
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("~/.monitor/db");
|
||||
|
||||
let restart = sub_matches
|
||||
.get_one::<String>("restart")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("unless-stopped")
|
||||
.parse::<RestartMode>()
|
||||
.expect("invalid restart mode");
|
||||
|
||||
let env = if let (Some(username), Some(password)) = (username, password) {
|
||||
format!(" --env MONGO_INITDB_ROOT_USERNAME={username} --env MONGO_INITDB_ROOT_PASSWORD={password}")
|
||||
} else {
|
||||
@@ -149,7 +156,7 @@ pub fn start_mongo(sub_matches: &ArgMatches) {
|
||||
println!("pressed another button, exiting");
|
||||
}
|
||||
|
||||
let command = format!("docker run -d --name {name} -p {port}:27017 --network {network} -v {mount}:/data/db{env} mongo --quiet");
|
||||
let command = format!("docker run -d --name {name} -p {port}:27017 --network {network} -v {mount}:/data/db{env} --restart {restart} mongo --quiet");
|
||||
|
||||
let output = run_command_pipe_to_terminal(&command);
|
||||
|
||||
@@ -184,6 +191,13 @@ pub fn start_core(sub_matches: &ArgMatches) {
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("bridge");
|
||||
|
||||
let restart = sub_matches
|
||||
.get_one::<String>("restart")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("unless-stopped")
|
||||
.parse::<RestartMode>()
|
||||
.expect("invalid restart mode");
|
||||
|
||||
println!(
|
||||
"\n===================\n {} \n===================\n",
|
||||
"core config".bold()
|
||||
@@ -207,7 +221,7 @@ pub fn start_core(sub_matches: &ArgMatches) {
|
||||
println!("pressed another button, exiting");
|
||||
}
|
||||
|
||||
let command = format!("docker run -d --name {name} -p {port}:9000 --network {network} -v {config_path}:/config/config.toml {CORE_IMAGE_NAME}");
|
||||
let command = format!("docker run -d --name {name} -p {port}:9000 --network {network} -v {config_path}:/config/config.toml --restart {restart} {CORE_IMAGE_NAME}");
|
||||
|
||||
let output = run_command_pipe_to_terminal(&command);
|
||||
|
||||
@@ -278,6 +292,13 @@ pub fn start_periphery(sub_matches: &ArgMatches) {
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("bridge");
|
||||
|
||||
let restart = sub_matches
|
||||
.get_one::<String>("restart")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("unless-stopped")
|
||||
.parse::<RestartMode>()
|
||||
.expect("invalid restart mode");
|
||||
|
||||
println!(
|
||||
"\n========================\n {} \n========================\n",
|
||||
"periphery config".bold()
|
||||
@@ -302,7 +323,7 @@ pub fn start_periphery(sub_matches: &ArgMatches) {
|
||||
println!("pressed another button, exiting");
|
||||
}
|
||||
|
||||
let command = format!("docker run -d --name {name} -p {port}:8000 --network {network} -v {config_path}:/config/config.toml -v {repo_dir}:/repos -v /var/run/docker.sock:/var/run/docker.sock {PERIPHERY_IMAGE_NAME}");
|
||||
let command = format!("docker run -d --name {name} -p {port}:8000 --network {network} -v {config_path}:/config/config.toml -v {repo_dir}:/repos -v /var/run/docker.sock:/var/run/docker.sock --restart {restart} {PERIPHERY_IMAGE_NAME}");
|
||||
|
||||
let output = run_command_pipe_to_terminal(&command);
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ fn cli() -> Command {
|
||||
arg!(--network <NETWORK> "sets docker network of mongo container. default is bridge")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--restart <RESTART> "sets docker restart mode of mongo container. default is unless-stopped")
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("start")
|
||||
@@ -90,9 +93,12 @@ fn cli() -> Command {
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--network <NETWORK> "sets docker network of monitor periphery container. default is bridge")
|
||||
arg!(--network <NETWORK> "sets docker network of monitor core container. default is bridge")
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--restart <RESTART> "sets docker restart mode of monitor core container. default is unless-stopped")
|
||||
)
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
@@ -132,6 +138,9 @@ fn cli() -> Command {
|
||||
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")
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::collections::HashMap;
|
||||
|
||||
use async_timing_util::Timelength;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use strum_macros::{Display, EnumString};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct CoreConfig {
|
||||
@@ -87,3 +88,21 @@ fn default_periphery_port() -> u16 {
|
||||
fn default_repo_dir() -> String {
|
||||
"/repos".to_string()
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Display, EnumString, PartialEq, Hash, Eq, Clone, Copy,
|
||||
)]
|
||||
pub enum RestartMode {
|
||||
#[serde(rename = "no")]
|
||||
#[strum(serialize = "no")]
|
||||
NoRestart,
|
||||
#[serde(rename = "on-failure")]
|
||||
#[strum(serialize = "on-failure")]
|
||||
OnFailure,
|
||||
#[serde(rename = "always")]
|
||||
#[strum(serialize = "always")]
|
||||
Always,
|
||||
#[serde(rename = "unless-stopped")]
|
||||
#[strum(serialize = "unless-stopped")]
|
||||
UnlessStopped,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user