This commit is contained in:
kristof 2025-06-15 19:20:32 +02:00
parent 7b859d274c
commit 63f4f77366
2 changed files with 16 additions and 10 deletions

View File

@ -148,7 +148,7 @@ cleanup_network() {
# Check if bridge still has any TAP interfaces
if [ -n "$bridge_name" ] && ip link show "$bridge_name" &>/dev/null; then
local tap_count=$(ip link show master "$bridge_name" 2>/dev/null | grep -c "tap-" || echo "0")
local tap_count=$(ip link show master "$bridge_name" 2>/dev/null | grep "tap-" | wc -l)
if [ "$tap_count" -eq 0 ]; then
info "Bridge '$bridge_name' has no remaining TAP interfaces"
# Note: We don't automatically remove the bridge as it might be used by other services

View File

@ -563,8 +563,8 @@ log "Launching Cloud Hypervisor..."
log "Starting Cloud Hypervisor with command:"
log "cloud-hypervisor --api-socket $VM_SOCKET --memory size=${MEMORY_MB}M --cpus boot=$CPU_CORES --firmware $FIRMWARE_PATH --disk path=$VM_IMAGE_PATH path=$CLOUD_INIT_PATH,readonly=on --net tap=$TAP_NAME,mac=$VM_MAC --serial file=$VM_LOG_FILE --console off --event-monitor path=${VM_LOG_FILE}.events"
# Try with API socket first, fall back without it if needed
cloud-hypervisor \
--api-socket "$VM_SOCKET" \
--memory "size=${MEMORY_MB}M" \
--cpus "boot=$CPU_CORES" \
--firmware "$FIRMWARE_PATH" \
@ -594,18 +594,24 @@ log "TAP interface: $TAP_NAME"
log "Bridge interface: $BRIDGE_NAME"
log "VM MAC address: $VM_MAC"
# Wait for the socket to be created (Cloud Hypervisor needs time to initialize)
log "Waiting for VM API socket to be created..."
socket_wait_count=0
while [ ! -S "$VM_SOCKET" ] && [ $socket_wait_count -lt 15 ]; do
# Wait for VM to initialize and check if it's running properly
log "Waiting for VM to initialize..."
init_wait_count=0
while [ $init_wait_count -lt 10 ]; do
sleep 1
socket_wait_count=$((socket_wait_count + 1))
if [ $((socket_wait_count % 5)) -eq 0 ]; then
info "Still waiting for API socket... ($socket_wait_count/15 seconds)"
init_wait_count=$((init_wait_count + 1))
# Check if VM process is still running
if ! kill -0 "$VM_PID" 2>/dev/null; then
error "VM process died during initialization. Check log: $VM_LOG_FILE"
fi
if [ $((init_wait_count % 3)) -eq 0 ]; then
info "VM initializing... ($init_wait_count/10 seconds)"
fi
done
test_file_exists "$VM_SOCKET" "VM API socket creation"
log "✓ VM initialization completed"
# Save VM information for management
log "Saving VM configuration..."