~ubuntu-branches/ubuntu/maverick/ipmitool/maverick

« back to all changes in this revision

Viewing changes to contrib/ipmi.init.redhat

  • Committer: Bazaar Package Importer
  • Author(s): Petter Reinholdtsen
  • Date: 2005-04-07 01:18:44 UTC
  • Revision ID: james.westby@ubuntu.com-20050407011844-a1b206z5iefiu5vi
Tags: upstream-1.8.1
ImportĀ upstreamĀ versionĀ 1.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# chkconfig: 2345 11 60
 
4
# description: start, stop, or query ipmi system monitoring tools
 
5
# config: /etc/sysconfig/ipmi
 
6
#
 
7
# For Redhat, Fedora, or similar systems.  Handles both 2.4 and 2.6
 
8
# configurations.  Requires an /etc/sysconfig/ipmi file to function,
 
9
# see below.
 
10
#
 
11
# Phil Hollenback
 
12
# philiph@pobox.com
 
13
 
 
14
# Source function library.
 
15
. /etc/init.d/functions
 
16
 
 
17
# Exit silently if we don't have a sysconfig file,
 
18
# and read IPMI setting from it to determine whether or
 
19
# not to continue.
 
20
# The only current setting is ipmi={YES|NO}, whether or not
 
21
# to enable IPMI.
 
22
[ -f /etc/sysconfig/ipmi ] || exit 0
 
23
. /etc/sysconfig/ipmi
 
24
[ "${IPMI}" = "yes" ] || exit 0
 
25
 
 
26
RETVAL=0
 
