2024-04-07 19:41:21 +01:00
|
|
|
mod actors;
|
2024-04-07 13:47:39 +01:00
|
|
|
mod config;
|
2024-04-16 22:21:55 +01:00
|
|
|
pub mod gitforge;
|
2024-04-12 18:45:32 +01:00
|
|
|
pub mod types;
|
2024-04-07 13:47:39 +01:00
|
|
|
|
2024-04-07 20:16:04 +01:00
|
|
|
use actix::prelude::*;
|
2024-04-16 22:21:55 +01:00
|
|
|
|
2024-04-09 10:44:01 +01:00
|
|
|
use kxio::network::Network;
|
2024-04-07 20:16:04 +01:00
|
|
|
|
2024-04-07 11:52:47 +01:00
|
|
|
use std::path::PathBuf;
|
2024-04-06 18:42:34 +01:00
|
|
|
|
2024-04-10 11:40:42 +01:00
|
|
|
use tracing::{error, info, level_filters::LevelFilter};
|
2024-04-06 18:53:18 +01:00
|
|
|
|
2024-05-07 08:17:29 +01:00
|
|
|
use crate::{
|
|
|
|
fs::FileSystem,
|
|
|
|
server::{actors::server::Server, types::ServerGeneration},
|
|
|
|
};
|
2024-04-27 15:23:42 +01:00
|
|
|
|
2024-04-07 16:09:16 +01:00
|
|
|
pub fn init(fs: FileSystem) {
|
2024-04-06 18:42:34 +01:00
|
|
|
let file_name = "git-next-server.toml";
|
2024-04-28 08:05:09 +01:00
|
|
|
let pathbuf = PathBuf::from(file_name);
|
|
|
|
let Ok(exists) = fs.path_exists(&pathbuf) else {
|
|
|
|
eprintln!("Could not check if file exist: {}", file_name);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
if exists {
|
2024-04-07 08:56:33 +01:00
|
|
|
eprintln!(
|
|
|
|
"The configuration file already exists at {} - not overwritting it.",
|
|
|
|
file_name
|
|
|
|
);
|
|
|
|
} else {
|
2024-04-28 08:05:09 +01:00
|
|
|
match fs.file_write(&pathbuf, include_str!("../../server-default.toml")) {
|
2024-04-07 11:52:47 +01:00
|
|
|
Ok(_) => println!("Created a default configuration file at {}", file_name),
|
2024-04-06 18:42:34 +01:00
|
|
|
Err(e) => {
|
2024-04-07 11:52:47 +01:00
|
|
|
eprintln!("Failed to write to the configuration file: {}", e)
|
2024-04-06 18:42:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-06 18:53:18 +01:00
|
|
|
|
2024-04-16 22:21:55 +01:00
|
|
|
pub async fn start(fs: FileSystem, net: Network) {
|
2024-04-27 15:23:42 +01:00
|
|
|
init_logging();
|
2024-05-07 08:17:29 +01:00
|
|
|
let generation = ServerGeneration::new();
|
|
|
|
{
|
|
|
|
let span = tracing::info_span!("Server", %generation);
|
|
|
|
let _guard = span.enter();
|
|
|
|
info!("Starting Server...");
|
|
|
|
let server_config = match config::ServerConfig::load(&fs) {
|
|
|
|
Ok(server_config) => server_config,
|
|
|
|
Err(err) => {
|
|
|
|
error!("Failed to load config file. Error: {}", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2024-05-04 12:37:35 +01:00
|
|
|
|
2024-05-07 08:17:29 +01:00
|
|
|
let server = Server::new(generation, fs.clone(), net.clone()).start();
|
|
|
|
server.do_send(server_config);
|
|
|
|
}
|
2024-05-04 12:37:35 +01:00
|
|
|
|
|
|
|
info!("Server running - Press Ctrl-C to stop...");
|
2024-04-12 12:58:07 +01:00
|
|
|
let _ = actix_rt::signal::ctrl_c().await;
|
|
|
|
info!("Ctrl-C received, shutting down...");
|
2024-04-09 07:20:13 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 15:23:42 +01:00
|
|
|
pub fn init_logging() {
|
2024-04-06 18:53:18 +01:00
|
|
|
use tracing_subscriber::prelude::*;
|
|
|
|
|
|
|
|
let subscriber = tracing_subscriber::fmt::layer()
|
|
|
|
// NOTE: set RUSTLOG in ${root}/.cargo/config
|
|
|
|
.with_target(false)
|
|
|
|
.with_file(true)
|
2024-04-10 11:40:42 +01:00
|
|
|
.with_line_number(true)
|
|
|
|
.with_filter(LevelFilter::INFO);
|
2024-04-06 18:53:18 +01:00
|
|
|
tracing_subscriber::registry()
|
2024-04-10 11:40:42 +01:00
|
|
|
.with(console_subscriber::ConsoleLayer::builder().spawn())
|
2024-04-06 18:53:18 +01:00
|
|
|
.with(subscriber)
|
|
|
|
.init();
|
|
|
|
}
|