forked from lavina/lavina
1
0
Fork 0
lavina/src/main.rs

67 lines
1.7 KiB
Rust
Raw Normal View History

2023-02-04 01:01:49 +00:00
mod core;
2023-01-19 17:18:41 +00:00
mod prelude;
2023-02-04 01:01:49 +00:00
mod projections;
2023-02-07 15:21:00 +00:00
mod protos;
2023-02-04 01:01:49 +00:00
mod util;
2023-01-19 17:18:41 +00:00
2023-01-19 14:25:52 +00:00
use std::future::Future;
use figment::providers::Format;
use figment::{providers::Toml, Figment};
use prometheus::Registry as MetricsRegistry;
2023-01-19 14:25:52 +00:00
use serde::Deserialize;
use crate::core::player::PlayerRegistry;
use crate::core::room::RoomRegistry;
use crate::prelude::*;
2023-01-19 14:25:52 +00:00
#[derive(Deserialize, Debug)]
struct ServerConfig {
telemetry: util::telemetry::ServerConfig,
irc: projections::irc::ServerConfig,
2023-01-19 14:25:52 +00:00
}
fn load_config() -> Result<ServerConfig> {
let raw_config = Figment::new().merge(Toml::file("config.toml"));
let config: ServerConfig = raw_config.extract()?;
Ok(config)
}
#[tokio::main]
async fn main() -> Result<()> {
set_up_logging()?;
let sleep = ctrl_c()?;
let config = load_config()?;
2023-01-27 20:43:20 +00:00
tracing::info!("Booting up");
tracing::info!("Loaded config: {config:?}");
2023-02-09 19:01:21 +00:00
let metrics = MetricsRegistry::new();
2023-02-03 22:43:59 +00:00
let rooms = RoomRegistry::empty();
let players = PlayerRegistry::empty(rooms.clone());
2023-02-09 19:01:21 +00:00
let telemetry_terminator = util::telemetry::launch(&config.telemetry, metrics.clone()).await?;
let irc = projections::irc::launch(&config.irc, players, metrics.clone()).await?;
2023-01-19 14:25:52 +00:00
tracing::info!("Started");
sleep.await;
2023-01-19 14:25:52 +00:00
tracing::info!("Begin shutdown");
2023-02-07 15:21:00 +00:00
irc.terminate().await?;
telemetry_terminator.terminate().await?;
2023-01-19 14:25:52 +00:00
tracing::info!("Shutdown complete");
Ok(())
}
fn ctrl_c() -> Result<impl Future<Output = ()>> {
use tokio::signal::unix::*;
let chan = signal(SignalKind::interrupt())?;
async fn recv(mut chan: Signal) {
let _ = chan.recv().await;
}
Ok(recv(chan))
}
fn set_up_logging() -> Result<()> {
tracing_subscriber::fmt::init();
Ok(())
}