27
 
 
28
start() {
 
29
        echo -n $"Starting ipmi: "
 
30
 
 
31
        # If ipmidev isn't listed in /proc/devices, try
 
32
        # loading the modules.
 
33
        if ! grep -q ipmidev /proc/devices
 
34
        then
 
35
            /sbin/modprobe ipmi_msghandler || RETVAL=1
 
36
            /sbin/modprobe ipmi_devintf || RETVAL=1
 
37
            # Try loading new driver module, fall back to old
 
38
            # module if that fails.
 
39
            if ! /sbin/modprobe ipmi_si >/dev/null 2>&1
 
40
            then
 
41
                /sbin/modprobe ipmi_kcs_drv || RETVAL=1
 
42
            fi
 
43
        fi
 
44
 
 
45
 
 
46
        # If ipmidev still isn't listed in /proc/devices after we load
 
47
        # modules, this just isn't going to work.  Set RETVAL to mark
 
48
        # this failure.
 
49
        grep -q ipmidev /proc/devices || RETVAL=1
 
50
 
 
51
        # remove old device file always
 
52
        # in case ipmi gets assigned new dynamic major number from kernel
 
53
        if [ -c /dev/ipmi0 ]; then
 
54
            rm -f /dev/ipmi0
 
55
        fi
 
56
 
 
57
        # Check if the device file exists and create if not.
 
58
        if [ ! -c /dev/ipmi0 ] && [ $RETVAL -eq 0 ]
 
59
        then
 
60
            major=$(awk '/ ipmidev$/{print $1}' /proc/devices)
 
61
            /bin/mknod -m 0600 /dev/ipmi0 c $major 0 || RETVAL=1
 
62
        fi
 
63
 
 
64
        if [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ipmi ; then
 
65
                echo_success
 
66
                echo
 
67
        else
 
68
                echo_failure
 
69
                echo
 
70
        fi
 
71
}
 
72
 
 
73
stop() {
 
74
        echo -n $"Shutting down ipmi: "
 
75
 
 
76
        # Stop doesn't actually do anything because we currently don't
 
77
        # unload ipmi modules on stop.  That might change in the future
 
78
        # if we decide unloading the ipmi modules is safe.
 
79
        RETVAL=0
 
80
 
 
81
        if [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ipmi ; then
 
82
                echo_success
 
83
                echo
 
84
        else
 
85
                echo_failure
 
86
                echo
 
87
        fi
 
88
}
 
89
 
 
90
dostatus() {
 
91
        # Extract cpu temperatures from ipmitool output.
 
92
 
 
93
        # Abort if we don't have the ipmitool program.
 
94
        if ! /usr/bin/ipmitool -V >/dev/null
 
95
        then
 
96
            echo "/usr/bin/ipmitool not found!" >&2
 
97
            exit 1
 
98
        fi
 
99
 
 
100
        # Abort if ipmi isn't loaded.
 
101
        if ! grep -q ipmidev /proc/devices
 
102
        then
 
103
            echo "ipmi not listed in /proc/devices!" >&2
 
104
            exit 1
 
105
        fi
 
106
 
 
107
        # Check if we are running on a v1.0 IPMI system, and
 
108
        # change our processor search string appropriately.
 
109
        if /usr/bin/ipmitool -I open bmc info | \
 
110
                grep -q "IPMI Version.*1.0"
 
111
        then
 
112
            IpmiVersion="1.0"
 
113
        fi
 
114
 
 
115
        # Determine # of running processors
 
116
        NumProcs=$(grep -c processor /proc/cpuinfo)
 
117
        if [ $NumProcs -eq 0 ]
 
118
        then
 
119
            echo "Can't determine number of processors!" >&2
 
120
            exit 1
 
121
        fi
 
122
 
 
123
        # Now build the query string.  Concatenate it into
 
124
        # one string because that's more efficient on 2.4 systems.
 
125
        Count=1
 
126
        TempString=""
 
127
        while [ $Count -le $NumProcs ]
 
128
        do
 
129
            if [ x$IpmiVersion  = x"1.0" ]
 
130
            then
 
131
                TempString="$TempString CPU\ $Count"
 
132
            else
 
133
                TempString="$TempString Processor$Count\ Temp"
 
134
            fi
 
135
            Count=$((Count + 1))
 
136
        done
 
137
        # building TempString like this and eval'ing it is ugly, but
 
138
        # it's the only way I could make the quoting work.  Sorry.
 
139
        TempString="/usr/bin/ipmitool -I open sensor get $TempString"
 
140
        eval $TempString | awk -v "c=$Count" '
 
141
BEGIN {
 
142
   n = 1
 
143
}
 
144
/Sensor Reading/ {
 
145
   printf "CPU%s Temp: %s\n",n,$4
 
146
   n++
 
147
}
 
148
END {
 
149
   if ( n != c) {
 
150
        printf "Error: found %s CPUs, but got temps for %s\n",--c,--n >"/dev/stderr"
 
151
        exit 1
 
152
   }
 
153
   exit 0
 
154
}'
 
155
        RETVAL=$((RETVAL + $?))
 
156
        return $RETVAL
 
157
}
 
158
 
 
159
restart() {
 
160
        stop
 
161
        start
 
162
        RETVAL=$?
 
163
}
 
164
 
 
165
condrestart() {
 
166
        [ -e /var/lock/subsys/ipmi ] && restart || :
 
167
}
 
168
 
 
169
remove () {
 
170
        # Actually remove the drivers.  Don't do during stop in case
 
171
        # this causes system to become unstable (a la lm_sensors)
 
172
        if /sbin/lsmod | awk '{print $1}' | grep -q ipmi_
 
173
        then
 
174
            # Try removing both 2.4 and 2.6 modules.
 
175
            /sbin/rmmod ipmi_si 2>/dev/null
 
176
            /sbin/rmmod ipmi_kcs_drv 2>/dev/null
 
177
            /sbin/rmmod ipmi_devintf
 
178
            /sbin/rmmod ipmi_msghandler
 
179
        else
 
180
            echo "No ipmi modules loaded!" >&2
 
181
            RETVAL=1
 
182
            return $RETVAL
 
183
        fi
 
184
 
 
185
        # Wait a sec to give modules time to unload.
 
186
        sleep 1
 
187
 
 
188
        # Check if we failed to remove any modules, and complain if so.
 
189
        if /sbin/lsmod | awk '{print $1}' | grep -q ipmi_
 
190
        then
 
191
            echo "ipmi modules still loaded!" >&2
 
192
            RETVAL=1
 
193
            return $RETVAL
 
194
        fi
 
195
}
 
196
 
 
197
# See how we were called.
 
198
case "$1" in
 
199
  start)
 
200
        start
 
201
        ;;
 
202
  stop)
 
203
        stop
 
204
        ;;
 
205
  status)
 
206
        dostatus
 
207
        ;;
 
208
  restart|reload)
 
209
        restart
 
210
        ;;
 
211
  condrestart)
 
212
        condrestart
 
213
        ;;
 
214
  remove)
 
215
        remove
 
216
        ;;
 
217
  *)
 
218
        echo "Usage: ipmi {start|stop|status|restart|condrestart|remove}"
 
219
        exit 1
 
220
esac
 
221
 
 
222
exit $RETVAL