#!@l_prefix@/bin/openpkg rc
##
##  rc.dbus -- Run-Commands
##

%config
    dbus_enable="$openpkg_rc_def"
    dbus_flags="--system --fork"

%common
    dbus_pidfile="@l_prefix@/var/dbus/run/dbus.pid"
    dbus_cfgfile="@l_prefix@/etc/dbus/system.conf"
    dbus_signal () {
        [ -f $dbus_pidfile ] && kill -$1 `cat $dbus_pidfile`
    }

%status -u @l_susr@ -o
    dbus_usable="unknown"
    dbus_active="no"
    rcService dbus enable yes && \
        dbus_signal 0 && dbus_active="yes"
    echo "dbus_enable=\"$dbus_enable\""
    echo "dbus_usable=\"$dbus_usable\""
    echo "dbus_active=\"$dbus_active\""

%start -u @l_susr@
    rcService dbus enable yes || exit 0
    rcService dbus active yes && exit 0
    @l_prefix@/bin/dbus-daemon $dbus_flags >/dev/null 2>&1

%stop -u @l_susr@
    rcService dbus enable yes || exit 0
    rcService dbus active no && exit 0
    dbus_signal TERM
    sleep 2
    rm -f $dbus_pidfile 2>/dev/null || true

%restart -u @l_susr@
    rcService dbus enable yes || exit 0
    rcService dbus active no && exit 0
    rc dbus stop start

