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
49# Check for missing binaries (stale symlinks should not happen)
50# Note: Special treatment of stop for LSB conformance
51IPMIEVD_BIN=/usr/sbin/ipmievd
52test -x $IPMIEVD_BIN || { echo "$IPMIEVD_BIN not installed";
53	if [ "$1" = "stop" ]; then exit 0;
54	else exit 5; fi; }
55
56# Check for existence of needed config file and read it
57IPMIEVD_CONFIG=/etc/sysconfig/ipmievd
58test -r $IPMIEVD_CONFIG || { echo "$IPMIEVD_CONFIG does not exist";
59	if [ "$1" = "stop" ]; then exit 0;
60	else exit 6; fi; }
61
62# Read config
63. $IPMIEVD_CONFIG
64
65if test -e /etc/rc.status; then
66    # SUSE rc script library
67    . /etc/rc.status
68else
69    export LC_ALL=POSIX
70    _cmd=$1
71    declare -a _SMSG
72    if test "${_cmd}" = "status"; then
73	_SMSG=(running dead dead unused unknown reserved)
74	_RC_UNUSED=3
75    else
76	_SMSG=(done failed failed missed failed skipped unused failed failed reserved)
77	_RC_UNUSED=6
78    fi
79    if test -e /lib/lsb/init-functions; then
80	# LSB
81    	. /lib/lsb/init-functions
82	echo_rc()
83	{
84	    if test ${_RC_RV} = 0; then
85		log_success_msg "  [${_SMSG[${_RC_RV}]}] "
86	    else
87		log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
88	    fi
89	}
90	# TODO: Add checking for lockfiles
91	checkproc() { return pidofproc ${1+"$@"} >/dev/null 2>&1; }
92    elif test -e /etc/init.d/functions; then
93	# RHAT
94	. /etc/init.d/functions
95	echo_rc()
96	{
97	    #echo -n "  [${_SMSG[${_RC_RV}]}] "
98	    if test ${_RC_RV} = 0; then
99		success "  [${_SMSG[${_RC_RV}]}] "
100	    else
101		failure "  [${_SMSG[${_RC_RV}]}] "
102	    fi
103	}
104	checkproc() { return status ${1+"$@"}; }
105	start_daemon() { return daemon ${1+"$@"}; }
106    else
107	# emulate it
108	echo_rc() { echo "  [${_SMSG[${_RC_RV}]}] "; }
109    fi
110    rc_reset() { _RC_RV=0; }
111    rc_failed()
112    {
113	if test -z "$1"; then
114	    _RC_RV=1;
115	elif test "$1" != "0"; then
116	    _RC_RV=$1;
117    	fi
118	return ${_RC_RV}
119    }
120    rc_check()
121    {
122	return rc_failed $?
123    }
124    rc_status()
125    {
126	rc_failed $?
127	if test "$1" = "-r"; then _RC_RV=0; shift; fi
128	if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
129	if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
130	if test "$1" = "-v"; then echo_rc; shift; fi
131	if test "$1" = "-r"; then _RC_RV=0; shift; fi
132	return ${_RC_RV}
133    }
134    rc_exit() { exit ${_RC_RV}; }
135    rc_active()
136    {
137	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
138	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
139	return 1
140    }
141fi
142
143# Reset status of this service
144rc_reset
145
146# Return values acc. to LSB for all commands but status:
147# 0	  - success
148# 1       - generic or unspecified error
149# 2       - invalid or excess argument(s)
150# 3       - unimplemented feature (e.g. "reload")
151# 4       - user had insufficient privileges
152# 5       - program is not installed
153# 6       - program is not configured
154# 7       - program is not running
155# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
156#
157# Note that starting an already running service, stopping
158# or restarting a not-running service as well as the restart
159# with force-reload (in case signaling is not supported) are
160# considered a success.
161
162case "$1" in
163    start)
164	echo -n "Starting ipmievd "
165	start_daemon $IPMIEVD_BIN $IPMIEVD_OPTIONS
166	rc_status -v
167	;;
168    stop)
169	echo -n "Shutting down ipmievd "
170	killproc -TERM $IPMIEVD_BIN
171	rc_status -v
172	;;
173    try-restart|condrestart)
174	## Do a restart only if the service was active before.
175	## Note: try-restart is now part of LSB (as of 1.9).
176	## RH has a similar command named condrestart.
177	if test "$1" = "condrestart"; then
178		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
179	fi
180	$0 status
181	if test $? = 0; then
182		$0 restart
183	else
184		rc_reset	# Not running is not a failure.
185	fi
186	rc_status
187	;;
188    restart)
189	$0 stop
190	$0 start
191	rc_status
192	;;
193    force-reload)
194	echo -n "Reload service ipmievd "
195	$0 try-restart
196	rc_status
197	;;
198    reload)
199	rc_failed 3
200	rc_status -v
201	;;
202    status)
203	echo -n "Checking for service ipmievd "
204	checkproc $IPMIEVD_BIN
205	rc_status -v
206	;;
207    *)
208	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload| reload}"
209	exit 1
210	;;
211esac
212rc_exit
213