feat: Show daemon log

* feat: Show daemon log
This commit is contained in:
Kroese 2023-12-28 17:58:07 +01:00 committed by GitHub
parent d09588b915
commit 973efa2d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 24 deletions

View File

@ -3,8 +3,8 @@ set -Eeuo pipefail
: ${VM_NET_DEV:='eth0'}
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
[ -f "/run/qemu.end" ] && echo "QEMU is shutting down.." && exit 1
[ ! -f "/run/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0
file="/run/dsm.url"
[ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1

View File

@ -14,6 +14,8 @@ if [[ "$GPU" == [Yy1]* ]] && [[ "$ARCH" == "amd64" ]]; then
DEF_OPTS="$DEF_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1"
fi
[[ "$CONSOLE" != [Yy]* ]] && DEF_OPTS="$DEF_OPTS -daemonize -D $QEMU_LOG"
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $EXTRA_OPTS $ARGUMENTS"
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')

View File

@ -19,13 +19,14 @@ cd /run
trap - ERR
if [[ "$CONSOLE" == [Yy]* ]]; then
exec qemu-system-x86_64 ${ARGS:+ $ARGS} && exit $?
exec qemu-system-x86_64 ${ARGS:+ $ARGS}
fi
[[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x
msg=$(qemu-system-x86_64 -daemonize ${ARGS:+ $ARGS})
msg=$(qemu-system-x86_64 ${ARGS:+ $ARGS})
{ set +x; } 2>/dev/null && terminal "$msg"
tail -fn +0 "$QEMU_LOG" 2>/dev/null &
cat "$QEMU_TERM" 2>/dev/null & wait $! || true
sleep 1 && finish 0

View File

@ -11,7 +11,8 @@ QEMU_TERM=""
QEMU_PORT=7100
QEMU_TIMEOUT=50
QEMU_PID="/run/qemu.pid"
QEMU_COUNT="/run/qemu.count"
QEMU_LOG="/run/qemu.log"
QEMU_END="/run/qemu.end"
if [[ "$KVM" == [Nn]* ]]; then
API_TIMEOUT=$(( API_TIMEOUT*2 ))
@ -19,7 +20,9 @@ if [[ "$KVM" == [Nn]* ]]; then
fi
rm -f "$QEMU_PID"
rm -f "$QEMU_COUNT"
rm -f "$QEMU_LOG"
rm -f "$QEMU_END"
touch "$QEMU_LOG"
_trap() {
func="$1" ; shift
@ -87,17 +90,18 @@ terminal() {
_graceful_shutdown() {
local cnt=0
local code=$?
local pid cnt response
local pid url response
set +e
if [ -f "$QEMU_COUNT" ]; then
echo && info "Ignored $1 signal, already shutting down..."
if [ -f "$QEMU_END" ]; then
echo && info "Received $1 signal while already shutting down..."
return
fi
echo 0 > "$QEMU_COUNT"
touch "$QEMU_END"
echo && info "Received $1 signal, sending shutdown command..."
if [ ! -f "$QEMU_PID" ]; then
@ -132,15 +136,12 @@ _graceful_shutdown() {
fi
while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do
while [ "$cnt" -lt "$QEMU_TIMEOUT" ]; do
! isAlive "$pid" && break
sleep 1
# Increase the counter
cnt=$(($(cat $QEMU_COUNT)+1))
echo $cnt > "$QEMU_COUNT"
cnt=$((cnt+1))
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)"
@ -149,14 +150,16 @@ _graceful_shutdown() {
done
if [ "$(cat $QEMU_COUNT)" -ge "$QEMU_TIMEOUT" ]; then
echo && error "Shutdown timeout reached!"
if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then
echo && error "Shutdown timeout reached, aborting..."
fi
finish "$code" && return "$code"
}
if [[ "$CONSOLE" != [Yy]* ]]; then
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
fi
MON_OPTS="\
-pidfile $QEMU_PID \

View File

@ -8,10 +8,11 @@ info () { printf "%b%s%b" "\E[1;34m \E[1;36m" "$1" "\E[0m\n" >&2; }
error () { printf "%b%s%b" "\E[1;31m " "ERROR: $1" "\E[0m\n" >&2; }
file="/run/dsm.url"
shutdown="/run/qemu.count"
shutdown="/run/qemu.end"
url="http://127.0.0.1:2210/read?command=10"
resp_err="Guest returned an invalid response:"
curl_err="Failed to connect to guest: curl error"
jq_err="Failed to parse response from guest: jq error"
while [ ! -f "$file" ]
@ -29,7 +30,7 @@ do
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
[ -f "$shutdown" ] && exit 1
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
(( rc != 0 )) && error "$curl_err $rc" && continue
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue

View File

@ -38,8 +38,9 @@ STORAGE="/storage"
# Cleanup files
rm -f /run/dsm.url
rm -f /run/qemu.log
rm -f /run/qemu.pid
rm -f /run/qemu.count
rm -f /run/qemu.end
# Cleanup dirs

View File

@ -47,6 +47,7 @@ done
# Configure serial ports
SERIAL_OPTS="\
-serial none \
-chardev pty,id=charserial0 \
-device isa-serial,chardev=charserial0,id=serial0 \
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \