Skip to main content

server/
lib.rs

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