1
use server::config::set_system_config;
2

            
3
/// Boot the server the same way the original CLI entrypoint did:
4
/// install drivers, run migrations, load config. Used by both
5
/// binaries so the initialization sequence stays identical.
6
///
7
/// # Errors
8
///
9
/// Returns an `anyhow::Error` if `database` conflicts with an already resolved
10
/// database URL, if the boot task fails or is aborted, or if
11
/// `set_system_config` fails for the optional `setopt` override.
12
12
pub async fn start_server(
13
12
    database: Option<String>,
14
12
    setopt: Option<(String, String)>,
15
12
) -> anyhow::Result<()> {
16
12
    if let Some(db) = database {
17
12
        server::db::use_url(db)?;
18
    }
19

            
20
    // `server::start` already returns the boot task's handle; spawning it again
21
    // only added a third Result layer to unwrap.
22
12
    server::start().await.await??;
23

            
24
12
    if let Some((field, content)) = setopt {
25
        set_system_config(&field, content.into()).await?;
26
12
    }
27

            
28
12
    Ok(())
29
12
}