summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorSimon Spöhel <simon@spoehel.ch>2023-08-23 13:39:17 +0000
committerSimon Spöhel <simon@spoehel.ch>2023-08-24 14:42:33 +0000
commit1acf6afd66c2d7e9a8a5bff42fd1484187d58426 (patch)
treee1d024adff12e371b5695b50a27955dfdffda23c /libexec
parentbasic cnt rm support. (diff)
downloadcompute-tools-1acf6afd66c2d7e9a8a5bff42fd1484187d58426.tar.xz
compute-tools-1acf6afd66c2d7e9a8a5bff42fd1484187d58426.zip
Basic unifid start.
Diffstat (limited to 'libexec')
-rwxr-xr-xlibexec/container/build1
-rwxr-xr-xlibexec/container/start105
2 files changed, 99 insertions, 7 deletions
diff --git a/libexec/container/build b/libexec/container/build
index efb42f3..5927308 100755
--- a/libexec/container/build
+++ b/libexec/container/build
@@ -267,7 +267,6 @@ sed -e "s|@CNT_AUTO@|${CNT_AUTO}|g" \
-e "s|@BIND_RO@|${BIND_RO}|g" \
-e "s|@BOOT@|yes|g" \
-e "s|@CAPABILITY@|${CAPABILITY}|g" \
- -e "s|@DIRECTORY@|${MACHINES}/${NAME}|g" \
-e "s|@DROP_CAPABILITY@|${DROP_CAPABILITY}|g" \
-e "s|@LINK_JOURNAL@|no|g" \
-e "s|@MACHINE@|${NAME}|g" \
diff --git a/libexec/container/start b/libexec/container/start
index 1f22325..2287bd1 100755
--- a/libexec/container/start
+++ b/libexec/container/start
@@ -27,6 +27,7 @@ COMMAND="$(basename ${0})"
CONFIG="/etc/${SOFTWARE}/config"
HOOKS="/etc/${SOFTWARE}/hooks"
MACHINES="/var/lib/machines"
+VMS="/srv/container/vms"
START="false"
SYSTEMCTL="true"
@@ -128,9 +129,9 @@ case "${NAME}" in
;;
esac
-if [ ! -e "${MACHINES}/${NAME}" ]
+if [ ! -e "${MACHINES}/${NAME}" ] && [ ! -e "${VMS}/${NAME}" ]
then
- echo "'${NAME}': no such container" >&2
+ echo "'${NAME}': no such vm or container" >&2
exit 1
fi
@@ -175,7 +176,13 @@ then
fi
HOST_ARCHITECTURE="$(dpkg --print-architecture)"
-MACHINE_ARCHITECTURE="$(chroot ${MACHINES}/${NAME} dpkg --print-architecture)"
+# FIXME: MACHINE_ARCHITECTURE in config?
+case "BOOT_METHOD" in
+ systemd-nspawn)
+ MACHINE_ARCHITECTURE="$(chroot ${MACHINES}/${NAME} dpkg --print-architecture)"
+ ;;
+esac
+
case "${HOST_ARCHITECTURE}" in
amd64)
@@ -377,6 +384,57 @@ then
;;
esac
+ BOOT_METHOD="$(awk -Fboot-method= '/^boot-method=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ MEMORY="-m $(awk -Fvm.memory= '/^vm.memory=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ FIRMWARE="$(awk -Fvm.firmware= '/^vm.firmware=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ CPU="-cpu $(awk -Fvm.cpu= '/^vm.cpu=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ DISPLAY="-display $(awk -Fvm.display= '/^vm.display=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ SERIAL="-serial $(awk -Fvm.serial= '/^vm.serial=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ MONITOR="-mon $(awk -Fvm.monitor= '/^vm.monitor=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+
+ DRIVES="$(awk -Fvm.drive= '/^vm.drive=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ case "${DRIVES}" in
+ "")
+ ;;
+
+ *)
+ OLDIFS="${IFS}"
+ IFS='
+'
+ for DRIVE_ITEM in ${DRIVES}
+ do
+ DRIVE="${DRIVE} -drive ${DRIVE_ITEM}"
+ done
+ IFS="${OLDIFS}"
+ ;;
+ esac
+
+ NETDEVS="$(awk -Fvm.netdev= '/^vm.netdev=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ case "${NETDEVS}" in
+ "")
+ ;;
+
+ *)
+ OLDIFS="${IFS}"
+ IFS='
+'
+ for NETDEV_ITEM in ${NETDEVS}
+ do
+ NETDEV="${NETDEV} -netdev ${NETDEV_ITEM}"
+ done
+ IFS="${OLDIFS}"
+ ;;
+ esac
+
+ DIRECTORY="$(awk -Fdirectory= '/^directory=/ { print $2 }' ${CONFIG}/${NAME}.conf || echo ${MACHINES}/${NAMES})"
+ DIRECTORY="--directory ${DIRECTORY}"
+
+ RAW_OPTIONS="$(awk -Fraw-options= '/^raw-options=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
+ # FIXME empty
+
+ MACHINE="-name ${NAME}"
+
+
NETWORK_BRIDGES="$(awk -Fcnt.network-bridge= '/^cnt.network-bridge=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
case "${NETWORK_BRIDGES}" in
@@ -519,11 +577,21 @@ EOF
TASKS_MAX="TasksMax=${TASKS_MAX}"
SET_PROPERTY="true"
fi
+
+ DIRECTORY="$(awk -Fdirectory= '/^directory=/ { print $2 }' ${CONFIG}/${NAME}.conf || echo ${MACHINES}/${NAMES})"
fi
case "${SYSTEMCTL}" in
true)
- systemctl start ${PROGRAM}@${NAME}.service
+ case "${BOOT_METHOD}" in
+ qemu)
+ systemctl start qemu@${NAME}.service
+ ;;
+
+ systemd-nspawn)
+ systemctl start ${PROGRAM}@${NAME}.service
+ ;;
+ esac
# Post hooks
for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
@@ -540,6 +608,7 @@ esac
case "${START}" in
true)
+
case "${SET_PROPERTY}" in
true)
systemctl --runtime set-property ${NAME} ${BLOCK_IO_DEVICE_WEIGHT} ${BLOCK_IO_READ_BANDWIDTH} ${BLOCK_IO_WEIGHT} ${BLOCK_IO_WRITE_BANDWIDTH} ${CPU_QUOTA} ${CPU_SHARES} ${MEMORY_LIMIT} ${TASKS_MAX}
@@ -552,14 +621,38 @@ case "${START}" in
case "${VERBOSE}" in
true)
- echo -n "Starting container ${NAME}..."
+ echo -n "Starting ${NAME} with ${BOOT_METHOD}..."
;;
esac
mkdir -p "/var/lib/${SOFTWARE}/state"
echo "start" > "/var/lib/${SOFTWARE}/state/${NAME}.run"
- ${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BIND_RO} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER}
+ case "${BOOT_METHOD}" in
+ qemu)
+ case "${FIRMWARE}" in
+ efi)
+ BIOS="-bios ${DIRECTORY}/firmware.fd"
+ ;;
+ esac
+
+ qemu-system-x86_64 \
+ -machine accel=kvm \
+ ${CPU} \
+ ${DISPLAY} \
+ ${MEMORY} \
+ ${MACHINE} \
+ ${BIOS} \
+ ${SERIAL} \
+ ${DRIVE} \
+ ${NETDEV} \
+ ${RAW_OPTIONS}
+ ;;
+
+ systemd-nspawn)
+ ${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BIND_RO} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER}
+ ;;
+ esac
case "${VERBOSE}" in
true)