mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 21:40:01 +08:00
Fix slow shutdown issue
Fix slow shutdown issue
This commit is contained in:
commit
a7a68dbc80
@ -1,10 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -u
|
||||
|
||||
declare nmi
|
||||
# Functions
|
||||
|
||||
snore()
|
||||
{
|
||||
local IFS
|
||||
[[ -n "${_snore_fd:-}" ]] || exec {_snore_fd}<> <(:)
|
||||
read ${1:+-t "$1"} -u $_snore_fd || :
|
||||
}
|
||||
|
||||
function checkNMI {
|
||||
|
||||
local nmi
|
||||
nmi=$(awk '/NMI/ {for (i=2; i<=NF; i++) if ($i ~ /^[0-9]+$/) {sum+=$i}} END {print sum}' /proc/interrupts)
|
||||
|
||||
if [ "$nmi" != "" ] && [ "$nmi" -ne "0" ]; then
|
||||
@ -12,15 +20,28 @@ function checkNMI {
|
||||
echo "Received shutdown request through NMI.." > /dev/ttyS0
|
||||
|
||||
/usr/syno/sbin/synoshutdown -s > /dev/null
|
||||
exit 0
|
||||
exit
|
||||
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
finish() {
|
||||
|
||||
echo "Shutting down agent.." > /dev/ttyS0
|
||||
exit
|
||||
|
||||
}
|
||||
|
||||
trap finish SIGINT SIGTERM
|
||||
|
||||
# Setup serialport
|
||||
|
||||
chmod 666 /dev/ttyS0
|
||||
checkNMI
|
||||
|
||||
# Install packages
|
||||
|
||||
first_run=false
|
||||
|
||||
for filename in /usr/local/packages/*.spk; do
|
||||
@ -50,14 +71,17 @@ else
|
||||
|
||||
fi
|
||||
|
||||
# Display message in docker log output
|
||||
|
||||
echo "-------------------------------------------" > /dev/ttyS0
|
||||
echo " You can now login to DSM at port 5000 " > /dev/ttyS0
|
||||
echo "-------------------------------------------" > /dev/ttyS0
|
||||
|
||||
# Wait for NMI interrupt as a shutdown signal
|
||||
|
||||
while true; do
|
||||
|
||||
checkNMI
|
||||
sleep 2
|
||||
snore 2
|
||||
|
||||
done
|
||||
|
||||
|
@ -160,7 +160,7 @@ cp /agent/service.sh $LOC/agent.sh
|
||||
chmod +x $LOC/agent.sh
|
||||
|
||||
# Store agent version
|
||||
echo "2" > "$STORAGE"/"$BASE".agent
|
||||
echo "3" > "$STORAGE"/"$BASE".agent
|
||||
|
||||
echo "Install: Installing system partition..."
|
||||
|
||||
|
@ -12,7 +12,6 @@ _QEMU_SHUTDOWN_COUNTER=/run/qemu.counter
|
||||
rm -f "${_QEMU_PID}"
|
||||
rm -f "${_QEMU_SHUTDOWN_COUNTER}"
|
||||
|
||||
# Allows for troubleshooting signals sent to the process
|
||||
_trap(){
|
||||
func="$1" ; shift
|
||||
for sig ; do
|
||||
@ -20,6 +19,13 @@ _trap(){
|
||||
done
|
||||
}
|
||||
|
||||
snore()
|
||||
{
|
||||
local IFS
|
||||
[[ -n "${_snore_fd:-}" ]] || exec {_snore_fd}<> <(:)
|
||||
read ${1:+-t "$1"} -u $_snore_fd || :
|
||||
}
|
||||
|
||||
_graceful_shutdown(){
|
||||
|
||||
local QEMU_MONPORT="${QEMU_MONPORT:-7100}"
|
||||
|
@ -52,7 +52,7 @@ set -m
|
||||
)
|
||||
set +m
|
||||
|
||||
# Since we have to start the process with -m, we need to poll every intervall if it's still running
|
||||
# Since we started the QEMU process with -m, we need to poll if it's still running
|
||||
while [ -d "/proc/$(cat ${_QEMU_PID})" ]; do
|
||||
sleep 1
|
||||
snore 1
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user