Move VM dirs under state/vms
This commit is contained in:
parent
75f03aeb04
commit
f8e7aedeb2
8 changed files with 11 additions and 10 deletions
|
|
@ -37,7 +37,7 @@ reboot
|
||||||
```
|
```
|
||||||
|
|
||||||
## VM Info File
|
## VM Info File
|
||||||
Each VM writes a metadata file at `state/vm-*/info` with the following fields:
|
Each VM writes a metadata file at `state/vms/<id>/info` with the following fields:
|
||||||
- `id`: unique identifier for the VM instance.
|
- `id`: unique identifier for the VM instance.
|
||||||
- `pid`: Firecracker process ID.
|
- `pid`: Firecracker process ID.
|
||||||
- `created_at`: timestamp when the VM was launched.
|
- `created_at`: timestamp when the VM was launched.
|
||||||
|
|
|
||||||
2
kill.sh
2
kill.sh
|
|
@ -23,7 +23,7 @@ find_vm_info() {
|
||||||
local query="$1"
|
local query="$1"
|
||||||
local info match_count=0 match=""
|
local info match_count=0 match=""
|
||||||
|
|
||||||
for info in state/vm-*/info; do
|
for info in state/vms/*/info; do
|
||||||
[[ -f "$info" ]] || continue
|
[[ -f "$info" ]] || continue
|
||||||
local id name
|
local id name
|
||||||
id="$(get_prop "$info" "id")"
|
id="$(get_prop "$info" "id")"
|
||||||
|
|
|
||||||
2
list.sh
2
list.sh
|
|
@ -9,7 +9,7 @@ get_prop() {
|
||||||
awk -F= -v k="$key" '$1==k {print $2}' "$info"
|
awk -F= -v k="$key" '$1==k {print $2}' "$info"
|
||||||
}
|
}
|
||||||
|
|
||||||
for info in state/vm-*/info; do
|
for info in state/vms/*/info; do
|
||||||
id="$(get_prop "$info" "id")"
|
id="$(get_prop "$info" "id")"
|
||||||
name="$(get_prop "$info" "name")"
|
name="$(get_prop "$info" "name")"
|
||||||
created_at="$(get_prop "$info" "created_at")"
|
created_at="$(get_prop "$info" "created_at")"
|
||||||
|
|
|
||||||
2
ps.sh
2
ps.sh
|
|
@ -9,7 +9,7 @@ get_prop() {
|
||||||
awk -F= -v k="$key" '$1==k {print $2}' "$info"
|
awk -F= -v k="$key" '$1==k {print $2}' "$info"
|
||||||
}
|
}
|
||||||
|
|
||||||
for info in state/vm-*/info; do
|
for info in state/vms/*/info; do
|
||||||
id="$(get_prop "$info" "id")"
|
id="$(get_prop "$info" "id")"
|
||||||
name="$(get_prop "$info" "name")"
|
name="$(get_prop "$info" "name")"
|
||||||
created_at="$(get_prop "$info" "created_at")"
|
created_at="$(get_prop "$info" "created_at")"
|
||||||
|
|
|
||||||
2
rm.sh
2
rm.sh
|
|
@ -23,7 +23,7 @@ find_vm_info() {
|
||||||
local query="$1"
|
local query="$1"
|
||||||
local info match_count=0 match=""
|
local info match_count=0 match=""
|
||||||
|
|
||||||
for info in state/vm-*/info; do
|
for info in state/vms/*/info; do
|
||||||
[[ -f "$info" ]] || continue
|
[[ -f "$info" ]] || continue
|
||||||
local id name
|
local id name
|
||||||
id="$(get_prop "$info" "id")"
|
id="$(get_prop "$info" "id")"
|
||||||
|
|
|
||||||
7
run.sh
7
run.sh
|
|
@ -22,7 +22,8 @@ log "starting"
|
||||||
|
|
||||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
STATE="$DIR/state"
|
STATE="$DIR/state"
|
||||||
mkdir -p "$STATE"
|
VM_ROOT="$STATE/vms"
|
||||||
|
mkdir -p "$VM_ROOT"
|
||||||
|
|
||||||
FC_BIN="$DIR/firecracker"
|
FC_BIN="$DIR/firecracker"
|
||||||
KERNEL="$DIR/vmlinux"
|
KERNEL="$DIR/vmlinux"
|
||||||
|
|
@ -52,7 +53,7 @@ shopt -s nullglob
|
||||||
name_taken() {
|
name_taken() {
|
||||||
local candidate="$1"
|
local candidate="$1"
|
||||||
local info existing_name
|
local info existing_name
|
||||||
for info in "$STATE"/vm-*/info; do
|
for info in "$VM_ROOT"/*/info; do
|
||||||
existing_name="$(awk -F= '$1=="name"{print $2}' "$info")"
|
existing_name="$(awk -F= '$1=="name"{print $2}' "$info")"
|
||||||
if [[ "$existing_name" == "$candidate" ]]; then
|
if [[ "$existing_name" == "$candidate" ]]; then
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -165,7 +166,7 @@ fi
|
||||||
|
|
||||||
VM_ID="$(head -c 32 /dev/urandom | xxd -p -c 256)"
|
VM_ID="$(head -c 32 /dev/urandom | xxd -p -c 256)"
|
||||||
VM_TAG="${VM_ID:0:8}"
|
VM_TAG="${VM_ID:0:8}"
|
||||||
VM_DIR="$STATE/vm-$VM_ID"
|
VM_DIR="$VM_ROOT/$VM_ID"
|
||||||
mkdir -p "$VM_DIR"
|
mkdir -p "$VM_DIR"
|
||||||
|
|
||||||
API_SOCK="$STATE/fc-$VM_TAG.sock"
|
API_SOCK="$STATE/fc-$VM_TAG.sock"
|
||||||
|
|
|
||||||
2
stop.sh
2
stop.sh
|
|
@ -23,7 +23,7 @@ find_vm_info() {
|
||||||
local query="$1"
|
local query="$1"
|
||||||
local info match_count=0 match=""
|
local info match_count=0 match=""
|
||||||
|
|
||||||
for info in state/vm-*/info; do
|
for info in state/vms/*/info; do
|
||||||
[[ -f "$info" ]] || continue
|
[[ -f "$info" ]] || continue
|
||||||
local id name
|
local id name
|
||||||
id="$(get_prop "$info" "id")"
|
id="$(get_prop "$info" "id")"
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ if ! ./run.sh; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VM_DIR="$(find state -maxdepth 1 -type d -name 'vm-*' -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n 1 | awk '{print $2}')"
|
VM_DIR="$(find state/vms -maxdepth 1 -mindepth 1 -type d -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n 1 | awk '{print $2}')"
|
||||||
if [[ -z "$VM_DIR" ]]; then
|
if [[ -z "$VM_DIR" ]]; then
|
||||||
log "no VM state directory found"
|
log "no VM state directory found"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue