forked from Mellanox/mlx-OpenIPMI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipmi.init
584 lines (519 loc) · 13.7 KB
/
ipmi.init
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#!/bin/sh
#############################################################################
#
# ipmi: OpenIPMI Driver init script
#
# Authors: Matt Domsch <[email protected]>
# Chris Poblete <[email protected]>
#
# chkconfig: - 13 87
# description: OpenIPMI Driver init script
#
### BEGIN INIT INFO
# Provides: ipmidrv
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start:
# Default-Stop:
# Short-Description: OpenIPMI Driver init script
# Description: OpenIPMI Driver init script
### END INIT INFO
#
# Status return code bits
# no bits set = no errors
# bit 0 set = minimum modules aren't loaded
# bit 1 set = requested feature module isn't loaded
# bit 2 set = /dev/ipmi0 (or /dev/imb if using that instead) doesn't exist
# bit 3 set = /dev/watchdog doesn't exist
# bit 4 set = lockfile doesn't exist
# bit 5 set = modules are loaded even when asked to be unloaded
#
#############################################################################
# for log_success_msg and friends
if [ -r /lib/lsb/init-functions ]; then
# LSB, SLES, ...
. /lib/lsb/init-functions
elif [ -r /etc/init.d/functions ]; then
# Red Hat / VMware
. /etc/init.d/functions
my_log_message()
{
ACTION=$1
shift
case "$ACTION" in
success)
echo -n $*
success 0
echo
;;
failure)
echo -n $*
failure 1
echo
;;
warning)
echo -n $*
warning 0
echo
;;
*)
;;
esac
}
log_success_msg()
{
my_log_message success "$*"
}
log_failure_msg()
{
my_log_message failure "$*"
}
log_warning_msg()
{
my_log_message warning "$*"
}
fi
CONFIGFILE=/etc/sysconfig/ipmi
# source config info
[ -r ${CONFIGFILE} ] && . ${CONFIGFILE}
#############################################################################
# GLOBALS
#############################################################################
MODULE_NAME="ipmi"
INTF_NUM=0
IPMI_SMB_MODULE_NAME="ipmi_smb"
IPMI_SI_MODULE_NAME="ipmi_si"
kernel=`uname -r | cut -d. -f1-2`
if [ "${kernel}" = "2.4" ]; then
IPMI_SMB_MODULE_NAME="ipmi_smb_intf"
IPMI_SI_MODULE_NAME="ipmi_si_drv"
fi
MODULES_INTERFACES=""
[ "${DEV_IPMI}" = "yes" ] && MODULES_INTERFACES="${MODULES_INTERFACES} ipmi_devintf"
[ "${IPMI_IMB}" = "yes" ] && MODULES_INTERFACES="${MODULES_INTERFACES} ipmi_imb"
MODULES_FEATURES=""
[ "${IPMI_WATCHDOG}" = "yes" ] && MODULES_FEATURES="${MODULES_FEATURES} ipmi_watchdog"
[ "${IPMI_POWEROFF}" = "yes" ] && MODULES_FEATURES="${MODULES_FEATURES} ipmi_poweroff"
MODULES_HW=""
[ "${IPMI_SI}" = "yes" ] && MODULES_HW="${MODULES_HW} ${IPMI_SI_MODULE_NAME}"
[ "${IPMI_SMB}" = "yes" ] && MODULES_HW="${MODULES_HW} ${IPMI_SMB_MODULE_NAME}"
MODULES_BASE="ipmi_msghandler"
MODULES="${MODULES_INTERFACES} ${MODULES_FEATURES} ${MODULES_HW} ${MODULES_BASE}"
RETVAL=0
LOCKFILE=/var/lock/subsys/ipmi
DEV_IPMI_TIMEOUT=15
UDEV_EXISTS=0
if [ -e /sbin/udev -o -e /sbin/udevd ]; then
UDEV_EXISTS=1
fi
#############################################################################
# NOTES:
# * /dev/ipmi0 is unconditionally deleted here on ipmi_devintf unload,
# because SLES9 and RHEL4 kernels don't send a message for udev to delete
# it for us.
#
#############################################################################
modules_loaded_verbose()
{
OnePlusLoaded=0
OnePlusUnloaded=0
for m in $@; do
if /sbin/lsmod | grep $m >/dev/null 2>&1 ; then
echo "$m module loaded."
OnePlusLoaded=1
else
echo "$m module not loaded."
OnePlusUnloaded=1
fi
done
}
modules_loaded()
{
OnePlusLoaded=0
OnePlusUnloaded=0
for m in $@; do
if /sbin/lsmod | grep $m >/dev/null 2>&1 ; then
OnePlusLoaded=1
else
OnePlusUnloaded=1
fi
done
}
device_node_exists ()
{
if [ -e "$1" ]; then
echo "$1 exists."
return 1
fi
echo "$1 does not exist."
return 0
}
minimum_modules_loaded()
{
rc_base=1
rc_hw=1
modules_loaded_verbose "${MODULES_BASE}"
[ ${OnePlusLoaded} -eq 0 ] && rc_base=0
modules_loaded_verbose "${MODULES_HW}"
[ ${OnePlusLoaded} -eq 0 ] && rc_hw=0
return $((rc_base && rc_hw))
}
#############################################################################
load_si()
{
if [ "${IPMI_SI}" = "yes" ]; then
modprobe ${IPMI_SI_MODULE_NAME} > /dev/null 2>&1
modules_loaded ${IPMI_SI_MODULE_NAME}
[ ${OnePlusLoaded} -ne 1 ] && RETVAL=$((RETVAL | 1))
fi
}
load_smb()
{
if [ "${IPMI_SMB}" = "yes" ]; then
modprobe ${IPMI_SMB_MODULE_NAME} > /dev/null 2>&1
modules_loaded ${IPMI_SMB_MODULE_NAME}
[ ${OnePlusLoaded} -ne 1 ] && RETVAL=$((RETVAL | 1))
fi
}
load_hw_modules()
{
load_si
load_smb
}
start_watchdog_common()
{
modules_loaded ipmi_watchdog
if [ ${OnePlusUnloaded} -eq 0 ]; then
log_success_msg &&
return
fi
if [ -e /dev/watchdog ]; then
log_failure_msg "/dev/watchdog already exists "
RETVAL=$((RETVAL | 8))
return
fi
load_hw_modules
modprobe ipmi_watchdog ${IPMI_WATCHDOG_OPTIONS} > /dev/null 2>&1
modules_loaded ipmi_watchdog
[ ${OnePlusUnloaded} -ne 0 ] &&
RETVAL=$((RETVAL | 2)) &&
log_failure_msg &&
return
if [ ${UDEV_EXISTS} -eq 0 -a ! -e /dev/watchdog ]; then
mknod -m 0600 /dev/watchdog c 10 130
[ $? -ne 0 ] &&
RETVAL=$((RETVAL | 8)) &&
log_failure_msg &&
return
fi
log_success_msg
}
start_watchdog_quiet()
{
[ "${IPMI_WATCHDOG}" != "yes" ] &&
return
echo -n $"Starting ipmi_watchdog driver: "
start_watchdog_common
}
start_watchdog()
{
echo -n $"Starting ipmi_watchdog driver: "
[ "${IPMI_WATCHDOG}" != "yes" ] &&
RETVAL=$((RETVAL | 2)) &&
log_failure_msg "not configured" &&
return
start_watchdog_common
}
stop_watchdog()
{
echo -n $"Stopping ipmi_watchdog driver: "
modprobe -q -r ipmi_watchdog > /dev/null 2>&1
modules_loaded ipmi_watchdog
if [ ${OnePlusLoaded} -ne 0 ]; then
RETVAL=$((RETVAL | 32))
log_failure_msg
else
if [ "${IPMI_WATCHDOG}" = "yes" ]; then
[ ${UDEV_EXISTS} -eq 0 ] && rm -f /dev/watchdog
fi
log_success_msg
fi
}
stop_watchdog_quiet()
{
modprobe -q -r ipmi_watchdog > /dev/null 2>&1
modules_loaded ipmi_watchdog
if [ ${OnePlusLoaded} -ne 0 ]; then
RETVAL=$((RETVAL | 32))
else
if [ "${IPMI_WATCHDOG}" = "yes" ]; then
[ ${UDEV_EXISTS} -eq 0 ] && rm -f /dev/watchdog
fi
fi
}
start_powercontrol_common()
{
local poweroff_opts=""
load_hw_modules
if [ "${IPMI_POWERCYCLE}" = "yes" ]; then
modinfo ipmi_poweroff 2>/dev/null | grep poweroff_control > /dev/null 2>&1 && \
poweroff_opts="poweroff_control=2"
modinfo ipmi_poweroff 2>/dev/null | grep poweroff_powercycle > /dev/null 2>&1 && \
poweroff_opts="poweroff_powercycle=1"
fi
modprobe ipmi_poweroff "${poweroff_opts}" > /dev/null 2>&1
modules_loaded ipmi_poweroff
[ ${OnePlusUnloaded} -ne 0 ] &&
RETVAL=$((RETVAL | 2)) &&
log_failure_msg &&
return
log_success_msg
}
start_powercontrol_quiet()
{
[ "${IPMI_POWEROFF}" != "yes" ] &&
return
echo -n $"Starting ipmi_poweroff driver: "
start_powercontrol_common
}
start_powercontrol()
{
echo -n $"Starting ipmi_poweroff driver: "
[ "${IPMI_POWEROFF}" != "yes" ] &&
RETVAL=$((RETVAL | 2)) &&
log_failure_msg "not configured" &&
return
start_powercontrol_common
}
stop_powercontrol()
{
echo -n $"Stopping ipmi_poweroff driver: "
modprobe -q -r ipmi_poweroff > /dev/null 2>&1
modules_loaded ipmi_poweroff
if [ ${OnePlusLoaded} -ne 0 ]; then
RETVAL=$((RETVAL | 32))
log_failure_msg
else
log_success_msg
fi
}
stop_powercontrol_quiet()
{
modprobe -q -r ipmi_poweroff > /dev/null 2>&1
modules_loaded ipmi_poweroff
[ ${OnePlusLoaded} -ne 0 ] && RETVAL=$((RETVAL | 32))
}
#############################################################################
unload_all_ipmi_modules()
{
stop_watchdog_quiet
stop_powercontrol_quiet
for m in ${MODULES}; do
modprobe -q -r ${m} > /dev/null 2>&1
done
# delete interface node ONLY if ipmi_devintf is unloaded
[ `lsmod | grep -c "ipmi_devintf"` -eq 0 ] &&
rm -f "/dev/ipmi${INTF_NUM}"
}
unload_ipmi_modules_leave_features()
{
for m in ${MODULES_INTERFACES}; do
modprobe -q -r ${m} > /dev/null 2>&1
done
# delete interface node ONLY if ipmi_devintf is unloaded
[ `lsmod | grep -c "ipmi_devintf"` -eq 0 ] &&
rm -f "/dev/ipmi${INTF_NUM}"
lsmod | egrep -q "ipmi_(poweroff|watchdog)" > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
stop_watchdog_quiet
stop_powercontrol_quiet
for m in ${MODULES}; do
modprobe -q -r ${m} > /dev/null 2>&1
done
fi
}
#############################################################################
load_ipmi_modules ()
{
local locdelay
modprobe ipmi_msghandler > /dev/null 2>&1
modules_loaded ipmi_msghandler
[ ${OnePlusLoaded} -ne 1 ] && unload_all_ipmi_modules && RETVAL=$((RETVAL | 1)) && return
load_hw_modules
[ $((RETVAL & 1)) -eq 1 ] && unload_all_ipmi_modules && RETVAL=$((RETVAL | 1)) && return
if [ "${DEV_IPMI}" = "yes" ]; then
modprobe ipmi_devintf > /dev/null 2>&1
modules_loaded ipmi_devintf
RETVAL=$((RETVAL & ~2))
[ ${OnePlusLoaded} -eq 0 ] && RETVAL=$((RETVAL | 2))
if [ ${OnePlusLoaded} -eq 1 ]; then
if [ ${UDEV_EXISTS} -eq 0 ]; then
DEVMAJOR=`cat /proc/devices | awk '/ipmidev/{print $1}'`
rm -f /dev/ipmi${INTF_NUM}
mknod -m 0600 /dev/ipmi${INTF_NUM} c ${DEVMAJOR} 0 || RETVAL=$((RETVAL | 4))
fi
# udev can take several seconds to create /dev/ipmi0,
# but it happens asynchronously, so delay here
locdelay=${DEV_IPMI_TIMEOUT}
while [ ! -e /dev/ipmi${INTF_NUM} -a ${locdelay} -gt 0 ]; do
locdelay=$((locdelay - 1))
sleep 1
done
fi
fi
if [ "${IPMI_IMB}" = "yes" ]; then
modprobe ipmi_imb > /dev/null 2>&1
modules_loaded ipmi_imb
RETVAL=$((RETVAL & ~2))
[ ${OnePlusLoaded} -eq 0 ] && RETVAL=$((RETVAL | 2))
if [ ${OnePlusLoaded} -eq 1 ]; then
DEVMAJOR=`cat /proc/devices | awk '/imb/{print $1}'`
rm -f /dev/imb
mknod -m 0600 /dev/imb c ${DEVMAJOR} 0 || RETVAL=$((RETVAL | 4))
fi
fi
# Per Corey Minyard, essentially no one uses ipmi_radisys
# and we don't want to encourage its further use
# so it won't be handled here.
return
}
#############################################################################
start()
{
echo -n "Starting ${MODULE_NAME} drivers: "
load_ipmi_modules
if [ ${RETVAL} -eq 0 ]; then
touch ${LOCKFILE} && log_success_msg
else
if [ $((RETVAL & 1)) -eq 1 ]; then
log_failure_msg
else
touch ${LOCKFILE} && log_warning_msg
fi
fi
start_watchdog_quiet
start_powercontrol_quiet
}
#############################################################################
stop()
{
echo -n "Stopping ${MODULE_NAME} drivers: "
unload_ipmi_modules_leave_features
modules_loaded ${MODULES_INTERFACES}
if [ ${OnePlusLoaded} -ne 0 ]; then
RETVAL=$((RETVAL | 32))
log_failure_msg "may be in use"
else
rm -f ${LOCKFILE}
log_success_msg
fi
}
stop_all()
{
echo -n $"Stopping all ${MODULE_NAME} drivers: "
unload_all_ipmi_modules
modules_loaded ${MODULES}
if [ ${OnePlusLoaded} -ne 0 ]; then
RETVAL=$((RETVAL | 32))
log_failure_msg "may be in use"
else
rm -f ${LOCKFILE}
log_success_msg
fi
}
#############################################################################
restart()
{
stop_all
RETVAL=0
start
}
#############################################################################
status_all()
{
minimum_modules_loaded
[ $? -eq 0 ] && RETVAL=$((RETVAL | 1))
modules_loaded_verbose ${MODULES_FEATURES} ${MODULES_INTERFACES}
[ ${OnePlusUnloaded} -ne 0 ] && RETVAL=$((RETVAL | 2))
if [ "${DEV_IPMI}" = "yes" ]; then
device_node_exists /dev/ipmi${INTF_NUM}
[ $? -eq 0 ] && RETVAL=$((RETVAL | 4))
fi
if [ "${IPMI_IMB}" = "yes" ]; then
device_node_exists /dev/imb
[ $? -eq 0 ] && RETVAL=$((RETVAL | 4))
fi
if [ "${IPMI_WATCHDOG}" = "yes" ]; then
device_node_exists /dev/watchdog
[ $? -eq 0 ] && RETVAL=$((RETVAL | 8))
fi
[ ! -e ${LOCKFILE} ] && RETVAL=$((RETVAL | 16))
}
status()
{
minimum_modules_loaded
[ $? -eq 0 ] && RETVAL=$((RETVAL | 1))
if [ "${DEV_IPMI}" = "yes" ]; then
modules_loaded_verbose ipmi_devintf
[ ${OnePlusLoaded} -eq 0 ] && RETVAL=$((RETVAL | 2))
device_node_exists /dev/ipmi${INTF_NUM}
[ $? -eq 0 ] && RETVAL=$((RETVAL | 4))
fi
if [ "${IPMI_IMB}" = "yes" ]; then
device_node_exists /dev/imb
[ $? -eq 0 ] && RETVAL=$((RETVAL | 4))
fi
}
status_watchdog()
{
minimum_modules_loaded
[ $? -eq 0 ] && RETVAL=$((RETVAL | 1))
modules_loaded_verbose ipmi_watchdog
[ ${OnePlusLoaded} -eq 0 ] && RETVAL=$((RETVAL | 2))
device_node_exists /dev/watchdog
[ $? -eq 0 ] && RETVAL=$((RETVAL | 8))
}
status_powercontrol()
{
minimum_modules_loaded
[ $? -eq 0 ] && RETVAL=$((RETVAL | 1))
modules_loaded_verbose ipmi_powercontrol
[ ${OnePlusLoaded} -eq 0 ] && RETVAL=$((RETVAL | 2))
}
#############################################################################
usage ()
{
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart" 1>&2
echo $" start-watchdog|stop-watchdog|status-watchdog" 1>&2
echo $" start-powercontrol|stop-powercontrol|status-powercontrol" 1>&2
echo $" stop-all|status-all}" 1>&2
RETVAL=1
}
condrestart ()
{
[ -e ${LOCKFILE} ] && restart
}
#############################################################################
# MAIN
#############################################################################
case "$1" in
start) start ;;
stop) stop ;;
restart) restart ;;
status) status ;;
status-all) status_all ;;
condrestart) condrestart ;;
try-restart) condrestart ;;
start-watchdog) start_watchdog ;;
stop-watchdog) stop_watchdog ;;
status-watchdog) status_watchdog ;;
start-powercontrol) start_powercontrol ;;
stop-powercontrol) stop_powercontrol ;;
status-powercontrol) status_powercontrol ;;
stop-all) stop_all ;;
*) usage ;;
esac
exit ${RETVAL}
#############################################################################
# end of file
#############################################################################