MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / main

Function main

vmm/src/main.rs:149–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147
148#[rocket::main]
149async fn main() -> Result<()> {
150 {
151 use tracing_subscriber::{fmt, EnvFilter};
152 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
153 fmt().with_env_filter(filter).with_ansi(false).init();
154 }
155
156 let args = Args::parse();
157 let figment = config::load_config_figment(args.config.as_deref());
158 let config = Config::extract_or_default(&figment)?.abs_path()?;
159
160 // Validate host API configuration
161 config
162 .host_api
163 .validate()
164 .context("Invalid host_api configuration")?;
165
166 // Handle commands
167 match args.command.unwrap_or_default() {
168 Command::Run(run_args) => {
169 // One-shot VM execution mode
170 return one_shot::run_one_shot(
171 &run_args.vm_config,
172 config,
173 run_args.workdir,
174 run_args.dry_run,
175 )
176 .await;
177 }
178 Command::Serve => {
179 // Default server mode - continue to main server logic
180 }
181 }
182
183 // Register this VMM instance for local discovery
184 discovery::cleanup_stale_registrations();
185 let listen_address = {
186 // Use Rocket's Endpoint type to parse the address exactly as Rocket would,
187 // then override the port with the figment's port value (matching Rocket's behavior).
188 let endpoint: rocket::listener::Endpoint =
189 figment.extract_inner("address").unwrap_or_default();
190 match endpoint.tcp() {
191 Some(addr) => {
192 let port: u16 = figment.extract_inner("port").unwrap_or(addr.port());
193 format!("{}:{port}", addr.ip())
194 }
195 None => endpoint.to_string(),
196 }
197 };
198 let _discovery_reg = discovery::DiscoveryRegistration::register(
199 &listen_address,
200 args.config.as_deref(),
201 &config.image.path,
202 &config.run_path,
203 &config.node_name,
204 &app_version(),
205 )
206 .context("failed to register VMM instance for discovery")?;

Callers

nothing calls this directly

Calls 9

run_one_shotFunction · 0.85
auto_restart_taskFunction · 0.85
abs_pathMethod · 0.80
cloneMethod · 0.80
load_config_figmentFunction · 0.70
app_versionFunction · 0.70
validateMethod · 0.45
reload_vmsMethod · 0.45

Tested by

no test coverage detected