Files
continuwuity/src/main/server.rs
T

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

88 lines
2.2 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2024-05-09 15:59:08 -07:00
use conduwuit_core::{
Error, Result,
config::Config,
info,
log::Log,
utils::{stream, sys},
};
2024-07-27 07:17:07 +00:00
use tokio::{runtime, sync::Mutex};
2024-05-09 15:59:08 -07:00
2025-07-06 21:59:20 +01:00
use crate::{
clap::{Args, update},
logging::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<conduwuit_core::Server>,
2024-05-09 15:59:08 -07:00
2024-12-14 21:58:01 -05:00
pub(crate) services: Mutex<Option<Arc<conduwuit_service::Services>>>,
2024-07-27 07:17:07 +00:00
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(all(conduwuit_mods, feature = "conduwuit_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<conduwuit_core::mods::Module>>,
2024-05-09 15:59:08 -07:00
}
impl Server {
2024-12-17 14:32:54 +00:00
pub(crate) fn new(
args: &Args,
runtime: Option<&runtime::Handle>,
) -> Result<Arc<Self>, Error> {
let _runtime_guard = runtime.map(runtime::Handle::enter);
let config_paths = args.config.clone().unwrap_or_default();
let config = Config::load(&config_paths)
2025-07-06 21:59:20 +01:00
.and_then(|raw| update(raw, args))
.and_then(|raw| Config::new(&raw))?;
2024-06-04 23:51:02 +00:00
let (tracing_reload_handle, tracing_flame_guard, capture) =
crate::logging::init(&config)?;
2024-05-09 15:59:08 -07:00
config.check()?;
2025-01-28 19:42:09 +00:00
#[cfg(feature = "sentry_telemetry")]
let sentry_guard = crate::sentry::init(&config);
2024-05-09 15:59:08 -07:00
#[cfg(unix)]
sys::maximize_fd_limit()
.expect("Unable to increase maximum soft and hard file descriptor limit");
2024-06-04 23:51:02 +00:00
let (_old_width, _new_width) = stream::set_width(config.stream_width_default);
2025-01-01 06:08:20 +00:00
let (_old_amp, _new_amp) = stream::set_amplification(config.stream_amplification);
2024-05-09 15:59:08 -07:00
info!(
server_name = %config.server_name,
database_path = ?config.database_path,
log_levels = %config.log,
"{}",
conduwuit_core::version(),
2024-05-09 15:59:08 -07:00
);
2024-06-09 10:23:06 +00:00
Ok(Arc::new(Self {
server: Arc::new(conduwuit_core::Server::new(config, runtime.cloned(), Log {
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(all(conduwuit_mods, feature = "conduwuit_mods"))]
2024-05-09 15:59:08 -07:00
mods: tokio::sync::RwLock::new(Vec::new()),
}))
}
}