appmgr 0.3.0 rewrite pt 1

appmgr: split bins

update cargo.toml and .gitignore

context

appmgr: refactor error module

appmgr: context

begin new s9pk format

appmgr: add fields to manifest

appmgr: start action abstraction

appmgr: volume abstraction

appmgr: improved volumes

appmgr: install wip

appmgr: health daemon

appmgr: health checks

appmgr: wip

config get

appmgr: secret store

wip

appmgr: config rewritten

appmgr: delete non-reusable code

appmgr: wip

appmgr: please the borrow-checker

appmgr: technically runs now

appmgr: cli

appmgr: clean up cli

appmgr: rpc-toolkit in action

appmgr: wrap up config

appmgr: account for updates during install

appmgr: fix: #308

appmgr: impl Display for Version

appmgr: cleanup

appmgr: set dependents on install

appmgr: dependency health checks
This commit is contained in:
Aiden McClelland
2021-04-08 11:16:25 -06:00
parent fd354b6cbe
commit ad12bf395c
84 changed files with 7510 additions and 9942 deletions

View File

@@ -0,0 +1,28 @@
use clap::Arg;
use embassy::context::{CliContext, EitherContext};
use embassy::Error;
use rpc_toolkit::run_cli;
fn inner_main() -> Result<(), Error> {
simple_logging::log_to_stderr(log::LevelFilter::Info);
run_cli!(
embassy::main_api,
app => app
.arg(Arg::with_name("host").long("host").short("h").takes_value(true))
.arg(Arg::with_name("port").long("port").short("p").takes_value(true)),
matches => EitherContext::Cli(CliContext::init(matches)?),
|code| if code < 0 { 1 } else { code }
)
}
fn main() {
match inner_main() {
Ok(_) => (),
Err(e) => {
eprintln!("{}", e.source);
log::debug!("{:?}", e.source);
drop(e.source);
std::process::exit(e.kind as i32)
}
}
}

View File

@@ -0,0 +1,22 @@
use embassy::Error;
async fn inner_main() -> Result<(), Error> {
// os sync
embassy::volume::disk::mount("/dev/sda", "/mnt/embassy-os-crypt").await?;
Ok(())
}
fn main() {
let rt = tokio::runtime::Runtime::new().expect("failed to initialize runtime");
match rt.block_on(inner_main()) {
Ok(_) => (),
Err(e) => {
drop(rt);
eprintln!("{}", e.source);
log::debug!("{:?}", e.source);
drop(e.source);
std::process::exit(e.kind as i32)
}
}
}

View File

@@ -0,0 +1,28 @@
use clap::Arg;
use embassy::context::{CliContext, EitherContext};
use embassy::Error;
use rpc_toolkit::run_cli;
fn inner_main() -> Result<(), Error> {
simple_logging::log_to_stderr(log::LevelFilter::Info);
run_cli!(
embassy::portable_api,
app => app
.arg(Arg::with_name("host").long("host").short("h").takes_value(true))
.arg(Arg::with_name("port").long("port").short("p").takes_value(true)),
matches => EitherContext::Cli(CliContext::init(matches)?),
|code| if code < 0 { 1 } else { code }
)
}
fn main() {
match inner_main() {
Ok(_) => (),
Err(e) => {
eprintln!("{}", e.source);
log::debug!("{:?}", e.source);
drop(e.source);
std::process::exit(e.kind as i32)
}
}
}

View File

@@ -0,0 +1,84 @@
use std::time::Duration;
use embassy::context::{EitherContext, RpcContext};
use embassy::db::model::Database;
use embassy::status::{check_all, synchronize_all};
use embassy::util::daemon;
use embassy::{Error, ErrorKind};
use futures::TryFutureExt;
use patch_db::json_ptr::JsonPointer;
use rpc_toolkit::hyper::StatusCode;
use rpc_toolkit::rpc_server;
fn status_fn(_: i32) -> StatusCode {
StatusCode::OK
}
async fn inner_main() -> Result<(), Error> {
simple_logging::log_to_stderr(log::LevelFilter::Info);
let rpc_ctx = RpcContext::init().await?;
if !rpc_ctx.db.exists(&<JsonPointer>::default()).await? {
rpc_ctx
.db
.put(&<JsonPointer>::default(), &Database::init(), None)
.await?;
}
let ctx = EitherContext::Rpc(rpc_ctx.clone());
let server = rpc_server!(embassy::main_api, ctx, status_fn);
let status_ctx = rpc_ctx.clone();
let status_daemon = daemon(
move || {
let ctx = status_ctx.clone();
async move {
if let Err(e) = synchronize_all(&ctx).await {
log::error!("Error in Status Sync daemon: {}", e);
log::debug!("{:?}", e);
} else {
log::info!("Status Sync completed successfully");
}
}
},
Duration::from_millis(500),
);
let health_ctx = rpc_ctx.clone();
let health_daemon = daemon(
move || {
let ctx = health_ctx.clone();
async move {
if let Err(e) = check_all(&ctx).await {
log::error!("Error in Health Check daemon: {}", e);
log::debug!("{:?}", e);
} else {
log::info!("Health Check completed successfully");
}
}
},
Duration::from_millis(500),
);
futures::try_join!(
server.map_err(|e| Error::new(e, ErrorKind::Network)),
status_daemon.map_err(|e| Error::new(
e.context("Status Sync daemon panicked!"),
ErrorKind::Unknown
)),
health_daemon.map_err(|e| Error::new(
e.context("Health Check daemon panicked!"),
ErrorKind::Unknown
)),
)?;
Ok(())
}
fn main() {
let rt = tokio::runtime::Runtime::new().expect("failed to initialize runtime");
match rt.block_on(inner_main()) {
Ok(_) => (),
Err(e) => {
drop(rt);
eprintln!("{}", e.source);
log::debug!("{:?}", e.source);
drop(e.source);
std::process::exit(e.kind as i32)
}
}
}