Shutdown services gracefully

This commit is contained in:
Héctor Molinero Fernández 2021-11-02 19:23:18 +01:00
parent 55587ba1f8
commit 88a1b868a8
4 changed files with 22 additions and 4 deletions

View File

@ -50,12 +50,14 @@ RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \ && apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
net-tools \ net-tools \
netcat-openbsd \
procps \ procps \
python3 \ python3 \
qemu-kvm \ qemu-kvm \
qemu-system-x86 \ qemu-system-x86 \
qemu-utils \ qemu-utils \
runit \ runit \
tini \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*


# Environment # Environment
@ -90,4 +92,4 @@ COPY --chown=root:root ./scripts/bin/ /usr/local/bin/
RUN find /usr/local/bin/ -type d -not -perm 0755 -exec chmod 0755 '{}' ';' RUN find /usr/local/bin/ -type d -not -perm 0755 -exec chmod 0755 '{}' ';'
RUN find /usr/local/bin/ -type f -not -perm 0755 -exec chmod 0755 '{}' ';' RUN find /usr/local/bin/ -type f -not -perm 0755 -exec chmod 0755 '{}' ';'


ENTRYPOINT ["/usr/local/bin/container-init"] ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/container-init"]

View File

@ -7,5 +7,16 @@ if [ ! -f /var/lib/qemu/images/reactos.img ]; then
qemu-img create -f qcow2 /var/lib/qemu/images/reactos.img "${VM_DISK_SIZE:?}" qemu-img create -f qcow2 /var/lib/qemu/images/reactos.img "${VM_DISK_SIZE:?}"
fi fi


# Start all services stop() {
exec runsvdir -P /etc/service/ for s in "${SVDIR:?}"/*; do sv force-stop "${s:?}" >/dev/null 2>&1; done
kill -HUP "${RUNSVDIRPID:?}"; wait "${RUNSVDIRPID:?}"
}
trap stop EXIT TERM INT HUP

if [ "$#" -gt 0 ] || [ -t 0 ] || [ -t 1 ]; then
runsvdir -P "${SVDIR:?}" >/dev/null 2>&1 & RUNSVDIRPID=$!
"$@"
else
runsvdir -P "${SVDIR:?}" & RUNSVDIRPID=$!
wait "${RUNSVDIRPID:?}"
fi

5
scripts/service/qemu/control/t Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh

set -eu

printf '%s\n' 'system_powerdown' | nc -U /run/qemu-monitor

View File

@ -4,7 +4,7 @@ set -eu


set -- set --
set -- "$@" -smp "${VM_CPU:?}" -m "${VM_RAM:?}" set -- "$@" -smp "${VM_CPU:?}" -m "${VM_RAM:?}"
set -- "$@" -serial stdio -device VGA -display vnc=:0 set -- "$@" -serial stdio -monitor unix:/run/qemu-monitor,server,nowait -device VGA -display vnc=:0
set -- "$@" -drive file=/var/lib/qemu/images/reactos.img,index=0,media=disk,format=qcow2 set -- "$@" -drive file=/var/lib/qemu/images/reactos.img,index=0,media=disk,format=qcow2
set -- "$@" -drive file=/var/lib/qemu/iso/reactos.iso,index=2,media=cdrom,format=raw set -- "$@" -drive file=/var/lib/qemu/iso/reactos.iso,index=2,media=cdrom,format=raw
set -- "$@" -boot order="${VM_BOOT_ORDER:?}",menu=off set -- "$@" -boot order="${VM_BOOT_ORDER:?}",menu=off