|
|
@ -1,5 +1,6 @@
|
|
|
|
use crate::daemon_management::error::{DaemonError, DaemonResult};
|
|
|
|
use crate::daemon_management::error::{DaemonError, DaemonResult};
|
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::ffi::OsStr;
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use tokio::process::{Child, Command};
|
|
|
|
use tokio::process::{Child, Command};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
@ -38,6 +39,17 @@ impl DaemonCli {
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Kills the running daemon process if there's one associated with the
|
|
|
|
|
|
|
|
/// daemon cli
|
|
|
|
|
|
|
|
#[tracing::instrument]
|
|
|
|
|
|
|
|
pub async fn stop_daemon(&mut self) -> DaemonResult<()> {
|
|
|
|
|
|
|
|
if let Some(mut child) = mem::take(&mut self.child) {
|
|
|
|
|
|
|
|
child.kill().await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns if the daemon is currently running
|
|
|
|
/// Returns if the daemon is currently running
|
|
|
|
pub fn daemon_running(&mut self) -> bool {
|
|
|
|
pub fn daemon_running(&mut self) -> bool {
|
|
|
|
if let Some(child) = &mut self.child {
|
|
|
|
if let Some(child) = &mut self.child {
|
|
|
@ -76,6 +88,7 @@ impl DaemonCli {
|
|
|
|
) -> DaemonResult<Child> {
|
|
|
|
) -> DaemonResult<Child> {
|
|
|
|
Command::new(&self.daemon_path)
|
|
|
|
Command::new(&self.daemon_path)
|
|
|
|
.args(args)
|
|
|
|
.args(args)
|
|
|
|
|
|
|
|
.kill_on_drop(true)
|
|
|
|
.spawn()
|
|
|
|
.spawn()
|
|
|
|
.map_err(DaemonError::from)
|
|
|
|
.map_err(DaemonError::from)
|
|
|
|
}
|
|
|
|
}
|
|
|
|