introduce graceful shutdown

This commit is contained in:
iceBear67
2026-07-13 17:07:50 +08:00
parent 1b79e7677b
commit c041cb97cd
2 changed files with 15 additions and 3 deletions
+8 -1
View File
@@ -1,7 +1,14 @@
#!/bin/sh
set -euo pipefail
exec /usr/bin/cloud-hypervisor \
_stop() {
ch-remote shutdown-vmm
}
trap _stop EXIT TERM
/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 \
+7 -2
View File
@@ -3,13 +3,18 @@
set -u
echo "fetching latest version of cloud-hypervisor"
DOWNLOAD_URL=$(curl https://api.github.com/repos/cloud-hypervisor/cloud-hypervisor/releases | jq -r '.[0].assets.[] | select( .name == "cloud-hypervisor-static") | .browser_download_url')
RESPONSE=$(curl https://api.github.com/repos/cloud-hypervisor/cloud-hypervisor/releases)
HYPERVISOR_URL=$(echo $RESPONSE | jq -r '.[0].assets.[] | select( .name == "cloud-hypervisor-static") | .browser_download_url')
CH_REMOTE_URL=$(echo $RESPONSE | jq -r '.[0].assets.[] | select( .name == "ch-remote-static") | .browser_download_url' )
if [ $? -ne 0 ]; then
echo "FAILED TO FETCH DOWNLOAD LINK OF CLOUD-HYPERVISOR-STATIC"
exit -1
fi
curl -sLo /usr/bin/cloud-hypervisor $DOWNLOAD_URL && chmod +x /usr/bin/cloud-hypervisor && cloud-hypervisor --help
curl -sLo /usr/bin/cloud-hypervisor "$HYPERVISOR_URL" && chmod +x /usr/bin/cloud-hypervisor && cloud-hypervisor --help >/dev/null 2>&1
curl -sLo /usr/bin/ch-remote "$CH_REMOTE_URL" && chmod +x /usr/bin/ch-remote && ch-remote --help >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "FAILED TO DOWNLOAD CLOUD-HYPERVISOR or CLOUD-HYPERVISOR IS NOT EXECUTABLE. (wrong arch?)"