From 6aa191663a97ae9193deeb0afd5984a2446780c2 Mon Sep 17 00:00:00 2001 From: Thales Maciel Date: Thu, 29 Jan 2026 13:25:23 -0300 Subject: [PATCH] Rename vm_id field and add list helpers --- README.md | 2 +- list.sh | 24 ++++++++++++++++++++++++ ps.sh | 23 +++++++++++++++++++++++ run.sh | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 list.sh create mode 100755 ps.sh diff --git a/README.md b/README.md index f8ed8e0..5d6105f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ reboot ## VM Info File Each VM writes a metadata file at `state/vm-*/info` with the following fields: -- `vm_id`: unique identifier for the VM instance. +- `id`: unique identifier for the VM instance. - `pid`: Firecracker process ID. - `created_at`: timestamp when the VM was launched. - `guest_ip`: IP address assigned to the guest. diff --git a/list.sh b/list.sh new file mode 100755 index 0000000..d3df0f2 --- /dev/null +++ b/list.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +shopt -s nullglob + +for info in state/vm-*/info; do + id="$(awk -F= '$1=="id"{print $2}' "$info")" + name="$(awk -F= '$1=="name"{print $2}' "$info")" + created_at="$(awk -F= '$1=="created_at"{print $2}' "$info")" + guest_ip="$(awk -F= '$1=="guest_ip"{print $2}' "$info")" + pid="$(awk -F= '$1=="pid"{print $2}' "$info")" + tap="$(awk -F= '$1=="tap"{print $2}' "$info")" + api_sock="$(awk -F= '$1=="api_sock"{print $2}' "$info")" + + status="stale" + if [[ -n "$pid" && -n "$api_sock" ]]; then + if ps -p "$pid" -o comm=,args= 2>/dev/null | rg -q "firecracker.*--api-sock $api_sock"; then + status="running" + fi + fi + + printf 'status=%s id=%s name=%s created_at=%s guest_ip=%s pid=%s tap=%s\n' \ + "$status" "$id" "$name" "$created_at" "$guest_ip" "$pid" "$tap" +done diff --git a/ps.sh b/ps.sh new file mode 100755 index 0000000..bc13c8b --- /dev/null +++ b/ps.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +shopt -s nullglob + +for info in state/vm-*/info; do + id="$(awk -F= '$1=="id"{print $2}' "$info")" + name="$(awk -F= '$1=="name"{print $2}' "$info")" + created_at="$(awk -F= '$1=="created_at"{print $2}' "$info")" + guest_ip="$(awk -F= '$1=="guest_ip"{print $2}' "$info")" + pid="$(awk -F= '$1=="pid"{print $2}' "$info")" + tap="$(awk -F= '$1=="tap"{print $2}' "$info")" + api_sock="$(awk -F= '$1=="api_sock"{print $2}' "$info")" + + if [[ -z "$pid" || -z "$api_sock" ]]; then + continue + fi + + if ps -p "$pid" -o comm=,args= 2>/dev/null | rg -q "firecracker.*--api-sock $api_sock"; then + printf 'id=%s name=%s created_at=%s guest_ip=%s pid=%s tap=%s\n' \ + "$id" "$name" "$created_at" "$guest_ip" "$pid" "$tap" + fi +done diff --git a/run.sh b/run.sh index 621afd9..4a0694c 100755 --- a/run.sh +++ b/run.sh @@ -355,7 +355,7 @@ log "starting virtual machine" VM_STARTED=1 cat > "$VM_DIR/info" <