Prepare, configure, and manage Firecracker microVMs in seconds!
virtualization linux microvm firecracker
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

implement 'reset' subcommand

+58 -4
+1 -1
Cargo.lock
··· 168 168 169 169 [[package]] 170 170 name = "fireup" 171 - version = "0.1.0" 171 + version = "0.1.1" 172 172 dependencies = [ 173 173 "anyhow", 174 174 "clap",
+1
README.md
··· 37 37 - `status`: Checks the status of the Firecracker microVM (running, stopped, or errored). 38 38 - `logs`: Displays the logs of the Firecracker microVM from the log file. 39 39 - `ssh`: Connects to the Firecracker microVM via SSH. 40 + - `reset`: Resets the Firecracker microVM, stopping it and preparing it for a fresh start. 40 41 - `help`: Prints help information for the CLI or specific subcommands.
+8 -1
crates/firecracker-prepare/src/lib.rs
··· 25 25 26 26 let ext4_file = format!("{}/ubuntu-{}.ext4", app_dir, ubuntu_version); 27 27 28 - rootfs::create_ext4_filesystem(&squashfs_root_dir, &ext4_file)?; 28 + if !std::path::Path::new(&ext4_file).exists() { 29 + rootfs::create_ext4_filesystem(&squashfs_root_dir, &ext4_file)?; 30 + } else { 31 + println!( 32 + "[!] {} already exists, skipping ext4 creation.", 33 + ext4_file.bright_yellow() 34 + ); 35 + } 29 36 30 37 let ssh_key_file = format!("{}/{}", app_dir, ssh_key_name); 31 38
+1 -1
crates/firecracker-up/Cargo.toml
··· 1 1 [package] 2 2 name = "fireup" 3 - version = "0.1.0" 3 + version = "0.1.1" 4 4 authors.workspace = true 5 5 edition.workspace = true 6 6 license.workspace = true
+1
crates/firecracker-up/src/cmd/mod.rs
··· 1 1 pub mod down; 2 2 pub mod logs; 3 + pub mod reset; 3 4 pub mod ssh; 4 5 pub mod status; 5 6 pub mod up;
+43
crates/firecracker-up/src/cmd/reset.rs
··· 1 + use anyhow::Error; 2 + use glob::glob; 3 + use owo_colors::OwoColorize; 4 + 5 + use crate::cmd::down::down; 6 + 7 + pub fn reset() -> Result<(), Error> { 8 + println!( 9 + "Are you sure you want to reset? This will remove all ext4 files. Type '{}' to confirm:", 10 + "yes".bright_green() 11 + ); 12 + let mut input = String::new(); 13 + std::io::stdin() 14 + .read_line(&mut input) 15 + .map_err(|e| Error::msg(format!("Failed to read input: {}", e)))?; 16 + let input = input.trim(); 17 + 18 + if input != "yes" { 19 + println!("Reset cancelled."); 20 + return Ok(()); 21 + } 22 + 23 + down()?; 24 + 25 + let app_dir = crate::config::get_config_dir()?; 26 + let ext4_file = glob(format!("{}/*.ext4", app_dir).as_str()) 27 + .map_err(|e| Error::msg(format!("Failed to find ext4 file: {}", e)))?; 28 + 29 + for file in ext4_file { 30 + if let Ok(path) = file { 31 + std::fs::remove_file(path) 32 + .map_err(|e| Error::msg(format!("Failed to remove file: {}", e)))?; 33 + } 34 + } 35 + 36 + println!("[+] Reset complete. All ext4 files have been removed."); 37 + println!( 38 + "[+] You can now run '{}' to start a new Firecracker MicroVM.", 39 + "fireup".bright_green() 40 + ); 41 + 42 + Ok(()) 43 + }
+3 -1
crates/firecracker-up/src/main.rs
··· 2 2 use clap::{arg, Command}; 3 3 use owo_colors::OwoColorize; 4 4 5 - use crate::cmd::{down::down, logs::logs, ssh::ssh, status::status, up::up}; 5 + use crate::cmd::{down::down, logs::logs, reset::reset, ssh::ssh, status::status, up::up}; 6 6 7 7 pub mod cmd; 8 8 pub mod command; ··· 39 39 .about("View the logs of the Firecracker MicroVM"), 40 40 ) 41 41 .subcommand(Command::new("ssh").about("SSH into the Firecracker MicroVM")) 42 + .subcommand(Command::new("reset").about("Reset the Firecracker MicroVM")) 42 43 } 43 44 44 45 fn main() -> Result<()> { ··· 53 54 logs(follow)?; 54 55 } 55 56 Some(("ssh", _)) => ssh()?, 57 + Some(("reset", _)) => reset()?, 56 58 _ => up()?, 57 59 } 58 60