//! The `in` binary: the process lifetime and the command line. The commands live in `cli`, the server in //! `boot`, and each feature in its own module. //! //! `in [--config ] [serve]` runs the server; a bare `in` does the same. `export`, `fsck`, `restore` and //! `quota recompute` run on a stopped instance. The configuration file is the `--config` path, then //! `IN_CONFIG`, then `config/in.toml`. Exit status 0 is success, 1 a failure, 2 a usage error. mod api; mod assets; mod audit; mod auth; mod backup; mod boot; mod cli; mod directory; mod family; mod health; mod i18n; mod live; mod oidc; mod pages; mod security; mod serve_bytes; mod state; mod sweeper; mod throttle; mod thumbs_worker; mod views; use std::path::PathBuf; use std::process::ExitCode; use clap::Parser; use tracing_subscriber::EnvFilter; use crate::cli::{Cli, Command}; /// The configuration file when neither `--config` nor `IN_CONFIG` names one. const DEFAULT_CONFIG: &str = "config/in.toml"; /// The environment variable that names the configuration file. const CONFIG_ENV: &str = "IN_CONFIG"; /// The configuration path: the flag, else `IN_CONFIG`, else the default. fn config_path(flag: Option) -> PathBuf { flag.or_else(|| std::env::var_os(CONFIG_ENV).map(PathBuf::from)) .unwrap_or_else(|| PathBuf::from(DEFAULT_CONFIG)) } /// Logs to stderr. The level comes from `RUST_LOG`, and defaults to `info`. fn init_logging() { let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); tracing_subscriber::fmt() .with_env_filter(filter) .with_writer(std::io::stderr) .init(); } #[tokio::main] async fn main() -> ExitCode { init_logging(); let cli = Cli::parse(); let path = config_path(cli.config.clone()); cli::run(&path, cli.command.unwrap_or(Command::Serve)).await }