#!/usr/bin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License, v2 or later

supervisor=supervise-daemon
description="An IPC message bus daemon"
command="/usr/bin/dbus-daemon"
command_args="--system"
command_args_foreground="--nofork --nopidfile"
extra_started_commands="reload"

dbus_socket="/run/dbus/system_bus_socket"

depend() {
    need localmount
    after bootmisc
}

start_pre() {
    /usr/bin/dbus-uuidgen --ensure=/etc/machine-id

    # We need to test if /run/dbus exists, since script will fail if it does not
    checkpath -q -d "/run/dbus"
}

stop_post() {
    [ ! -S "${dbus_socket}" ] || rm -f "${dbus_socket}"
}

reload() {
    ebegin "Reloading D-BUS messagebus config"
    dbus-send --print-reply --system --type=method_call \
            --dest=org.freedesktop.DBus \
            / org.freedesktop.DBus.ReloadConfig > /dev/null
    eend $?
}
