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 account_state;
18
pub mod artifact_mgmt;
19
pub(crate) mod attempt;
20
pub mod command;
21
pub mod commodity;
22
pub mod commodity_state;
23
pub mod error;
24
#[cfg(any(test, feature = "test-utils"))]
25
pub mod exhausted_pool;
26
pub mod fleet;
27
pub(crate) mod hierarchy;
28
#[cfg(any(test, feature = "test-utils"))]
29
pub mod log_capture;
30
pub mod logical;
31
#[cfg(any(test, feature = "test-utils"))]
32
pub mod lossless;
33
pub mod preflight;
34
pub mod provision;
35
pub mod script;
36
pub mod script_run;
37
pub mod script_state;
38
pub mod script_tags;
39
pub mod snapshot;
40
pub mod split;
41
pub mod ssh_keys;
42
pub mod tag;
43
pub mod tag_state;
44
pub mod telemetry;
45
pub mod template_state;
46
#[cfg(test)]
47
mod test_support;
48
pub mod timezone;
49
pub mod user;
50
use sqlx::any::install_default_drivers;
51
use tokio::{runtime::Handle, task::JoinHandle};
52

            
53
#[macro_use]
54
extern crate rust_i18n;
55

            
56
i18n!("locales", fallback = "en");
57

            
58
/// Runs the one-time-per-DB boot sequence: install sqlx drivers, migrate the
59
/// admin DB, run the idempotent global seed (`seed_complete`-guarded), and load
60
/// config. Every startup path MUST call this before reading config — the web
61
/// binary calls it directly; the CLI/server path goes through [`start`]. Safe
62
/// to call on an already-booted DB (migrate + seed are idempotent).
63
180
pub async fn boot() -> anyhow::Result<()> {
64
180
    install_default_drivers();
65
180
    db::migrate_db().await?;
66
180
    bootstrap::seed().await?;
67
180
    config::load_config().await?;
68

            
69
180
    tracing::info!("{}", t!("The server boot complete"));
70
180
    Ok(())
71
180
}
72

            
73
180
pub async fn start() -> JoinHandle<anyhow::Result<()>> {
74
180
    let handle = Handle::current();
75

            
76
180
    handle.spawn(boot())
77
180
}