-
Notifications
You must be signed in to change notification settings - Fork 47
/
S13watchdog
executable file
·94 lines (76 loc) · 2.19 KB
/
S13watchdog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
SYS_CONF="/etc/watchdog.conf"
BOOT_CONF="/boot/watchdog.conf"
USER_CONF="/data/etc/watchdog.conf"
PROG="/sbin/watchdog"
DEVICE="/dev/watchdog"
TIMEOUT=5
THERMAL_ZONE=
MAX_TEMP=
TEMP_INTERVAL=10
SYS_CHECK="/usr/libexec/watchdog-check"
USER_CHECK="/data/etc/watchdog-check"
CHECK_LOG="/var/log/watchdog-check.log"
CHECK_INTERVAL=10
test -s ${SYS_CONF} && source ${SYS_CONF}
test -s ${USER_CONF} && source ${USER_CONF}
test -s ${BOOT_CONF} && source ${BOOT_CONF}
test -n "${OS_VERSION}" || source /etc/init.d/base
function start_watchdog() {
if ! [[ -x ${PROG} && -e ${DEVICE} ]]; then
return
fi
msg_begin "Starting watchdog"
${PROG} -t ${TIMEOUT} ${DEVICE}
test $? == 0 && msg_done || msg_fail
}
function start_watch_temp() {
if [[ -z "${THERMAL_ZONE}" ]] || [[ -z "${MAX_TEMP}" ]]; then
return
fi
while true; do
sleep ${TEMP_INTERVAL}
temp=$(cat /sys/class/thermal/${THERMAL_ZONE}/temp)
temp=$((temp / 1000))
if [[ "${temp}" -gt ${MAX_TEMP} ]]; then
panic action watchdog "temperature too high: ${temp} > ${MAX_TEMP}"
fi
done
}
function start_watch_check() {
if ! [[ -x "${SYS_CHECK}" ]] && ! [[ -x "${USER_CHECK}" ]]; then
return
fi
while true; do
sleep ${CHECK_INTERVAL}
if [[ -x "${SYS_CHECK}" ]] && ! "${SYS_CHECK}" &>>${CHECK_LOG}; then
panic action watchdog "system check failed"
elif [[ -x "${USER_CHECK}" ]] && ! "${USER_CHECK}" &>>${CHECK_LOG}; then
panic action watchdog "user check failed"
fi
done
}
function stop() {
msg_begin "Stopping watchdog"
killall -q $(basename ${PROG})
ps | grep "service watchdog" | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
ps | grep "S13watchdog" | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
msg_done
}
case "$1" in
start)
start_watchdog
start_watch_temp &
start_watch_check &
;;
stop)
true
;;
reallystop)
stop
;;
*)
echo $"Usage: $0 {start|reallystop}"
exit 1
esac
exit $?