#!/bin/sh set -eu API_SOCKET="/hy.socks" # Build the --net argument, omitting empty fields so cloud-hypervisor can pick # sensible defaults (auto-created tap / generated MAC) instead of getting # "tap=,mac=". NET_INTERFACE="${NET_INTERFACE:-}" NET_MAC="${NET_MAC:-}" NET_ARG="tap=${NET_INTERFACE}" if [ -n "$NET_MAC" ]; then NET_ARG="${NET_ARG},mac=${NET_MAC}" fi /usr/bin/cloud-hypervisor \ --kernel /boot/vmlinuz-virt --initramfs /boot/initramfs-virt \ --disk path=/image/vm.raw,image_type=raw \ --disk path=/image/data.raw,direct=on,image_type=raw \ --api-socket "$API_SOCKET" \ --cmdline "root=/dev/vda rootfstype=ext4 modules=ext4a rw console=hvc0" \ --cpus boot=${CPU_COUNT:-4} \ --memory size=${MEMORY:-4G},shared=on \ --net "$NET_ARG" \ "$@" & CH_PID=$! _stop() { echo "STOPPING!!" ch-remote --api-socket "$API_SOCKET" power-button wait $CH_PID } trap _stop TERM INT wait $CH_PID