diff --git a/radicle-cli/src/commands/node/control.rs b/radicle-cli/src/commands/node/control.rs index ecca8695..ab5fd869 100644 --- a/radicle-cli/src/commands/node/control.rs +++ b/radicle-cli/src/commands/node/control.rs @@ -44,9 +44,9 @@ pub fn start(daemon: bool, options: Vec) -> anyhow::Result<()> { } pub fn stop(node: Node) -> anyhow::Result<()> { - let spinner = term::spinner("Stopping the node..."); - if let Err(err) = node.shutdown() { - spinner.error(format!("Error occurred while shutting down node: {err}")); + let spinner = term::spinner("Stopping node..."); + if node.shutdown().is_err() { + spinner.error("node is not running"); } else { spinner.finish(); } diff --git a/radicle-node/src/control.rs b/radicle-node/src/control.rs index 331c3e21..78d7a2fe 100644 --- a/radicle-node/src/control.rs +++ b/radicle-node/src/control.rs @@ -211,6 +211,7 @@ fn command + 'static>( // Channel might already be disconnected if shutdown // came from somewhere else. Ignore errors. handle.shutdown().ok(); + CommandResult::ok().to_writer(writer).ok(); } } Ok(()) diff --git a/radicle/src/node.rs b/radicle/src/node.rs index 43970d74..5300e5f4 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -10,7 +10,7 @@ use std::io::{BufRead, BufReader}; use std::ops::Deref; use std::os::unix::net::UnixStream; use std::path::{Path, PathBuf}; -use std::{fmt, io, net, time}; +use std::{fmt, io, net, thread, time}; use amplify::WrapperMut; use cyphernet::addr::{HostName, NetAddr}; @@ -697,7 +697,14 @@ impl Handle for Node { } fn shutdown(self) -> Result<(), Error> { - todo!(); + for line in self.call::<&str, CommandResult>(CommandName::Shutdown, [], DEFAULT_TIMEOUT)? { + line?; + } + // Wait until the shutdown has completed. + while self.is_running() { + thread::sleep(time::Duration::from_secs(1)); + } + Ok(()) } } @@ -709,7 +716,7 @@ pub trait AliasStore { impl AliasStore for &T { fn alias(&self, nid: &NodeId) -> Option { - dbg!((*self).alias(nid)) + (*self).alias(nid) } } @@ -721,7 +728,7 @@ impl AliasStore for Box { impl AliasStore for HashMap { fn alias(&self, nid: &NodeId) -> Option { - dbg!(self.get(nid).map(ToOwned::to_owned)) + self.get(nid).map(ToOwned::to_owned) } }