53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
![]() |
use eyre::Result;
|
||
|
use log::warn;
|
||
|
use std::env;
|
||
|
use std::process::exit;
|
||
|
|
||
|
use init::cmd;
|
||
|
use init::dklog;
|
||
|
|
||
|
#[tokio::main(flavor = "current_thread")]
|
||
|
async fn main() -> Result<()> {
|
||
|
dklog::LOG.spawn(dklog::LOG.copy_to(tokio::io::stderr()));
|
||
|
|
||
|
dklog::init();
|
||
|
|
||
|
let call_name = env::args().next().unwrap_or("init".into());
|
||
|
let call_name = (call_name.rsplit_once('/').map(|(_, n)| n)).unwrap_or(call_name.as_str());
|
||
|
|
||
|
if call_name == "init" {
|
||
|
dklog::LOG.spawn(async {
|
||
|
let Ok(log_file) = (tokio::fs::File::create("/var/log/init.log").await)
|
||
|
.inspect_err(|e| warn!("failed to open init.log: {e}"))
|
||
|
else {
|
||
|
return;
|
||
|
};
|
||
|
dklog::LOG.copy_to(log_file).await;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
let result = match call_name {
|
||
|
"init" => {
|
||
|
cmd::init::run().await;
|
||
|
Ok(())
|
||
|
}
|
||
|
"init-version" => {
|
||
|
cmd::version::run();
|
||
|
Ok(())
|
||
|
}
|
||
|
"init-connect" => {
|
||
|
cmd::init_input::run().await;
|
||
|
Ok(())
|
||
|
}
|
||
|
"bootstrap" => cmd::bootstrap::run().await,
|
||
|
|
||
|
_ => {
|
||
|
eprintln!("invalid call name: {call_name:?}");
|
||
|
exit(1);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
dklog::LOG.close().await;
|
||
|
result
|
||
|
}
|