ipmi.init.redhat 4.8 KB

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