#!/bin/sh
#
# messagebus:   The D-BUS systemwide message bus
#
# chkconfig: 345 33 92
# description:  This is a daemon which broadcasts notifications of system events \
#               and other messages. See http://www.freedesktop.org/software/dbus/
#
# processname: dbus-daemon
# config: /etc/dbus-1
# pidfile: /var/run/messagebus.pid
#

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Sanity checks.
[ -x /usr/bin/dbus-daemon ] || exit 0

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

# so we can rearrange this easily
processname=dbus-daemon
servicename=messagebus

LOCKFILE=/var/lock/subsys/$servicename
PIDFILE=/var/run/messagebus.pid
USER=messagebus

RETVAL=0

start() {
    if [ -x /usr/bin/dbus-uuidgen ] ; then
        /usr/bin/dbus-uuidgen --ensure
    fi

    msg_starting $"system message bus"
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --no-announce -- \
	"$processname" --system
    RETVAL=$?
    return $RETVAL
}

stop() {
    msg_stopping $"system message bus"
    stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --no-announce \
       "$processname" -TERM
    rm -f "$PIDFILE" ||:
    RETVAL=$?
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
	status --pidfile "$PIDFILE" --expect-user "$USER" $processname
	RETVAL=$?
        ;;
    restart)
        stop
        start
        ;;
    condstop)
	if [ -f "$LOCKFILE" ]; then
	    stop
	fi
	;;
    condrestart)
	if [ -f "$LOCKFILE" ]; then
            stop
            start
        fi
	;;
    reload)
        msg_usage "Message bus can't reload its configuration, you have to restart it"
        RETVAL=1
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condstop|condrestart|reload}"
        ;;
esac
exit $RETVAL
