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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: mcelog
# Required-Start: $syslog $local_fs $remote_fs
# Required-Stop: $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Machine Check Exceptions (MCE) collector & decoder
# Description: Machine Check Exceptions are raised by the CPU whenever
# it encounters an hardware error. mcelog collects and
# decodes Machine Check Exceptions as they happen.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/mcelog
NAME=mcelog
DESC="Machine Check Exceptions decoder"
TRIGGER=/sys/devices/system/machinecheck/machinecheck0/trigger
RUN_MODE=daemon
test -x $DAEMON || exit 0
if [ ! -r /dev/mcelog ]; then
echo "/dev/mcelog not active"
exit 0
fi
[ -r /etc/default/mcelog ] && . /etc/default/mcelog
. /lib/lsb/init-functions
set -e
# Trigger functions
start_trigger()
{
if start-stop-daemon --stop --test --quiet --exec $DAEMON; then
echo "WARNING: mcelog daemon running, not setting up MCE trigger"
exit 1
fi
echo -n "Setting up Machine Check Exceptions trigger..."
if [ -e $TRIGGER ] && $DAEMON --is-cpu-supported ; then
echo $DAEMON > $TRIGGER
else
echo " not supported on this machine."
exit 0
fi
echo " done."
echo -n "Running $DESC..."
$DAEMON
echo " done."
}
stop_trigger()
{
echo -n "Clearing Machine Check Exceptions trigger..."
if [ -e $TRIGGER ]; then
echo "" > $TRIGGER
else
echo " not supported on this machine."
exit 0
fi
echo " done."
}
trigger_status()
{
if [ "$(cat $TRIGGER)" = $DAEMON ]; then
echo "Machine Check Exceptions collected by mcelog."
exit 0
else
if [ ! -e $TRIGGER ]; then
echo "Machine Check Exceptions not collected by mcelog; trigger mode not supported."
else
echo "Machine Check Exceptions not collected by mcelog."
fi
exit 1
fi
}
# Daemon functions
start_daemon()
{
# Check & clear mcelog trigger
if [ -e $TRIGGER ] && [ "$(cat $TRIGGER)" = $DAEMON ]; then
echo "" > $TRIGGER
fi
if $DAEMON --is-cpu-supported ; then
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --exec $DAEMON -- --daemon $DAEMON_OPTS
echo "$NAME."
fi
}
stop_daemon()
{
echo -n "Stopping $DESC: "
start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
echo "$NAME."
}
restart_daemon()
{
echo -n "Restarting $DESC: "
# Check & clear mcelog trigger
if [ -e $TRIGGER ] && [ "$(cat $TRIGGER)" = $DAEMON ]; then
echo "" > $TRIGGER
fi
start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
if $DAEMON --is-cpu-supported ; then
sleep 1
start-stop-daemon --start --quiet --exec $DAEMON -- --daemon $DAEMON_OPTS
fi
echo "$NAME."
}
daemon_status()
{
echo -n "$NAME is "
if start-stop-daemon --stop --test --quiet --exec $DAEMON; then
echo "running."
else
echo "not running."
exit 1
fi
}
case "$1" in
start)
if [ "$RUN_MODE" = "trigger" ]; then
start_trigger
else
start_daemon
fi
;;
stop)
if [ "$RUN_MODE" = "trigger" ]; then
stop_trigger
else
stop_daemon
fi
;;
restart)
if [ "$RUN_MODE" = "trigger" ]; then
start_trigger
else
restart_daemon
fi
;;
force-reload)
if [ "$RUN_MODE" = "trigger" ]; then
[ -e $TRIGGER ] && [ "$(cat $TRIGGER)" = $DAEMON ] && $0 restart || exit 0
else
start-stop-daemon --stop --test --quiet --exec $DAEMON \
&& restart_daemon \
|| exit 0
fi
;;
status)
if [ "$RUN_MODE" = "trigger" ]; then
trigger_status
else
daemon_status
fi
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
|