Loading agent/agent.sh +28 −4 Original line number Diff line number Diff line #!/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 Loading @@ -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 Loading Loading @@ -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 run/install.sh +1 −1 Original line number Diff line number Diff line Loading @@ -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..." Loading run/power.sh +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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}" Loading run/run.sh +2 −2 Original line number Diff line number Diff line Loading @@ -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
agent/agent.sh +28 −4 Original line number Diff line number Diff line #!/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 Loading @@ -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 Loading Loading @@ -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
run/install.sh +1 −1 Original line number Diff line number Diff line Loading @@ -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..." Loading
run/power.sh +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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}" Loading
run/run.sh +2 −2 Original line number Diff line number Diff line Loading @@ -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