forge
Explore
Log in

Don't you dare go Hollow

in

Clone
★ 0

0 watching0 forksRustAGPL-3.0528.7 KiB9215377Tahinli27 days ago37 commits

main.rs65 lines, 1.8 KiBHistoryRawDownload
1//! The `in` binary: the process lifetime and the command line. The commands live in `cli`, the server in
2//! `boot`, and each feature in its own module.
3//!
4//! `in [--config <path>] [serve]` runs the server; a bare `in` does the same. `export`, `fsck`, `restore` and
5//! `quota recompute` run on a stopped instance. The configuration file is the `--config` path, then
6//! `IN_CONFIG`, then `config/in.toml`. Exit status 0 is success, 1 a failure, 2 a usage error.
7
8mod api;
9mod assets;
10mod audit;
11mod auth;
12mod backup;
13mod boot;
14mod cli;
15mod directory;
16mod family;
17mod health;
18mod i18n;
19mod live;
20mod oidc;
21mod pages;
22mod security;
23mod serve_bytes;
24mod state;
25mod sweeper;
26mod throttle;
27mod thumbs_worker;
28mod views;
29
30use std::path::PathBuf;
31use std::process::ExitCode;
32
33use clap::Parser;
34use tracing_subscriber::EnvFilter;
35
36use crate::cli::{Cli, Command};
37
38/// The configuration file when neither `--config` nor `IN_CONFIG` names one.
39const DEFAULT_CONFIG: &str = "config/in.toml";
40
41/// The environment variable that names the configuration file.
42const CONFIG_ENV: &str = "IN_CONFIG";
43
44/// The configuration path: the flag, else `IN_CONFIG`, else the default.
45fn config_path(flag: Option<PathBuf>) -> PathBuf {
46 flag.or_else(|| std::env::var_os(CONFIG_ENV).map(PathBuf::from))
47 .unwrap_or_else(|| PathBuf::from(DEFAULT_CONFIG))
48}
49
50/// Logs to stderr. The level comes from `RUST_LOG`, and defaults to `info`.
51fn init_logging() {
52 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
53 tracing_subscriber::fmt()
54 .with_env_filter(filter)
55 .with_writer(std::io::stderr)
56 .init();
57}
58
59#[tokio::main]
60async fn main() -> ExitCode {
61 init_logging();
62 let cli = Cli::parse();
63 let path = config_path(cli.config.clone());
64 cli::run(&path, cli.command.unwrap_or(Command::Serve)).await
65}