#!/bin/sh
#
# haldaemon	HAL daemon
#
# chkconfig:	345 48 52
#
# description:	This is a daemon for collecting and maintaing information \
#               about hardware from several sources. \
#               See http://www.freedesktop.org/wiki/Software/hal
#
# $Id: haldaemon.init,v 1.15 2009/03/24 17:44:08 paszczus Exp $


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

# Include debbuging statment
. /etc/sysconfig/hald

start() {
	# First step: check for running messagebus service
	if [ ! -f /var/lock/subsys/messagebus ]; then
		msg_not_running messagebus
		return
	fi

	# Check if the service is already running?
	if [ -f /var/lock/subsys/haldaemon ]; then
		msg_already_running haldaemon
		return
	fi

	msg_starting haldaemon
	# Syslog output
	if is_yes "$USE_SYSLOG"; then
		daemon /usr/sbin/hald --use-syslog
	else
		daemon /usr/sbin/hald
	fi
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/haldaemon
}

stop() {
	if [ ! -f /var/lock/subsys/haldaemon ]; then
		msg_not_running haldaemon
		return
	fi

	# Stop daemons.
	msg_stopping haldaemon
	killproc hald
	rm -f /var/lock/subsys/haldaemon
}

condrestart() {
	if [ ! -f /var/lock/subsys/haldaemon ]; then
		msg_not_running haldaemon
		RETVAL=$1
		return
	fi

	stop
	start
}

reload() {
	if [ ! -f /var/lock/subsys/haldaemon ]; then
		msg_not_running haldaemon
		RETVAL=7
		return
	fi

	msg_reloading haldaemon
	killproc hald -HUP
	RETVAL=$?
}

# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  reload|force-reload)
  	reload
	;;
  status)
	status hald
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
