description "DBus Session Bus"
author "Stéphane Graber <stgraber@ubuntu.com>"

start on starting xsession-init

env DBUS_DEBUG_OUTPUT=1

respawn
expect fork
pre-start script
    DBUS_SESSION_BUS_ADDRESS=unix:abstract=$(mktemp -u /tmp/dbus-XXXXXXXXXX)
    initctl set-env DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
end script

exec dbus-daemon --fork --session --address="$DBUS_SESSION_BUS_ADDRESS"

post-start script
    initctl set-env --global DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
    [ -d "$HOME/.cache/upstart" ] || mkdir -p "$HOME/.cache/upstart" || true
    echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" >$XDG_RUNTIME_DIR/dbus-session || true
    initctl notify-dbus-address "$DBUS_SESSION_BUS_ADDRESS" || true
end script
