mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-28 13:46:32 +00:00
add panic init script
This commit is contained in:
parent
fda8329f20
commit
0c5ce8c19f
@ -6,6 +6,8 @@ board_name=$(cat /etc/board)
|
|||||||
|
|
||||||
test -n "$os_debug" || source /etc/init.d/conf
|
test -n "$os_debug" || source /etc/init.d/conf
|
||||||
|
|
||||||
|
source /etc/init.d/panic
|
||||||
|
|
||||||
msg_begin() {
|
msg_begin() {
|
||||||
echo -n " * $1: "
|
echo -n " * $1: "
|
||||||
}
|
}
|
||||||
@ -22,8 +24,3 @@ msg_background() {
|
|||||||
test -n "$1" && echo $1 || echo "pending"
|
test -n "$1" && echo $1 || echo "pending"
|
||||||
}
|
}
|
||||||
|
|
||||||
panic_action() {
|
|
||||||
logger -t panic -s "rebooting"
|
|
||||||
/sbin/reboot
|
|
||||||
}
|
|
||||||
|
|
||||||
|
28
board/common/overlay/etc/init.d/panic
Executable file
28
board/common/overlay/etc/init.d/panic
Executable 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
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# carry on with the script in case of error
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
|
# write buffers to disk
|
||||||
/bin/sync
|
/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
|
/bin/busybox reboot
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user