diff --git a/crates/jstzd/src/task/octez_node.rs b/crates/jstzd/src/task/octez_node.rs index b7de7bdd..49a90005 100644 --- a/crates/jstzd/src/task/octez_node.rs +++ b/crates/jstzd/src/task/octez_node.rs @@ -40,13 +40,14 @@ impl Task for OctezNode { Some(v) => Directory::Path(v.clone()), None => Directory::default(), }; - let log_file = match &config.log_file { + let log_file = Arc::new(match &config.log_file { Some(v) => FileWrapper::try_from(v.clone())?, None => FileWrapper::default(), - }; + }); let node = node::OctezNode { octez_node_bin: Some(config.binary_path.clone()), octez_node_dir: (&data_dir).into(), + log_file: log_file.clone(), }; let status = node.generate_identity().await?.wait().await?; @@ -71,11 +72,9 @@ impl Task for OctezNode { } Ok(OctezNode { - inner: ChildWrapper::new_shared( - node.run(log_file.as_file(), &config.run_options)?, - ), + inner: ChildWrapper::new_shared(node.run(&config.run_options)?), config, - _log_file: Arc::new(log_file), + _log_file: log_file, _data_dir: Arc::new(data_dir), }) } diff --git a/crates/octez/src/async/node.rs b/crates/octez/src/async/node.rs index 24cb617e..afa88cf6 100644 --- a/crates/octez/src/async/node.rs +++ b/crates/octez/src/async/node.rs @@ -1,4 +1,4 @@ -use std::{fs::File, path::PathBuf, process::Stdio}; +use std::{path::PathBuf, process::Stdio, sync::Arc}; use tokio::process::{Child, Command}; @@ -6,7 +6,7 @@ use crate::path_or_default; use anyhow::Result; -use super::{endpoint::Endpoint, node_config::OctezNodeRunOptions}; +use super::{endpoint::Endpoint, file::FileWrapper, node_config::OctezNodeRunOptions}; pub struct OctezNode { /// Path to the octez-node binary @@ -14,11 +14,17 @@ pub struct OctezNode { pub octez_node_bin: Option, /// Path to the octez-node directory pub octez_node_dir: PathBuf, + /// Path to the log file. + pub log_file: Arc, } impl OctezNode { - fn command(&self) -> Command { - Command::new(path_or_default(self.octez_node_bin.as_ref(), "octez-node")) + fn command(&self) -> Result { + let mut cmd = + Command::new(path_or_default(self.octez_node_bin.as_ref(), "octez-node")); + cmd.stdout(Stdio::from(self.log_file.as_file().try_clone()?)) + .stderr(Stdio::from(self.log_file.as_file().try_clone()?)); + Ok(cmd) } pub async fn config_init( @@ -29,7 +35,7 @@ impl OctezNode { num_connections: u32, ) -> Result { Ok(self - .command() + .command()? .args([ "config", "init", @@ -50,7 +56,7 @@ impl OctezNode { pub async fn generate_identity(&self) -> Result { Ok(self - .command() + .command()? .args([ "identity", "generate", @@ -61,8 +67,8 @@ impl OctezNode { .spawn()?) } - pub fn run(&self, log_file: &File, options: &OctezNodeRunOptions) -> Result { - let mut command = self.command(); + pub fn run(&self, options: &OctezNodeRunOptions) -> Result { + let mut command = self.command()?; command .args([ @@ -71,9 +77,7 @@ impl OctezNode { self.octez_node_dir.to_str().expect("Invalid path"), "--singleprocess", ]) - .args(options.to_string().split(' ')) - .stdout(Stdio::from(log_file.try_clone()?)) - .stderr(Stdio::from(log_file.try_clone()?)); + .args(options.to_string().split(' ')); Ok(command.spawn()?) }