Skip to main content

server/
lib.rs

1#![recursion_limit = "256"]
2
3pub mod auth_keys;
4pub mod bootstrap;
5pub mod config;
6
7pub mod db;
8
9//pub mod transaction;
10pub mod account;
11#[cfg(feature = "scripting")]
12pub mod artifact_mgmt;
13pub mod command;
14pub mod commodity;
15pub mod error;
16pub mod provision;
17#[cfg(feature = "scripting")]
18pub mod script;
19pub mod split;
20pub mod tag;
21pub mod user;
22use exitfailure::ExitFailure;
23use sqlx::any::install_default_drivers;
24use tokio::{runtime::Handle, task::JoinHandle};
25
26#[macro_use]
27extern crate rust_i18n;
28
29i18n!("locales", fallback = "en");
30
31/// Runs the one-time-per-DB boot sequence: install sqlx drivers, migrate the
32/// admin DB, run the idempotent global seed (`seed_complete`-guarded), and load
33/// config. Every startup path MUST call this before reading config — the web
34/// binary calls it directly; the CLI/server path goes through [`start`]. Safe
35/// to call on an already-booted DB (migrate + seed are idempotent).
36pub async fn boot() -> Result<(), ExitFailure> {
37    install_default_drivers();
38    db::migrate_db().await?;
39    bootstrap::seed().await?;
40    config::load_config().await?;
41
42    log::info!("{}", &t!("The server boot complete"));
43    Ok(())
44}
45
46pub async fn start() -> JoinHandle<Result<(), ExitFailure>> {
47    let handle = Handle::current();
48
49    handle.spawn(boot())
50}