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"))]
7
extern crate self as server;
8

            
9
pub mod auth_keys;
10
pub mod bootstrap;
11
pub mod config;
12

            
13
pub mod db;
14

            
15
//pub mod transaction;
16
pub mod account;
17
pub mod artifact_mgmt;
18
pub mod command;
19
pub mod commodity;
20
pub mod error;
21
pub mod fleet;
22
pub mod logical;
23
pub mod provision;
24
pub mod script;
25
pub mod split;
26
pub mod tag;
27
pub mod user;
28
use exitfailure::ExitFailure;
29
use sqlx::any::install_default_drivers;
30
use tokio::{runtime::Handle, task::JoinHandle};
31

            
32
#[macro_use]
33
extern crate rust_i18n;
34

            
35
i18n!("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).
42
pub 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

            
52
pub async fn start() -> JoinHandle<Result<(), ExitFailure>> {
53
    let handle = Handle::current();
54

            
55
    handle.spawn(boot())
56
}