Files
continuwuity/src/main/server.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.8 KiB
Rust
Raw Normal View History

2024-05-09 15:59:08 -07:00
use std::sync::Arc;
2024-06-26 00:19:35 +00:00
use conduit::{config::Config, info, log::Log, utils::sys, Error, Result};
2024-07-27 07:17:07 +00:00
use tokio::{runtime, sync::Mutex};
2024-05-09 15:59:08 -07:00
2024-06-24 22:22:18 +00:00
use crate::{clap::Args, tracing::TracingFlameGuard};
2024-05-20 08:11:05 +00:00
2024-05-09 15:59:08 -07:00
/// Server runtime state; complete
pub(crate) struct Server {
/// Server runtime state; public portion
pub(crate) server: Arc<conduit::Server>,
2024-07-27 07:17:07 +00:00
pub(crate) services: Mutex<Option<Arc<conduit_service::Services>>>,
2024-05-09 15:59:08 -07:00
_tracing_flame_guard: TracingFlameGuard,
#[cfg(feature = "sentry_telemetry")]
_sentry_guard: Option<::sentry::ClientInitGuard>,
2024-05-09 15:59:08 -07:00
#[cfg(conduit_mods)]
2024-05-09 15:59:08 -07:00
// Module instances; TODO: move to mods::loaded mgmt vector
pub(crate) mods: tokio::sync::RwLock<Vec<conduit::mods::Module>>,
}
impl Server {
pub(crate) fn build(args: &Args, runtime: Option<&runtime::Handle>) -> Result<Arc<Self>, Error> {
2024-07-25 02:59:54 +00:00
let raw_config = Config::load(&args.config)?;
let raw_config = crate::clap::update(raw_config, args)?;
let config = Config::new(&raw_config)?;
2024-06-04 23:51:02 +00:00
2024-05-09 15:59:08 -07:00
#[cfg(feature = "sentry_telemetry")]
let sentry_guard = crate::sentry::init(&config);
2024-07-11 05:03:16 +00:00
let (tracing_reload_handle, tracing_flame_guard, capture) = crate::tracing::init(&config)?;
2024-05-09 15:59:08 -07:00
config.check()?;
2024-05-09 15:59:08 -07:00
#[cfg(unix)]
2024-06-04 23:51:02 +00:00
sys::maximize_fd_limit().expect("Unable to increase maximum soft and hard file descriptor limit");
2024-05-09 15:59:08 -07:00
info!(
server_name = %config.server_name,
database_path = ?config.database_path,
log_levels = %config.log,
"{}",
2024-06-24 22:06:20 +00:00
conduit::version(),
2024-05-09 15:59:08 -07:00
);
2024-06-09 10:23:06 +00:00
Ok(Arc::new(Self {
2024-06-11 01:26:31 +00:00
server: Arc::new(conduit::Server::new(
config,
runtime.cloned(),
2024-06-26 00:19:35 +00:00
Log {
2024-06-11 01:26:31 +00:00
reload: tracing_reload_handle,
capture,
},
)),
2024-05-09 15:59:08 -07:00
2024-07-27 07:17:07 +00:00
services: None.into(),
2024-05-09 15:59:08 -07:00
_tracing_flame_guard: tracing_flame_guard,
#[cfg(feature = "sentry_telemetry")]
_sentry_guard: sentry_guard,
#[cfg(conduit_mods)]
2024-05-09 15:59:08 -07:00
mods: tokio::sync::RwLock::new(Vec::new()),
}))
}
}