Checkpoint
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use tokio::signal;
|
||||
use tokio::task::JoinSet;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
use crate::args::Args;
|
||||
use crate::commands::setup::SetupKind;
|
||||
|
||||
mod args;
|
||||
mod commands;
|
||||
mod db;
|
||||
mod listener;
|
||||
mod utils;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
let user_id = uzers::get_current_uid();
|
||||
|
||||
if user_id != 0 {
|
||||
anyhow::bail!(concat!(
|
||||
"The daemon must be run as root, but the current user is not root. ",
|
||||
"Please run the daemon as root."
|
||||
));
|
||||
}
|
||||
|
||||
let env_filter = if args.debug {
|
||||
EnvFilter::new("off,nye_daemon=trace,nye_wire_protocol=trace")
|
||||
} else {
|
||||
EnvFilter::new("off,nye_daemon=info,nye_wire_protocol=warn")
|
||||
};
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(env_filter)
|
||||
.with_target(false)
|
||||
.init();
|
||||
|
||||
commands::setup::setup(SetupKind::System)
|
||||
.await
|
||||
.context("Could not set up the Nye package manager's system-wide configuration.")?;
|
||||
|
||||
let mut tasks = JoinSet::new();
|
||||
|
||||
tokio::select! {
|
||||
_ = listener::run(&mut tasks) => {}
|
||||
_ = signal::ctrl_c() => {
|
||||
tasks.join_all().await;
|
||||
}
|
||||
}
|
||||
|
||||
listener::cleanup()
|
||||
.await
|
||||
.context("Failed to cleanup socket listener.")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user