1pub mod config;
2pub mod database;
3pub mod library;
4pub mod logger;
5pub mod music;
6pub mod server;
7
8use config::Config;
9use pg_embed::pg_errors::PgEmbedErrorType;
10use server::Server;
11use std::{error::Error, path::Path};
12
13use database::*;
14use pg_embed::pg_errors::PgEmbedError;
15use pg_embed::pg_errors::PgEmbedErrorType::*;
16
17use color_eyre::eyre::eyre;
18use color_eyre::Result;
19use log::{debug, error, info, warn};
20
21pub async fn start(config: Config) -> Result<()> {
22 info!("Ouverture server started");
23
24 let status = {
26 let mut pg = setup_db(config.clone()).await?;
27
28 let res = start_db(&mut pg, config.clone()).await;
29 if let Err(e) = res {
30 warn!(
31 "Retrying to start the database (may happen when the last process was interrupted)"
32 );
33 debug!("failed to start the database once {e}");
34 if format!("{:?}", e).contains("PgStartFailure") {
35 pg = setup_db(config.clone()).await?;
38 start_db(&mut pg, config.clone()).await?;
39 }
40 }
41 let server_exit_status = Server::start(&config).await;
44
45 debug!("stopping database");
46 let res = pg.stop_db().await;
47 match res {
48 Err(e) => error!("failed to stop database {:?}", e),
49 _ => (),
50 };
51 server_exit_status
52 };
53
54 info!("Ouverture server stopped");
55 status
56}