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
56 lines (45 loc) · 1.8 KB
/
Copy pathmain.rs
File metadata and controls
56 lines (45 loc) · 1.8 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
54
55
56
use std::env;
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 = "./config.toml";
const CONFIG_ENV_VAR_NAME: &str = "TORRUST_TRACKER_CONFIG";
// 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 = if env::var(CONFIG_ENV_VAR_NAME).is_ok() {
println!("Loading configuration from env var {CONFIG_ENV_VAR_NAME}");
Arc::new(Configuration::load_from_env_var(CONFIG_ENV_VAR_NAME).unwrap())
} else {
println!("Loading configuration from config file {CONFIG_PATH}");
Arc::new(Configuration::load_from_file(CONFIG_PATH).unwrap())
};
// 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.");
}
}
}