#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
fn main() {
use std::time::Duration;
use supermachine::{Image, VmConfig};
let snap = std::env::var("SUPERMACHINE_RECON_SNAPSHOT").expect("SUPERMACHINE_RECON_SNAPSHOT");
let cmd = std::env::var("SUPERMACHINE_RECON_CMD").expect("SUPERMACHINE_RECON_CMD");
let mem: u32 = std::env::var("SUPERMACHINE_RECON_MEM_MIB")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(8192);
let cfg = VmConfig::new().with_memory_mib(mem);
let vm = Image::from_snapshot(&snap)
.expect("from_snapshot")
.start(&cfg)
.expect("start");
for _ in 0..120 {
if let Ok(o) = vm
.exec_builder()
.argv(["/bin/sh", "-c", "echo up"])
.output()
{
if o.success() {
break;
}
}
std::thread::sleep(Duration::from_millis(1000));
}
let o = vm
.exec_builder()
.argv(["/bin/sh", "-c", &cmd])
.output()
.expect("exec");
println!("RECON_STDOUT_BEGIN");
println!("{}", String::from_utf8_lossy(&o.stdout));
println!("RECON_STDOUT_END success={}", o.success());
eprintln!("stderr: {}", String::from_utf8_lossy(&o.stderr));
vm.stop().ok();
}
#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))]
fn main() {
eprintln!("linux/x86_64 only");
}