forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
53 lines (42 loc) · 1.54 KB
/
main.rs
File metadata and controls
53 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::sync::Arc;
use log::info;
use torrust_tracker::config::Configuration;
use torrust_tracker::stats::setup_statistics;
use torrust_tracker::{ephemeral_instance_keys, logging, setup, static_time, tracker};
#[tokio::main]
async fn main() {
const CONFIG_PATH: &str = "./storage/config/config.toml";
// Set the time of Torrust app starting
lazy_static::initialize(&static_time::TIME_AT_APP_START);
// Initialize the Ephemeral Instance Random Seed
lazy_static::initialize(&ephemeral_instance_keys::RANDOM_SEED);
// Initialize Torrust config
let config = match Configuration::load_from_file(CONFIG_PATH) {
Ok(config) => Arc::new(config),
Err(error) => {
panic!("{}", error)
}
};
// Initialize statistics
let (stats_event_sender, stats_repository) = setup_statistics(config.tracker_usage_statistics);
// Initialize Torrust tracker
let tracker = match tracker::Tracker::new(&config.clone(), stats_event_sender, stats_repository) {
Ok(tracker) => Arc::new(tracker),
Err(error) => {
panic!("{}", error)
}
};
// Initialize logging
logging::setup(&config);
// Run jobs
let jobs = setup::setup(&config, tracker.clone()).await;
// handle the signals here
tokio::select! {
_ = tokio::signal::ctrl_c() => {
info!("Torrust shutting down..");
// Await for all jobs to shutdown
futures::future::join_all(jobs).await;
info!("Torrust successfully shutdown.");
}
}
}