ipmievd.init.suse 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. #
  3. # System startup script for ipmievd
  4. # Based on skeleton.compat example script
  5. # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
  6. #
  7. # This library is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
  20. # USA.
  21. #
  22. # Note: This template uses functions rc_XXX defined in /etc/rc.status on
  23. # UnitedLinux/SUSE/Novell based Linux distributions. However, it will work
  24. # on other distributions as well, by using the LSB (Linux Standard Base)
  25. # or RH functions or by open coding the needed functions.
  26. # Read http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/ if you prefer not
  27. # to use this template.
  28. #
  29. # chkconfig: 345 99 00
  30. # description: ipmievd daemon
  31. #
  32. ### BEGIN INIT INFO
  33. # Provides: ipmievd
  34. # Required-Start: $syslog ipmi
  35. # Should-Start: $time
  36. # Required-Stop: $syslog ipmi
  37. # Should-Stop: $time
  38. # Default-Start: 3 4 5
  39. # Default-Stop: 0 1 2 6
  40. # Short-Description: ipmievd daemon to send events to syslog
  41. # Description: Start ipmievd to read events from BMC and
  42. # log them to syslog. Events correspond to hardware faults,
  43. # state transitions such as power on and off, and sensor
  44. # readings such as temperature, voltage and fan speed that
  45. # are abnormal.
  46. ### END INIT INFO
  47. #
  48. # Check for missing binaries (stale symlinks should not happen)
  49. # Note: Special treatment of stop for LSB conformance
  50. IPMIEVD_BIN=/usr/sbin/ipmievd
  51. test -x $IPMIEVD_BIN || { echo "$IPMIEVD_BIN not installed";
  52. if [ "$1" = "stop" ]; then exit 0;
  53. else exit 5; fi; }
  54. # Check for existence of needed config file and read it
  55. IPMIEVD_CONFIG=/etc/sysconfig/ipmievd
  56. test -r $IPMIEVD_CONFIG || { echo "$IPMIEVD_CONFIG does not exist";
  57. if [ "$1" = "stop" ]; then exit 0;
  58. else exit 6; fi; }
  59. # Read config
  60. . $IPMIEVD_CONFIG
  61. if test -e /etc/rc.status; then
  62. # SUSE rc script library
  63. . /etc/rc.status
  64. else
  65. export LC_ALL=POSIX
  66. _cmd=$1
  67. declare -a _SMSG
  68. if test "${_cmd}" = "status"; then
  69. _SMSG=(running dead dead unused unknown reserved)
  70. _RC_UNUSED=3
  71. else
  72. _SMSG=(done failed failed missed failed skipped unused failed failed reserved)
  73. _RC_UNUSED=6
  74. fi
  75. if test -e /lib/lsb/init-functions; then
  76. # LSB
  77. . /lib/lsb/init-functions
  78. echo_rc()
  79. {
  80. if test ${_RC_RV} = 0; then
  81. log_success_msg " [${_SMSG[${_RC_RV}]}] "
  82. else
  83. log_failure_msg " [${_SMSG[${_RC_RV}]}] "
  84. fi
  85. }
  86. # TODO: Add checking for lockfiles
  87. checkproc() { return pidofproc ${1+"$@"} >/dev/null 2>&1; }
  88. elif test -e /etc/init.d/functions; then
  89. # RHAT
  90. . /etc/init.d/functions
  91. echo_rc()
  92. {
  93. #echo -n " [${_SMSG[${_RC_RV}]}] "
  94. if test ${_RC_RV} = 0; then
  95. success " [${_SMSG[${_RC_RV}]}] "
  96. else
  97. failure " [${_SMSG[${_RC_RV}]}] "
  98. fi
  99. }
  100. checkproc() { return status ${1+"$@"}; }
  101. start_daemon() { return daemon ${1+"$@"}; }
  102. else
  103. # emulate it
  104. echo_rc() { echo " [${_SMSG[${_RC_RV}]}] "; }
  105. fi
  106. rc_reset() { _RC_RV=0; }
  107. rc_failed()
  108. {
  109. if test -z "$1"; then
  110. _RC_RV=1;
  111. elif test "$1" != "0"; then
  112. _RC_RV=$1;
  113. fi
  114. return ${_RC_RV}
  115. }
  116. rc_check()
  117. {
  118. return rc_failed $?
  119. }
  120. rc_status()
  121. {
  122. rc_failed $?
  123. if test "$1" = "-r"; then _RC_RV=0; shift; fi
  124. if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
  125. if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
  126. if test "$1" = "-v"; then echo_rc; shift; fi
  127. if test "$1" = "-r"; then _RC_RV=0; shift; fi
  128. return ${_RC_RV}
  129. }
  130. rc_exit() { exit ${_RC_RV}; }
  131. rc_active()
  132. {
  133. if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
  134. if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
  135. return 1
  136. }
  137. fi
  138. # Reset status of this service
  139. rc_reset
  140. # Return values acc. to LSB for all commands but status:
  141. # 0 - success
  142. # 1 - generic or unspecified error
  143. # 2 - invalid or excess argument(s)
  144. # 3 - unimplemented feature (e.g. "reload")
  145. # 4 - user had insufficient privileges
  146. # 5 - program is not installed
  147. # 6 - program is not configured
  148. # 7 - program is not running
  149. # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  150. #
  151. # Note that starting an already running service, stopping
  152. # or restarting a not-running service as well as the restart
  153. # with force-reload (in case signaling is not supported) are
  154. # considered a success.
  155. case "$1" in
  156. start)
  157. echo -n "Starting ipmievd "
  158. start_daemon $IPMIEVD_BIN $IPMIEVD_OPTIONS
  159. rc_status -v
  160. ;;
  161. stop)
  162. echo -n "Shutting down ipmievd "
  163. killproc -TERM $IPMIEVD_BIN
  164. rc_status -v
  165. ;;
  166. try-restart|condrestart)
  167. ## Do a restart only if the service was active before.
  168. ## Note: try-restart is now part of LSB (as of 1.9).
  169. ## RH has a similar command named condrestart.
  170. if test "$1" = "condrestart"; then
  171. echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
  172. fi
  173. $0 status
  174. if test $? = 0; then
  175. $0 restart
  176. else
  177. rc_reset # Not running is not a failure.
  178. fi
  179. rc_status
  180. ;;
  181. restart)
  182. $0 stop
  183. $0 start
  184. rc_status
  185. ;;
  186. force-reload)
  187. echo -n "Reload service ipmievd "
  188. $0 try-restart
  189. rc_status
  190. ;;
  191. reload)
  192. rc_failed 3
  193. rc_status -v
  194. ;;
  195. status)
  196. echo -n "Checking for service ipmievd "
  197. checkproc $IPMIEVD_BIN
  198. rc_status -v
  199. ;;
  200. *)
  201. echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload| reload}"
  202. exit 1
  203. ;;
  204. esac
  205. rc_exit