MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / spawn

Function spawn

crates/openshell-server/src/compute/vm.rs:452–516  ·  view source on GitHub ↗
(
    config: &Config,
    vm_config: &VmComputeConfig,
)

Source from the content-addressed store, hash-verified

450/// kills the subprocess and removes the socket on drop.
451#[cfg(unix)]
452pub async fn spawn(
453 config: &Config,
454 vm_config: &VmComputeConfig,
455) -> Result<AcquiredRemoteDriverEndpoint> {
456 if vm_config.grpc_endpoint.trim().is_empty() {
457 return Err(Error::config(
458 "grpc_endpoint is required when using the vm compute driver",
459 ));
460 }
461
462 let driver_bin = resolve_compute_driver_bin(vm_config)?;
463 let socket_path = compute_driver_socket_path(vm_config);
464 let guest_tls_paths = compute_driver_guest_tls_paths(vm_config)?;
465 prepare_compute_driver_socket_path(vm_config, &socket_path)?;
466
467 let mut command = Command::new(&driver_bin);
468 command.kill_on_drop(true);
469 command.stdin(Stdio::null());
470 command.stdout(Stdio::inherit());
471 command.stderr(Stdio::inherit());
472 command.arg("--bind-socket").arg(&socket_path);
473 command
474 .arg("--expected-peer-pid")
475 .arg(std::process::id().to_string());
476 command.arg("--log-level").arg(&config.log_level);
477 command
478 .arg("--openshell-endpoint")
479 .arg(&vm_config.grpc_endpoint);
480 command.arg("--state-dir").arg(&vm_config.state_dir);
481 if !vm_config.default_image.trim().is_empty() {
482 command.arg("--default-image").arg(&vm_config.default_image);
483 }
484 if !vm_config.bootstrap_image.trim().is_empty() {
485 command
486 .arg("--bootstrap-image")
487 .arg(&vm_config.bootstrap_image);
488 }
489 command
490 .arg("--krun-log-level")
491 .arg(vm_config.krun_log_level.to_string());
492 command.arg("--vcpus").arg(vm_config.vcpus.to_string());
493 command.arg("--mem-mib").arg(vm_config.mem_mib.to_string());
494 command
495 .arg("--overlay-disk-mib")
496 .arg(vm_config.overlay_disk_mib.to_string());
497 if let Some(tls) = guest_tls_paths {
498 command.arg("--guest-tls-ca").arg(tls.ca);
499 command.arg("--guest-tls-cert").arg(tls.cert);
500 command.arg("--guest-tls-key").arg(tls.key);
501 }
502
503 let mut child = command.spawn().map_err(|e| {
504 Error::execution(format!(
505 "failed to launch vm compute driver '{}': {e}",
506 driver_bin.display()
507 ))
508 })?;
509 let channel = wait_for_compute_driver(&socket_path, &mut child).await?;

Callers 15

spawn_watchersMethod · 0.70
run_as_holderMethod · 0.70
proxy_to_endpointFunction · 0.50
http1_getFunction · 0.50
spawn_refresh_workerFunction · 0.50
run_serverFunction · 0.50
spawn_gateway_connectionFunction · 0.50
build_compute_runtimeFunction · 0.50

Calls 8

configFunction · 0.85
wait_for_compute_driverFunction · 0.85
is_emptyMethod · 0.45
spawnMethod · 0.45