diff --git a/control-plane/src/orchestration.rs b/control-plane/src/orchestration.rs index 334a43e2..10087d3c 100644 --- a/control-plane/src/orchestration.rs +++ b/control-plane/src/orchestration.rs @@ -3,7 +3,10 @@ use std::process::{Output, Stdio}; use log::info; use serde_json::Value; use thiserror::Error; -use tokio::process::Command; +use tokio::{ + io::{AsyncBufReadExt, BufReader}, + process::Command, +}; use crate::configuration::get_enclave_run_config; @@ -54,7 +57,7 @@ impl Orchestration { info!("No enclaves currently running on this host."); } - println!("Starting new enclave..."); + info!("Starting new enclave..."); let mut run_command = vec![ "nitro-cli", "run-enclave", @@ -69,10 +72,10 @@ impl Orchestration { ]; if run_config.debug_mode == "true" { - println!("Debug mode enabled..."); + info!("Debug mode enabled..."); run_command.push("--debug-mode"); } else { - println!("Debug mode disabled..."); + info!("Debug mode disabled..."); } Self::run_command_capture_stdout(&run_command).await?; @@ -81,16 +84,27 @@ impl Orchestration { std::thread::sleep(std::time::Duration::from_secs(10)); if run_config.debug_mode == "true" { - println!("Attaching headless console for running enclaves..."); + info!("Attaching headless console for running enclaves..."); let running_enclaves = Self::run_command_capture_stdout(&["nitro-cli", "describe-enclaves"]).await?; let enclaves: Value = serde_json::from_str(&running_enclaves)?; - let v = vec![]; - let enclaves_array = enclaves.as_array().unwrap_or(&v); + static EMPTY_VEC: Vec = Vec::new(); + let enclaves_array = enclaves.as_array().unwrap_or(&EMPTY_VEC).clone(); for enclave in enclaves_array { - let id = enclave["EnclaveID"].as_str().unwrap(); - Self::run_command_capture_stdout(&["nitro-cli", "console", "--enclave-id", id]) - .await?; + let id = enclave["EnclaveID"].as_str().unwrap().to_string(); + + let mut child = Command::new("nitro-cli") + .args(["console", "--enclave-id", &id]) + .stdout(Stdio::piped()) + .spawn()?; + + let stdout = child.stdout.take().unwrap(); + tokio::spawn(async move { + let mut lines = BufReader::new(stdout).lines(); + while let Ok(Some(line)) = lines.next_line().await { + info!("[ENCLAVE {}]: {}", id, line); + } + }); } } Ok(())