~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/mcelog

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
#
3
 
### BEGIN INIT INFO
4
 
# Provides:          mcelog
5
 
# Required-Start:    $syslog $local_fs $remote_fs
6
 
# Required-Stop:     $remote_fs
7
 
# Should-Start:      
8
 
# Should-Stop:       
9
 
# Default-Start:     2 3 4 5
10
 
# Default-Stop:      0 1 6
11
 
# Short-Description: Machine Check Exceptions (MCE) collector & decoder
12
 
# Description:       Machine Check Exceptions are raised by the CPU whenever
13
 
#                    it encounters an hardware error. mcelog collects and
14
 
#                    decodes Machine Check Exceptions as they happen. 
15
 
### END INIT INFO
16
 
 
17
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
18
 
DAEMON=/usr/sbin/mcelog
19
 
NAME=mcelog
20
 
DESC="Machine Check Exceptions decoder"
21
 
TRIGGER=/sys/devices/system/machinecheck/machinecheck0/trigger
22
 
 
23
 
RUN_MODE=daemon
24
 
 
25
 
test -x $DAEMON || exit 0
26
 
 
27
 
if [ ! -r /dev/mcelog ]; then
28
 
    echo "/dev/mcelog not active"
29
 
    exit 0
30
 
fi
31
 
 
32
 
[ -r /etc/default/mcelog ] && . /etc/default/mcelog
33
 
 
34
 
. /lib/lsb/init-functions
35
 
 
36
 
set -e
37
 
 
38
 
# Trigger functions
39
 
start_trigger()
40
 
{
41
 
    if start-stop-daemon --stop --test --quiet --exec $DAEMON; then
42
 
        echo "WARNING: mcelog daemon running, not setting up MCE trigger"
43
 
        exit 1
44
 
    fi
45
 
 
46
 
    echo -n "Setting up Machine Check Exceptions trigger..."
47
 
    if [ -e $TRIGGER ]; then
48
 
        echo $DAEMON > $TRIGGER
49
 
    else
50
 
        echo " not supported on this machine."
51
 
        exit 0
52
 
    fi
53
 
    echo " done."
54
 
 
55
 
    echo -n "Running $DESC..."
56
 
    $DAEMON
57
 
    echo " done."
58
 
}
59
 
 
60
 
stop_trigger()
61
 
{
62
 
    echo -n "Clearing Machine Check Exceptions trigger..."
63
 
    if [ -e $TRIGGER ]; then
64
 
        echo "" > $TRIGGER
65
 
    else
66
 
        echo " not supported on this machine."
67
 
        exit 0
68
 
    fi
69
 
    echo " done."
70
 
}
71
 
 
72
 
trigger_status()
73
 
{
74
 
    if [ "$(cat $TRIGGER)" = $DAEMON ]; then
75
 
        echo "Machine Check Exceptions collected by mcelog."
76
 
        exit 0
77
 
    else
78
 
        if [ ! -e $TRIGGER ]; then
79
 
            echo "Machine Check Exceptions not collected by mcelog; trigger mode not supported."
80
 
        else
81
 
            echo "Machine Check Exceptions not collected by mcelog."
82
 
        fi
83
 
        exit 1
84
 
    fi
85
 
}
86
 
 
87
 
# Daemon functions
88
 
start_daemon()
89
 
{
90
 
    # Check & clear mcelog trigger
91
 
    if [ -e $TRIGGER ] && [ "$(cat $TRIGGER)" = $DAEMON ]; then
92
 
        echo "" > $TRIGGER
93
 
    fi
94
 
 
95
 
    echo -n "Starting $DESC: "
96
 
    start-stop-daemon --start --quiet --exec $DAEMON -- --daemon $DAEMON_OPTS
97
 
    echo "$NAME."
98
 
}
99
 
 
100
 
stop_daemon()
101
 
{
102
 
    echo -n "Stopping $DESC: "
103
 
    start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
104
 
    echo "$NAME."
105
 
}
106
 
 
107
 
restart_daemon()
108
 
{
109
 
    echo -n "Restarting $DESC: "
110
 
 
111
 
    # Check & clear mcelog trigger
112
 
    if [ -e $TRIGGER ] && [ "$(cat $TRIGGER)" = $DAEMON ]; then
113
 
        echo "" > $TRIGGER
114
 
    fi
115
 
 
116
 
    start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
117
 
    sleep 1
118
 
    start-stop-daemon --start --quiet --exec $DAEMON -- --daemon $DAEMON_OPTS
119
 
 
120
 
    echo "$NAME."
121
 
}
122
 
 
123
 
daemon_status()
124
 
{
125
 
    echo -n "$NAME is "
126
 
 
127
 
    if start-stop-daemon --stop --test --quiet --exec $DAEMON; then
128
 
        echo "running."
129
 
    else
130
 
        echo "not running."
131
 
        exit 1
132
 
    fi
133
 
}
134
 
 
135
 
 
136
 
case "$1" in
137
 
  start)
138
 
        if [ "$RUN_MODE" = "trigger" ]; then
139
 
            start_trigger
140
 
        else
141
 
            start_daemon
142
 
        fi
143
 
        ;;
144
 
  stop)
145
 
        if [ "$RUN_MODE" = "trigger" ]; then
146
 
            stop_trigger
147
 
        else
148
 
            stop_daemon
149
 
        fi
150
 
        ;;
151
 
  restart)
152
 
        if [ "$RUN_MODE" = "trigger" ]; then
153
 
            start_trigger
154
 
        else
155
 
            restart_daemon
156
 
        fi
157
 
        ;;
158
 
  force-reload)
159
 
        if [ "$RUN_MODE" = "trigger" ]; then
160
 
            [ -e $TRIGGER ] && [ "$(cat $TRIGGER)" = $DAEMON ] && $0 restart || exit 0
161
 
        else
162
 
            start-stop-daemon --stop --test --quiet --exec $DAEMON \
163
 
                && restart_daemon \
164
 
                || exit 0
165
 
        fi
166
 
        ;;
167
 
  status)
168
 
        if [ "$RUN_MODE" = "trigger" ]; then
169
 
            trigger_status
170
 
        else
171
 
            daemon_status
172
 
        fi
173
 
        ;;
174
 
  *)
175
 
        N=/etc/init.d/$NAME
176
 
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
177
 
        exit 1
178
 
        ;;
179
 
esac
180
 
 
181
 
exit 0