]> git.pld-linux.org Git - packages/watchdog.git/blob - watchdog.init
1737007529c8086a09ba4876ddd3aa568b68ec78
[packages/watchdog.git] / watchdog.init
1 #! /bin/sh
2 #
3 # chkconfig:            12345 89 89
4 # description:          A software watchdog
5 # rc file author:       Marc Merlin <marcsoft@merlins.org>
6 #                       Henning P. Schmiedehausen <hps@tanstaafl.de>
7 # Note that even though chkconfig says that this should be run at runlevel 1,
8 # RH by default won't do this, so the RPM applies an ugly patch to
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
21 WATCHDOG_OOM_ADJUST="-1000"
22 VERBOSE="no"
23 if [ -f /etc/sysconfig/watchdog ]; then
24         . /etc/sysconfig/watchdog
25 fi
26
27 adjust_oom() {
28         if [ -e /var/run/watchdog.pid ]; then
29                 for pid in $(cat /var/run/watchdog.pid); do
30                         if [ -w "/proc/$pid/oom_score_adj" ]; then
31                                 echo "$WATCHDOG_OOM_ADJUST" > "/proc/$pid/oom_score_adj" 2> /dev/null || :
32                         fi
33                 done
34         fi
35 }
36
37 start() {
38         if [ ! -f /var/lock/subsys/watchdog ]; then
39                 msg_starting watchdog
40                 busy
41                 if [ -z "$WATCHDOG_MODULES" ]; then
42                         # preload software module
43                         modprobe -s softdog > /dev/null 2>&1
44                 else
45                         for module in $WATCHDOG_MODULES; do
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
50                                 modprobe -s $module > /dev/null 2>&1
51                         done
52                 fi
53
54                 if [ "${VERBOSE}" = "yes" ]; then
55                         daemon watchdog -v
56                 else
57                         daemon watchdog
58                 fi
59                 RETVAL=$?
60                 adjust_oom
61                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/watchdog
62         else
63                 msg_already_running watchdog
64         fi
65 }
66
67 stop() {
68         if [ -f /var/lock/subsys/watchdog ]; then
69                 msg_stopping watchdog
70                 killproc watchdog
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
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
88                 fi
89
90                 rm -f /var/lock/subsys/watchdog >/dev/null 2>&1
91         else
92                 msg_not_running watchdog
93         fi
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
111         ;;
112   stop)
113         stop
114         ;;
115   restart|force-reload)
116         stop
117         start
118         ;;
119   try-restart)
120         condrestart 0
121         ;;
122   force-reload)
123         condrestart 7
124         ;;
125   status)
126         status watchdog
127         exit $?
128         ;;
129   *)
130         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
131         exit 3
132 esac
133
134 exit $RETVAL
This page took 0.062943 seconds and 4 git commands to generate.