#!/bin/sh
#
# mcelog	Hardware error logging
#
# chkconfig: - 90 10
# description:	Start the mcelog hardware error logging. \
#		This logs and handles CPU hardware errors on x86 systems
# processname: mcelog
# config: /etc/mcelog.conf
# pidfile: /var/run/mcelog.pid

### BEGIN INIT INFO
# Provides:             mcelog 
# Default-Start:        3 5
# Default-Stop:         0 1 2 6
# Short-Description:    mcelog hardware error logging
# Description:          Start the mcelog hardware error logging. 
#                       This logs and handles CPU hardware errors on x86 systems.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

[ ! -r /dev/mcelog ] && ( echo "/dev/mcelog not active" ; exit 0 )

PIDFILE=/var/run/mcelog.pid
LOCKFILE=/var/lock/subsys/mcelog
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- mcelog --daemon
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- mcelog
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload|restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- mcelog
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
