diff --git a/backend/src/bin/embassyd.rs b/backend/src/bin/embassyd.rs index 79e86e001..308302fce 100644 --- a/backend/src/bin/embassyd.rs +++ b/backend/src/bin/embassyd.rs @@ -88,17 +88,13 @@ async fn inner_main(cfg_path: Option) -> Result, Error .map_ok(|_| tracing::debug!("Metrics daemon Shutdown")) .await?; - let mut shutdown = shutdown_recv + let shutdown = shutdown_recv .recv() .await .with_kind(crate::ErrorKind::Unknown)?; sig_handler.abort(); - if let Some(shutdown) = &mut shutdown { - drop(shutdown.db_handle.take()); - } - (rpc_ctx, shutdown) }; rpc_ctx.shutdown().await?; diff --git a/backend/src/diagnostic.rs b/backend/src/diagnostic.rs index 78e05226f..c4c8adbfb 100644 --- a/backend/src/diagnostic.rs +++ b/backend/src/diagnostic.rs @@ -45,7 +45,6 @@ pub fn restart(#[context] ctx: DiagnosticContext) -> Result<(), Error> { .send(Some(Shutdown { datadir: ctx.datadir.clone(), disk_guid: ctx.disk_guid.clone(), - db_handle: None, restart: true, })) .expect("receiver dropped"); diff --git a/backend/src/init.rs b/backend/src/init.rs index 22cd214c8..bad9a58a3 100644 --- a/backend/src/init.rs +++ b/backend/src/init.rs @@ -12,7 +12,7 @@ use tokio::process::Command; use crate::context::rpc::RpcContextConfig; use crate::db::model::ServerStatus; use crate::install::PKG_ARCHIVE_DIR; -use crate::sound::{BEP, CIRCLE_OF_5THS_SHORT}; +use crate::sound::BEP; use crate::util::Invoke; use crate::Error; @@ -197,15 +197,30 @@ pub struct InitResult { pub async fn init(cfg: &RpcContextConfig) -> Result { let secret_store = cfg.secret_store().await?; + tracing::info!("Opened Postgres"); + + crate::ssh::sync_keys_from_db(&secret_store, "/home/start9/.ssh/authorized_keys").await?; + tracing::info!("Synced SSH Keys"); + let db = cfg.db(&secret_store).await?; + tracing::info!("Opened PatchDB"); let mut handle = db.handle(); crate::db::DatabaseModel::new() .server_info() .lock(&mut handle, LockType::Write) .await?; - let receipts = InitReceipts::new(&mut handle).await?; + if let Some(wifi_interface) = &cfg.wifi_interface { + crate::net::wifi::synchronize_wpa_supplicant_conf( + &cfg.datadir().join("main"), + wifi_interface, + &receipts.last_wifi_region.get(&mut handle).await?, + ) + .await?; + tracing::info!("Synchronized WiFi"); + } + let should_rebuild = tokio::fs::metadata(SYSTEM_REBUILD_PATH).await.is_ok() || &*receipts.server_version.get(&mut handle).await? < &emver::Version::new(0, 3, 3, 1); @@ -239,6 +254,7 @@ pub async fn init(cfg: &RpcContextConfig) -> Result { .invoke(crate::ErrorKind::Journald) .await?; tracing::info!("Mounted Logs"); + let tmp_dir = cfg.datadir().join("package-data/tmp"); if tokio::fs::metadata(&tmp_dir).await.is_err() { tokio::fs::create_dir_all(&tmp_dir).await?; @@ -318,18 +334,6 @@ pub async fn init(cfg: &RpcContextConfig) -> Result { .await?; tracing::info!("Enabled Docker QEMU Emulation"); - crate::ssh::sync_keys_from_db(&secret_store, "/home/start9/.ssh/authorized_keys").await?; - tracing::info!("Synced SSH Keys"); - - if let Some(wifi_interface) = &cfg.wifi_interface { - crate::net::wifi::synchronize_wpa_supplicant_conf( - &cfg.datadir().join("main"), - wifi_interface, - &receipts.last_wifi_region.get(&mut handle).await?, - ) - .await?; - tracing::info!("Synchronized WiFi"); - } receipts .status_info .set( diff --git a/backend/src/shutdown.rs b/backend/src/shutdown.rs index d6e0151f4..7b984f0bb 100644 --- a/backend/src/shutdown.rs +++ b/backend/src/shutdown.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use std::sync::Arc; -use patch_db::{LockType, PatchDbHandle}; use rpc_toolkit::command; use crate::context::RpcContext; @@ -16,7 +15,6 @@ pub struct Shutdown { pub datadir: PathBuf, pub disk_guid: Option>, pub restart: bool, - pub db_handle: Option>, } impl Shutdown { /// BLOCKING @@ -87,16 +85,11 @@ impl Shutdown { #[command(display(display_none))] pub async fn shutdown(#[context] ctx: RpcContext) -> Result<(), Error> { - let mut db = ctx.db.handle(); - crate::db::DatabaseModel::new() - .lock(&mut db, LockType::Write) - .await?; ctx.shutdown .send(Some(Shutdown { datadir: ctx.datadir.clone(), disk_guid: Some(ctx.disk_guid.clone()), restart: false, - db_handle: Some(Arc::new(db)), })) .map_err(|_| ()) .expect("receiver dropped"); @@ -105,16 +98,11 @@ pub async fn shutdown(#[context] ctx: RpcContext) -> Result<(), Error> { #[command(display(display_none))] pub async fn restart(#[context] ctx: RpcContext) -> Result<(), Error> { - let mut db = ctx.db.handle(); - crate::db::DatabaseModel::new() - .lock(&mut db, LockType::Write) - .await?; ctx.shutdown .send(Some(Shutdown { datadir: ctx.datadir.clone(), disk_guid: Some(ctx.disk_guid.clone()), restart: true, - db_handle: Some(Arc::new(db)), })) .map_err(|_| ()) .expect("receiver dropped");