Sync
This commit is contained in:
parent
54da2f29e6
commit
d8669c0b8a
1 changed files with 5 additions and 14 deletions
19
run/power.sh
19
run/power.sh
|
@ -19,18 +19,8 @@ _trap(){
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
snore()
|
|
||||||
{
|
|
||||||
local IFS
|
|
||||||
[[ -n "${_snore_fd:-}" ]] || exec {_snore_fd}<> <(:)
|
|
||||||
read ${1:+-t "$1"} -u $_snore_fd || :
|
|
||||||
}
|
|
||||||
|
|
||||||
_graceful_shutdown(){
|
_graceful_shutdown(){
|
||||||
|
|
||||||
local QEMU_MONPORT="${QEMU_MONPORT:-7100}"
|
|
||||||
local QEMU_POWERDOWN_TIMEOUT="${QEMU_POWERDOWN_TIMEOUT:-8}"
|
|
||||||
|
|
||||||
[ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return
|
[ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
@ -40,7 +30,7 @@ _graceful_shutdown(){
|
||||||
echo 0 > "${_QEMU_SHUTDOWN_COUNTER}"
|
echo 0 > "${_QEMU_SHUTDOWN_COUNTER}"
|
||||||
|
|
||||||
# Send the shutdown (system_powerdown) command to the QMP monitor
|
# Send the shutdown (system_powerdown) command to the QMP monitor
|
||||||
echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}">/dev/null
|
echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null
|
||||||
|
|
||||||
while [ "$(cat ${_QEMU_SHUTDOWN_COUNTER})" -lt "${QEMU_POWERDOWN_TIMEOUT}" ]; do
|
while [ "$(cat ${_QEMU_SHUTDOWN_COUNTER})" -lt "${QEMU_POWERDOWN_TIMEOUT}" ]; do
|
||||||
|
|
||||||
|
@ -48,21 +38,22 @@ _graceful_shutdown(){
|
||||||
echo $(($(cat ${_QEMU_SHUTDOWN_COUNTER})+1)) > ${_QEMU_SHUTDOWN_COUNTER}
|
echo $(($(cat ${_QEMU_SHUTDOWN_COUNTER})+1)) > ${_QEMU_SHUTDOWN_COUNTER}
|
||||||
|
|
||||||
# Try to connect to qemu
|
# Try to connect to qemu
|
||||||
if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT:-7100}">/dev/null; then
|
if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null; then
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
echo "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})"
|
echo "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Quitting..."
|
echo "Quitting..."
|
||||||
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT:-7100}">/dev/null || true
|
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null || true
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
|
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
|
||||||
|
|
||||||
KVM_MON_OPTS="-monitor telnet:localhost:${QEMU_MONPORT:-7100},server,nowait,nodelay"
|
KVM_MON_OPTS="-monitor telnet:localhost:${QEMU_MONPORT},server,nowait,nodelay"
|
||||||
|
|
Loading…
Reference in a new issue