]>
Commit | Line | Data |
---|---|---|
f92c540a PG |
1 | #! /bin/sh |
2 | # | |
520aa0f2 | 3 | # chkconfig: 12345 89 89 |
10754e53 | 4 | # description: A software watchdog |
5 | # rc file author: Marc Merlin <marcsoft@merlins.org> | |
6 | # Henning P. Schmiedehausen <hps@tanstaafl.de> | |
f92c540a | 7 | # Note that even though chkconfig says that this should be run at runlevel 1, |
5c26365e | 8 | # RH by default won't do this, so the RPM applies an ugly patch to |
f92c540a PG |
9 | # /etc/rc.d/init.d/single so that if you go from RL 3 to RL 1, watchdog is |
10 | # restarted anyway (if it's not, it can cause the kernel to reboot your machine | |
11 | # depending on whether your kernel was compiled with CONFIG_WATCHDOG_NOWAYOUT) | |
12 | # | |
13 | # I have filed a bug with RH about this, and I hope they will change their | |
14 | # single script to allow for other scripts to be run in RL 1. | |
15 | ||
16 | # Source function library. | |
17 | . /etc/rc.d/init.d/functions | |
18 | ||
19 | [ -x /usr/sbin/watchdog -a -e /etc/watchdog.conf ] || exit 0 | |
20 | ||
d661441e | 21 | WATCHDOG_OOM_ADJUST="-1000" |
f92c540a PG |
22 | VERBOSE="no" |
23 | if [ -f /etc/sysconfig/watchdog ]; then | |
6dadfa72 | 24 | . /etc/sysconfig/watchdog |
f92c540a PG |
25 | fi |
26 | ||
c5d05d0e AM |
27 | adjust_oom() { |
28 | if [ -e /var/run/watchdog.pid ]; then | |
29 | for pid in $(cat /var/run/watchdog.pid); do | |
d661441e AM |
30 | if [ -w "/proc/$pid/oom_score_adj" ]; then |
31 | echo "$WATCHDOG_OOM_ADJUST" > "/proc/$pid/oom_score_adj" 2> /dev/null || : | |
c5d05d0e AM |
32 | fi |
33 | done | |
34 | fi | |
35 | } | |
36 | ||
616a6b39 | 37 | start() { |
f92c540a PG |
38 | if [ ! -f /var/lock/subsys/watchdog ]; then |
39 | msg_starting watchdog | |
98f25415 | 40 | busy |
443176d9 | 41 | if [ -z "$WATCHDOG_MODULES" ]; then |
6dadfa72 | 42 | # preload software module |
43 | modprobe -s softdog > /dev/null 2>&1 | |
443176d9 | 44 | else |
6dadfa72 | 45 | for module in $WATCHDOG_MODULES; do |
6825535d AM |
46 | if [ "$module" = "ipmi_watchdog" ]; then |
47 | modprobe -s ipmi_si > /dev/null 2>&1 | |
48 | modprobe -s ipmi_devintf > /dev/null 2>&1 | |
49 | fi | |
6dadfa72 | 50 | modprobe -s $module > /dev/null 2>&1 |
51 | done | |
443176d9 | 52 | fi |
f92c540a | 53 | |
be64c9c5 | 54 | if [ "${VERBOSE}" = "yes" ]; then |
f92c540a PG |
55 | daemon watchdog -v |
56 | else | |
57 | daemon watchdog | |
98f25415 | 58 | fi |
f92c540a | 59 | RETVAL=$? |
c5d05d0e | 60 | adjust_oom |
f92c540a PG |
61 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/watchdog |
62 | else | |
f1a61ffc | 63 | msg_already_running watchdog |
f92c540a | 64 | fi |
616a6b39 JB |
65 | } |
66 | ||
67 | stop() { | |
f92c540a PG |
68 | if [ -f /var/lock/subsys/watchdog ]; then |
69 | msg_stopping watchdog | |
70 | killproc watchdog | |
98f25415 | 71 | # If you compiled your kernel with CONFIG_WATCHDOG_NOWAYOUT, you may |
72 | # not want to remove the module as sometimes /etc/rc.d/init.d/halt | |
73 | # will hang on umounting some remote nfs partition or for some other | |
74 | # reason, and you may then want the kernel to reboot by itself. | |
75 | # However, this means that if you stop watchdog, your system has one | |
76 | # minute to reboot cleanly, or it will be rebooted by the kernel. If | |
77 | # this behavior isn't what you want, just uncomment the following | |
78 | # lines | |
80c4d550 AM |
79 | if [ "$WATCHDOG_UNLOAD" = "yes" ]; then |
80 | if [ -z "$WATCHDOG_MODULES" ]; then | |
81 | # try to unload software module | |
82 | rmmod -s softdog > /dev/null 2>&1 | |
83 | else | |
84 | for module in $WATCHDOG_MODULES; do | |
85 | rmmod -s $module > /dev/null 2>&1 | |
86 | done | |
87 | fi | |
6dadfa72 | 88 | fi |
443176d9 | 89 | |
f92c540a PG |
90 | rm -f /var/lock/subsys/watchdog >/dev/null 2>&1 |
91 | else | |
f1a61ffc | 92 | msg_not_running watchdog |
f92c540a | 93 | fi |
616a6b39 JB |
94 | } |
95 | ||
96 | condrestart() { | |
97 | if [ -f /var/lock/subsys/watchdog ]; then | |
98 | stop | |
99 | start | |
100 | else | |
101 | msg_not_running watchdog | |
102 | RETVAL=$1 | |
103 | fi | |
104 | } | |
105 | ||
106 | RETVAL=0 | |
107 | # See how we were called. | |
108 | case "$1" in | |
109 | start) | |
110 | start | |
f92c540a | 111 | ;; |
616a6b39 JB |
112 | stop) |
113 | stop | |
f92c540a | 114 | ;; |
10754e53 | 115 | restart|force-reload) |
616a6b39 JB |
116 | stop |
117 | start | |
118 | ;; | |
119 | try-restart) | |
120 | condrestart 0 | |
121 | ;; | |
122 | force-reload) | |
123 | condrestart 7 | |
124 | ;; | |
125 | status) | |
126 | status watchdog | |
98f25415 | 127 | exit $? |
128 | ;; | |
f92c540a | 129 | *) |
616a6b39 | 130 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" |
10754e53 | 131 | exit 3 |
f92c540a PG |
132 | esac |
133 | ||
98f25415 | 134 | exit $RETVAL |