mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
feat: Show daemon log
* feat: Show daemon log
This commit is contained in:
parent
d09588b915
commit
973efa2d27
@ -3,8 +3,8 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
: ${VM_NET_DEV:='eth0'}
|
: ${VM_NET_DEV:='eth0'}
|
||||||
|
|
||||||
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
|
[ -f "/run/qemu.end" ] && echo "QEMU is shutting down.." && exit 1
|
||||||
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
|
[ ! -f "/run/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0
|
||||||
|
|
||||||
file="/run/dsm.url"
|
file="/run/dsm.url"
|
||||||
[ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
|
[ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
|
||||||
|
@ -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"
|
DEF_OPTS="$DEF_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1"
|
||||||
fi
|
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="$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 ' ')
|
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
||||||
|
|
||||||
|
@ -19,13 +19,14 @@ cd /run
|
|||||||
trap - ERR
|
trap - ERR
|
||||||
|
|
||||||
if [[ "$CONSOLE" == [Yy]* ]]; then
|
if [[ "$CONSOLE" == [Yy]* ]]; then
|
||||||
exec qemu-system-x86_64 ${ARGS:+ $ARGS} && exit $?
|
exec qemu-system-x86_64 ${ARGS:+ $ARGS}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x
|
[[ "$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"
|
{ set +x; } 2>/dev/null && terminal "$msg"
|
||||||
|
tail -fn +0 "$QEMU_LOG" 2>/dev/null &
|
||||||
cat "$QEMU_TERM" 2>/dev/null & wait $! || true
|
cat "$QEMU_TERM" 2>/dev/null & wait $! || true
|
||||||
|
|
||||||
sleep 1 && finish 0
|
sleep 1 && finish 0
|
||||||
|
31
src/power.sh
31
src/power.sh
@ -11,7 +11,8 @@ QEMU_TERM=""
|
|||||||
QEMU_PORT=7100
|
QEMU_PORT=7100
|
||||||
QEMU_TIMEOUT=50
|
QEMU_TIMEOUT=50
|
||||||
QEMU_PID="/run/qemu.pid"
|
QEMU_PID="/run/qemu.pid"
|
||||||
QEMU_COUNT="/run/qemu.count"
|
QEMU_LOG="/run/qemu.log"
|
||||||
|
QEMU_END="/run/qemu.end"
|
||||||
|
|
||||||
if [[ "$KVM" == [Nn]* ]]; then
|
if [[ "$KVM" == [Nn]* ]]; then
|
||||||
API_TIMEOUT=$(( API_TIMEOUT*2 ))
|
API_TIMEOUT=$(( API_TIMEOUT*2 ))
|
||||||
@ -19,7 +20,9 @@ if [[ "$KVM" == [Nn]* ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$QEMU_PID"
|
rm -f "$QEMU_PID"
|
||||||
rm -f "$QEMU_COUNT"
|
rm -f "$QEMU_LOG"
|
||||||
|
rm -f "$QEMU_END"
|
||||||
|
touch "$QEMU_LOG"
|
||||||
|
|
||||||
_trap() {
|
_trap() {
|
||||||
func="$1" ; shift
|
func="$1" ; shift
|
||||||
@ -87,17 +90,18 @@ terminal() {
|
|||||||
|
|
||||||
_graceful_shutdown() {
|
_graceful_shutdown() {
|
||||||
|
|
||||||
|
local cnt=0
|
||||||
local code=$?
|
local code=$?
|
||||||
local pid cnt response
|
local pid url response
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
if [ -f "$QEMU_COUNT" ]; then
|
if [ -f "$QEMU_END" ]; then
|
||||||
echo && info "Ignored $1 signal, already shutting down..."
|
echo && info "Received $1 signal while already shutting down..."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo 0 > "$QEMU_COUNT"
|
touch "$QEMU_END"
|
||||||
echo && info "Received $1 signal, sending shutdown command..."
|
echo && info "Received $1 signal, sending shutdown command..."
|
||||||
|
|
||||||
if [ ! -f "$QEMU_PID" ]; then
|
if [ ! -f "$QEMU_PID" ]; then
|
||||||
@ -132,15 +136,12 @@ _graceful_shutdown() {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do
|
while [ "$cnt" -lt "$QEMU_TIMEOUT" ]; do
|
||||||
|
|
||||||
! isAlive "$pid" && break
|
! isAlive "$pid" && break
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
cnt=$((cnt+1))
|
||||||
# Increase the counter
|
|
||||||
cnt=$(($(cat $QEMU_COUNT)+1))
|
|
||||||
echo $cnt > "$QEMU_COUNT"
|
|
||||||
|
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)"
|
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)"
|
||||||
|
|
||||||
@ -149,14 +150,16 @@ _graceful_shutdown() {
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$(cat $QEMU_COUNT)" -ge "$QEMU_TIMEOUT" ]; then
|
if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then
|
||||||
echo && error "Shutdown timeout reached!"
|
echo && error "Shutdown timeout reached, aborting..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
finish "$code" && return "$code"
|
finish "$code" && return "$code"
|
||||||
}
|
}
|
||||||
|
|
||||||
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
|
if [[ "$CONSOLE" != [Yy]* ]]; then
|
||||||
|
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
|
||||||
|
fi
|
||||||
|
|
||||||
MON_OPTS="\
|
MON_OPTS="\
|
||||||
-pidfile $QEMU_PID \
|
-pidfile $QEMU_PID \
|
||||||
|
@ -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; }
|
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||||
|
|
||||||
file="/run/dsm.url"
|
file="/run/dsm.url"
|
||||||
shutdown="/run/qemu.count"
|
shutdown="/run/qemu.end"
|
||||||
url="http://127.0.0.1:2210/read?command=10"
|
url="http://127.0.0.1:2210/read?command=10"
|
||||||
|
|
||||||
resp_err="Guest returned an invalid response:"
|
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"
|
jq_err="Failed to parse response from guest: jq error"
|
||||||
|
|
||||||
while [ ! -f "$file" ]
|
while [ ! -f "$file" ]
|
||||||
@ -29,7 +30,7 @@ do
|
|||||||
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
|
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
|
||||||
|
|
||||||
[ -f "$shutdown" ] && exit 1
|
[ -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=$?; } || :
|
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
|
@ -38,8 +38,9 @@ STORAGE="/storage"
|
|||||||
# Cleanup files
|
# Cleanup files
|
||||||
|
|
||||||
rm -f /run/dsm.url
|
rm -f /run/dsm.url
|
||||||
|
rm -f /run/qemu.log
|
||||||
rm -f /run/qemu.pid
|
rm -f /run/qemu.pid
|
||||||
rm -f /run/qemu.count
|
rm -f /run/qemu.end
|
||||||
|
|
||||||
# Cleanup dirs
|
# Cleanup dirs
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ pKill() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fKill () {
|
fKill() {
|
||||||
local name=$1
|
local name=$1
|
||||||
|
|
||||||
{ pkill -f "$name" || true; } 2>/dev/null
|
{ pkill -f "$name" || true; } 2>/dev/null
|
||||||
@ -83,7 +84,7 @@ fKill () {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getCountry () {
|
getCountry() {
|
||||||
local url=$1
|
local url=$1
|
||||||
local query=$2
|
local query=$2
|
||||||
local rc json result
|
local rc json result
|
||||||
@ -102,7 +103,7 @@ getCountry () {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
setCountry () {
|
setCountry() {
|
||||||
|
|
||||||
[[ "${TZ,,}" == "asia/harbin" ]] && COUNTRY="CN"
|
[[ "${TZ,,}" == "asia/harbin" ]] && COUNTRY="CN"
|
||||||
[[ "${TZ,,}" == "asia/beijing" ]] && COUNTRY="CN"
|
[[ "${TZ,,}" == "asia/beijing" ]] && COUNTRY="CN"
|
||||||
|
@ -47,6 +47,7 @@ done
|
|||||||
# Configure serial ports
|
# Configure serial ports
|
||||||
|
|
||||||
SERIAL_OPTS="\
|
SERIAL_OPTS="\
|
||||||
|
-serial none \
|
||||||
-chardev pty,id=charserial0 \
|
-chardev pty,id=charserial0 \
|
||||||
-device isa-serial,chardev=charserial0,id=serial0 \
|
-device isa-serial,chardev=charserial0,id=serial0 \
|
||||||
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
|
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user