adds bep to embassy startup sequence (#468)

* adds bep to embassy startup sequence

* always run postinit

* Update appmgr/src/bin/embassy-init.rs

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
This commit is contained in:
Keagan McClelland
2021-09-13 11:59:56 -06:00
committed by GitHub
parent 982ed0172c
commit e5c2f59539
2 changed files with 37 additions and 30 deletions

View File

@@ -115,15 +115,12 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> {
Ok(()) Ok(())
} }
// BLOCKING async fn run_script_if_exists<P: AsRef<Path>>(path: P) {
fn run_script_if_exists<P: AsRef<Path>>(path: P) {
use std::process::Command;
let script = path.as_ref(); let script = path.as_ref();
if script.exists() { if script.exists() {
match Command::new("/bin/bash").arg(script).spawn() { match Command::new("/bin/bash").arg(script).spawn() {
Ok(mut c) => { Ok(mut c) => {
if let Err(e) = c.wait() { if let Err(e) = c.wait().await {
log::error!("Error Running {}: {}", script.display(), e) log::error!("Error Running {}: {}", script.display(), e)
} }
} }
@@ -133,28 +130,40 @@ fn run_script_if_exists<P: AsRef<Path>>(path: P) {
} }
async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> { async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> {
if let Err(e) = init(cfg_path).await { embassy::sound::BEP.play().await?;
log::error!("{}", e.source);
log::debug!("{}", e.source);
embassy::sound::BEETHOVEN.play().await?;
let ctx = RecoveryContext::init(cfg_path).await?;
rpc_server!({
command: embassy::recovery_api,
context: ctx.clone(),
status: status_fn,
middleware: [ ]
})
.with_graceful_shutdown({
let mut shutdown = ctx.shutdown.subscribe();
async move {
shutdown.recv().await.expect("context dropped");
}
})
.await
.with_kind(embassy::ErrorKind::Network)?;
}
Ok(()) run_script_if_exists("/embassy-os/preinit.sh").await;
let res = if let Err(e) = init(cfg_path).await {
(|| async {
log::error!("{}", e.source);
log::debug!("{}", e.source);
embassy::sound::BEETHOVEN.play().await?;
let ctx = RecoveryContext::init(cfg_path).await?;
rpc_server!({
command: embassy::recovery_api,
context: ctx.clone(),
status: status_fn,
middleware: [ ]
})
.with_graceful_shutdown({
let mut shutdown = ctx.shutdown.subscribe();
async move {
shutdown.recv().await.expect("context dropped");
}
})
.await
.with_kind(embassy::ErrorKind::Network)?;
Ok::<_, Error>(())
})()
.await
} else {
Ok(())
};
run_script_if_exists("/embassy-os/postinit.sh").await;
res
} }
fn main() { fn main() {
@@ -183,8 +192,6 @@ fn main() {
}); });
let cfg_path = matches.value_of("config"); let cfg_path = matches.value_of("config");
run_script_if_exists("/embassy-os/preinit.sh");
let res = { let res = {
let rt = tokio::runtime::Builder::new_multi_thread() let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
@@ -193,8 +200,6 @@ fn main() {
rt.block_on(inner_main(cfg_path)) rt.block_on(inner_main(cfg_path))
}; };
run_script_if_exists("/embassy-os/postinit.sh");
match res { match res {
Ok(_) => (), Ok(_) => (),
Err(e) => { Err(e) => {

View File

@@ -337,6 +337,8 @@ macro_rules! song {
}; };
} }
pub const BEP: Song<[(Option<Note>, TimeSlice); 1]> = song!(120, [note(A, 4, Quarter);]);
pub const MARIO_DEATH: Song<[(Option<Note>, TimeSlice); 12]> = song!(400, [ pub const MARIO_DEATH: Song<[(Option<Note>, TimeSlice); 12]> = song!(400, [
note(B, 4, Quarter); note(B, 4, Quarter);
note(F, 5, Quarter); note(F, 5, Quarter);