mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
add standby mode (#1671)
* add standby mode * fix standby mode to go before drive mount
This commit is contained in:
@@ -8,6 +8,7 @@ use embassy::disk::fsck::RepairStrategy;
|
|||||||
use embassy::disk::main::DEFAULT_PASSWORD;
|
use embassy::disk::main::DEFAULT_PASSWORD;
|
||||||
use embassy::disk::REPAIR_DISK_PATH;
|
use embassy::disk::REPAIR_DISK_PATH;
|
||||||
use embassy::hostname::get_product_key;
|
use embassy::hostname::get_product_key;
|
||||||
|
use embassy::init::STANDBY_MODE_PATH;
|
||||||
use embassy::middleware::cors::cors;
|
use embassy::middleware::cors::cors;
|
||||||
use embassy::middleware::diagnostic::diagnostic;
|
use embassy::middleware::diagnostic::diagnostic;
|
||||||
use embassy::middleware::encrypt::encrypt;
|
use embassy::middleware::encrypt::encrypt;
|
||||||
@@ -128,6 +129,12 @@ async fn run_script_if_exists<P: AsRef<Path>>(path: P) {
|
|||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn inner_main(cfg_path: Option<&str>) -> Result<Option<Shutdown>, Error> {
|
async fn inner_main(cfg_path: Option<&str>) -> Result<Option<Shutdown>, Error> {
|
||||||
|
if tokio::fs::metadata(STANDBY_MODE_PATH).await.is_ok() {
|
||||||
|
tokio::fs::remove_file(STANDBY_MODE_PATH).await?;
|
||||||
|
embassy::sound::SHUTDOWN.play().await?;
|
||||||
|
futures::future::pending::<()>().await;
|
||||||
|
}
|
||||||
|
|
||||||
embassy::sound::BEP.play().await?;
|
embassy::sound::BEP.play().await?;
|
||||||
|
|
||||||
run_script_if_exists("/embassy-os/preinit.sh").await;
|
run_script_if_exists("/embassy-os/preinit.sh").await;
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ use tokio::process::Command;
|
|||||||
use crate::context::rpc::RpcContextConfig;
|
use crate::context::rpc::RpcContextConfig;
|
||||||
use crate::db::model::ServerStatus;
|
use crate::db::model::ServerStatus;
|
||||||
use crate::install::PKG_DOCKER_DIR;
|
use crate::install::PKG_DOCKER_DIR;
|
||||||
|
use crate::sound::SHUTDOWN;
|
||||||
use crate::util::Invoke;
|
use crate::util::Invoke;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
pub const SYSTEM_REBUILD_PATH: &str = "/embassy-os/system-rebuild";
|
pub const SYSTEM_REBUILD_PATH: &str = "/embassy-os/system-rebuild";
|
||||||
|
pub const STANDBY_MODE_PATH: &str = "/embassy-os/standby";
|
||||||
|
|
||||||
pub async fn check_time_is_synchronized() -> Result<bool, Error> {
|
pub async fn check_time_is_synchronized() -> Result<bool, Error> {
|
||||||
Ok(String::from_utf8(
|
Ok(String::from_utf8(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use rpc_toolkit::command;
|
|||||||
|
|
||||||
use crate::context::RpcContext;
|
use crate::context::RpcContext;
|
||||||
use crate::disk::main::export;
|
use crate::disk::main::export;
|
||||||
use crate::init::SYSTEM_REBUILD_PATH;
|
use crate::init::{STANDBY_MODE_PATH, SYSTEM_REBUILD_PATH};
|
||||||
use crate::sound::SHUTDOWN;
|
use crate::sound::SHUTDOWN;
|
||||||
use crate::util::{display_none, Invoke};
|
use crate::util::{display_none, Invoke};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
@@ -54,23 +54,18 @@ impl Shutdown {
|
|||||||
tracing::debug!("{:?}", e);
|
tracing::debug!("{:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Err(e) = SHUTDOWN.play().await {
|
if self.restart {
|
||||||
tracing::error!("Error Playing Shutdown Song: {}", e);
|
if let Err(e) = SHUTDOWN.play().await {
|
||||||
tracing::debug!("{:?}", e);
|
tracing::error!("Error Playing Shutdown Song: {}", e);
|
||||||
|
tracing::debug!("{:?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
drop(rt);
|
drop(rt);
|
||||||
if self.restart {
|
if !self.restart {
|
||||||
Command::new("reboot").spawn().unwrap().wait().unwrap();
|
std::fs::write(STANDBY_MODE_PATH, "").unwrap();
|
||||||
} else {
|
|
||||||
Command::new("shutdown")
|
|
||||||
.arg("-h")
|
|
||||||
.arg("now")
|
|
||||||
.spawn()
|
|
||||||
.unwrap()
|
|
||||||
.wait()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
Command::new("reboot").spawn().unwrap().wait().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user