-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathstart.rs
More file actions
94 lines (83 loc) · 2.26 KB
/
start.rs
File metadata and controls
94 lines (83 loc) · 2.26 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::time::Duration;
use anyhow::*;
use clap::Parser;
use rivet_service_manager::{CronConfig, RunConfig};
// 7 day logs retention
const LOGS_RETENTION: Duration = Duration::from_secs(7 * 24 * 60 * 60);
#[derive(Parser)]
pub struct Opts {
#[arg(long)]
skip_provision: bool,
#[arg(long, value_enum)]
services: Vec<ServiceKind>,
}
#[derive(clap::ValueEnum, Clone, PartialEq)]
enum ServiceKind {
ApiPublic,
ApiEdge,
ApiPrivate,
Standalone,
Singleton,
Oneshot,
Cron,
}
impl From<ServiceKind> for rivet_service_manager::ServiceKind {
fn from(val: ServiceKind) -> Self {
use ServiceKind::*;
match val {
ApiPublic => rivet_service_manager::ServiceKind::ApiPublic,
ApiEdge => rivet_service_manager::ServiceKind::ApiEdge,
ApiPrivate => rivet_service_manager::ServiceKind::ApiPrivate,
Standalone => rivet_service_manager::ServiceKind::Standalone,
Singleton => rivet_service_manager::ServiceKind::Singleton,
Oneshot => rivet_service_manager::ServiceKind::Oneshot,
Cron => rivet_service_manager::ServiceKind::Cron(CronConfig::default()),
}
}
}
impl Opts {
pub async fn execute(
&self,
config: rivet_config::Config,
run_config: &RunConfig,
) -> Result<()> {
// Redirect logs if enabled on the edge
if let Some(logs_dir) = config
.server()
.ok()
.and_then(|x| x.rivet.edge.as_ref())
.and_then(|x| x.redirect_logs_dir.as_ref())
{
rivet_logs::Logs::new(logs_dir.clone(), LOGS_RETENTION)
.start()
.await?;
}
// Provision services before starting server
if !self.skip_provision {
s3_util::provision(config.clone(), &run_config.s3_buckets).await?;
rivet_migrate::up(config.clone(), &run_config.sql_services).await?;
}
// Select services t orun
let services = if self.services.is_empty() {
// Run all services
run_config.services.clone()
} else {
// Filter services
let service_kinds = self
.services
.iter()
.map(|x| x.clone().into())
.collect::<Vec<rivet_service_manager::ServiceKind>>();
run_config
.services
.iter()
.filter(|x| service_kinds.iter().any(|y| y.eq(&x.kind)))
.cloned()
.collect::<Vec<_>>()
};
// Start server
let pools = rivet_pools::Pools::new(config.clone()).await?;
rivet_service_manager::start(config, pools, services).await?;
Ok(())
}
}