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 --global DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
    [ -d "$HOME/.cache/upstart" ] || mkdir -p "$HOME/.cache/upstart"
    echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" >$HOME/.cache/upstart/dbus-session
end script

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

post-start exec initctl notify-dbus-address "$DBUS_SESSION_BUS_ADDRESS" || true
