diff --git a/appmgr/src/disk/main.rs b/appmgr/src/disk/main.rs index 96bc02053..033b67a8d 100644 --- a/appmgr/src/disk/main.rs +++ b/appmgr/src/disk/main.rs @@ -152,22 +152,6 @@ pub async fn export(pool_name: &str) -> Result<(), Error> { Ok(()) } -/// BLOCKING -pub fn export_blocking(pool: &str) -> Result<(), Error> { - let output = std::process::Command::new("zpool") - .arg("export") - .arg(pool) - .output()?; - if !output.status.success() { - Err(Error::new( - anyhow!("{}", String::from_utf8(output.stderr)?), - crate::ErrorKind::Zfs, - )) - } else { - Ok(()) - } -} - pub async fn import(guid: &str) -> Result<(), Error> { Command::new("zpool") .arg("import") diff --git a/appmgr/src/shutdown.rs b/appmgr/src/shutdown.rs index 9c1a5c43f..5c16e9975 100644 --- a/appmgr/src/shutdown.rs +++ b/appmgr/src/shutdown.rs @@ -3,8 +3,9 @@ use std::sync::Arc; use rpc_toolkit::command; use crate::context::RpcContext; -use crate::disk::main::export_blocking; -use crate::util::display_none; +use crate::disk::main::export; +use crate::sound::MARIO_DEATH; +use crate::util::{display_none, Invoke}; use crate::Error; #[derive(Debug, Clone)] @@ -17,23 +18,36 @@ impl Shutdown { pub fn execute(&self) { use std::process::Command; - Command::new("systemctl") - .arg("stop") - .arg("systemd-journald") - .spawn() + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() .unwrap() - .wait() - .unwrap(); - Command::new("systemctl") - .arg("stop") - .arg("docker") - .spawn() - .unwrap() - .wait() - .unwrap(); - if let Err(e) = export_blocking(&self.zfs_pool) { - log::error!("Error Exporting ZFS Pool: {}", e); - } + .block_on(async { + use tokio::process::Command; + + if let Err(e) = Command::new("systemctl") + .arg("stop") + .arg("systemd-journald") + .invoke(crate::ErrorKind::Journald) + .await + { + log::error!("Error Stopping Journald: {}", e); + } + if let Err(e) = Command::new("systemctl") + .arg("stop") + .arg("docker") + .invoke(crate::ErrorKind::Docker) + .await + { + log::error!("Error Stopping Docker: {}", e); + } + if let Err(e) = export(&self.zfs_pool).await { + log::error!("Error Exporting ZFS Pool: {}", e); + } + if let Err(e) = MARIO_DEATH.play().await { + log::error!("Error Playing Shutdown Song: {}", e); + } + }); if self.restart { Command::new("reboot").spawn().unwrap().wait().unwrap(); } else {