mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
recovery mode
This commit is contained in:
committed by
Aiden McClelland
parent
7eda76f447
commit
91d08ca650
@@ -27,6 +27,7 @@ pub mod middleware;
|
|||||||
pub mod migration;
|
pub mod migration;
|
||||||
pub mod net;
|
pub mod net;
|
||||||
pub mod properties;
|
pub mod properties;
|
||||||
|
pub mod recovery;
|
||||||
pub mod s9pk;
|
pub mod s9pk;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
pub mod shutdown;
|
pub mod shutdown;
|
||||||
@@ -62,7 +63,8 @@ pub fn echo(#[arg] message: String) -> Result<String, RpcError> {
|
|||||||
auth::auth,
|
auth::auth,
|
||||||
db::db,
|
db::db,
|
||||||
ssh::ssh,
|
ssh::ssh,
|
||||||
net::wifi::wifi
|
net::wifi::wifi,
|
||||||
|
disk::disk,
|
||||||
))]
|
))]
|
||||||
pub fn main_api() -> Result<(), RpcError> {
|
pub fn main_api() -> Result<(), RpcError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -103,12 +105,12 @@ pub fn portable_api() -> Result<(), RpcError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(subcommands(version::git_info, echo,))]
|
#[command(subcommands(version::git_info, echo, recovery::recovery))]
|
||||||
pub fn recovery_api() -> Result<(), RpcError> {
|
pub fn recovery_api() -> Result<(), RpcError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(subcommands(version::git_info, echo,))]
|
#[command(subcommands(version::git_info, echo, setup::setup))]
|
||||||
pub fn setup_api() -> Result<(), RpcError> {
|
pub fn setup_api() -> Result<(), RpcError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
40
appmgr/src/recovery.rs
Normal file
40
appmgr/src/recovery.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use rpc_toolkit::command;
|
||||||
|
use rpc_toolkit::yajrc::RpcError;
|
||||||
|
|
||||||
|
use crate::context::RecoveryContext;
|
||||||
|
use crate::logs::{display_logs, fetch_logs, LogResponse, LogSource};
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
pub const SYSTEMD_UNIT: &'static str = "embassy-init";
|
||||||
|
|
||||||
|
#[command(subcommands(error, logs, exit))]
|
||||||
|
pub fn recovery() -> Result<(), Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub fn error(#[context] ctx: RecoveryContext) -> Result<Arc<RpcError>, Error> {
|
||||||
|
Ok(ctx.error.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command(display(display_logs))]
|
||||||
|
pub async fn logs(
|
||||||
|
#[arg] limit: Option<usize>,
|
||||||
|
#[arg] cursor: Option<String>,
|
||||||
|
#[arg] before_flag: Option<bool>,
|
||||||
|
) -> Result<LogResponse, Error> {
|
||||||
|
Ok(fetch_logs(
|
||||||
|
LogSource::Service(SYSTEMD_UNIT),
|
||||||
|
limit,
|
||||||
|
cursor,
|
||||||
|
before_flag.unwrap_or(false),
|
||||||
|
)
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub fn exit(#[context] ctx: RecoveryContext) -> Result<(), Error> {
|
||||||
|
ctx.shutdown.send(()).expect("receiver dropped");
|
||||||
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tokio::process::Command;
|
||||||
use torut::onion::TorSecretKeyV3;
|
use torut::onion::TorSecretKeyV3;
|
||||||
|
|
||||||
use crate::context::SetupContext;
|
use crate::context::SetupContext;
|
||||||
use crate::disk::disk;
|
use crate::disk::disk;
|
||||||
use crate::disk::main::DEFAULT_PASSWORD;
|
use crate::disk::main::DEFAULT_PASSWORD;
|
||||||
|
use crate::util::Invoke;
|
||||||
use crate::{Error, ResultExt};
|
use crate::{Error, ResultExt};
|
||||||
|
|
||||||
#[command(subcommands(status, disk))]
|
#[command(subcommands(status, disk, execute))]
|
||||||
pub fn setup() -> Result<(), Error> {
|
pub fn setup() -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -44,6 +47,21 @@ pub async fn execute(
|
|||||||
let guid =
|
let guid =
|
||||||
crate::disk::main::create(&ctx.zfs_pool_name, [embassy_logicalname], DEFAULT_PASSWORD)
|
crate::disk::main::create(&ctx.zfs_pool_name, [embassy_logicalname], DEFAULT_PASSWORD)
|
||||||
.await?;
|
.await?;
|
||||||
|
let mut ctr = 0;
|
||||||
|
while {
|
||||||
|
ctr += 1;
|
||||||
|
ctr < 30 // 30s timeout
|
||||||
|
} && String::from_utf8(
|
||||||
|
Command::new("zpool")
|
||||||
|
.arg("import")
|
||||||
|
.invoke(crate::ErrorKind::Zfs)
|
||||||
|
.await?,
|
||||||
|
)?
|
||||||
|
.trim()
|
||||||
|
== "no pools available to import"
|
||||||
|
{
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
crate::disk::main::load(&guid, &ctx.zfs_pool_name, &ctx.datadir, DEFAULT_PASSWORD).await?;
|
crate::disk::main::load(&guid, &ctx.zfs_pool_name, &ctx.datadir, DEFAULT_PASSWORD).await?;
|
||||||
let password = argon2::hash_encoded(
|
let password = argon2::hash_encoded(
|
||||||
embassy_password.as_bytes(),
|
embassy_password.as_bytes(),
|
||||||
|
|||||||
Reference in New Issue
Block a user