forge
Explore
Log in

Don't you dare go Hollow

iz

Clone
★ 0

0 watching0 forksRustAGPL-3.0567.3 KiB3950aceTahinli27 days ago34 commits

main.rs78 lines, 2.2 KiBHistoryRawDownload
1//! The `iz` binary: the command line, logging and the process lifetime.
2//!
3//! `iz [--config <path>] [serve]` runs the server; a bare `iz` does the same. `iz export`, `iz restore` and
4//! `iz fsck` are the operator commands (see `cli`). The configuration file is the `--config` path, then
5//! `IZ_CONFIG`, then `config/iz.toml`. Exit status 0 is success, 1 a failure, 2 a usage error.
6
7// The page handlers nest many view and store futures; the default limit is too small for their types.
8#![recursion_limit = "256"]
9
10mod assets;
11mod attachments;
12mod auth;
13mod backup;
14mod boot;
15mod cli;
16mod directory;
17mod family;
18mod health;
19mod i18n;
20mod in_store;
21mod live;
22mod mail;
23mod mover;
24mod oidc;
25mod pages;
26mod security;
27mod serve;
28mod state;
29mod sweeper;
30mod views;
31
32use std::path::Path;
33use std::process::ExitCode;
34
35use clap::Parser;
36use cli::{Cli, Command};
37use tracing_subscriber::EnvFilter;
38
39/// Logs to stderr. The level comes from `RUST_LOG`, and defaults to `info`.
40fn init_logging() {
41 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
42 tracing_subscriber::fmt()
43 .with_env_filter(filter)
44 .with_writer(std::io::stderr)
45 .init();
46}
47
48/// Runs the server and maps its outcome to an exit status.
49async fn serve(config: &Path) -> ExitCode {
50 match boot::serve(config).await {
51 Ok(()) => ExitCode::SUCCESS,
52 Err(error) => {
53 tracing::error!(error = %error, "iz stopped with an error");
54 ExitCode::FAILURE
55 }
56 }
57}
58
59#[tokio::main]
60async fn main() -> ExitCode {
61 let cli = match Cli::try_parse() {
62 Ok(cli) => cli,
63 Err(error) => {
64 // Help and version are not failures; a usage error is exit 2.
65 let code = if error.use_stderr() { 2 } else { 0 };
66 let _ = error.print();
67 return ExitCode::from(code);
68 }
69 };
70 init_logging();
71 let config = cli::config_path(cli.config);
72 match cli.command.unwrap_or(Command::Serve) {
73 Command::Serve => serve(&config).await,
74 Command::Export { out } => cli::export::run(&config, &out).await,
75 Command::Restore { from } => cli::restore::run(&config, &from).await,
76 Command::Fsck { remote } => cli::fsck::run(&config, remote).await,
77 }
78}