add panic init script

This commit is contained in:
Calin Crisan 2018-10-15 23:45:38 +03:00
parent fda8329f20
commit 0c5ce8c19f
3 changed files with 39 additions and 6 deletions

View File

@ -6,6 +6,8 @@ board_name=$(cat /etc/board)
test -n "$os_debug" || source /etc/init.d/conf
source /etc/init.d/panic
msg_begin() {
echo -n " * $1: "
}
@ -22,8 +24,3 @@ msg_background() {
test -n "$1" && echo $1 || echo "pending"
}
panic_action() {
logger -t panic -s "rebooting"
/sbin/reboot
}

View File

@ -0,0 +1,28 @@
#!/bin/bash
_PANIC_COUNTER_FILE="/var/lib/panic_counter"
_PANIC_REBOOT_DELAY_FACTOR=10
_PANIC_REBOOT_DELAY_MAX=3600 # reboot at least once an hour in case of panic
panic_action() {
# read counter from file
panic_counter=$(cat ${_PANIC_COUNTER_FILE} 2>/dev/null || echo 0)
# write increased counter back to file
echo $((panic_counter + 1)) > ${_PANIC_COUNTER_FILE}
delay=$((_PANIC_REBOOT_DELAY_FACTOR * panic_counter))
if [ "${delay}" -gt "${_PANIC_REBOOT_DELAY_MAX}" ]; then
delay=${_PANIC_REBOOT_DELAY_MAX}
fi
if [ "${delay}" -gt 0 ]; then
logger -t panic -s "rebooting in ${delay} seconds (caused by $1)"
sleep ${delay}
fi
logger -t panic -s "rebooting (caused by $1)"
/sbin/reboot
}

View File

@ -1,7 +1,15 @@
#!/bin/bash
# carry on with the script in case of error
set +e
# write buffers to disk
/bin/sync
(sleep 10 && /usr/bin/killall -STOP watchdog) &
# allow the shutdown script 20 seconds to shut down,
# after which we stop feeding the watchdog
(sleep 20 && /usr/bin/killall -STOP watchdog) &
# actual reboot command
/bin/busybox reboot