I was wandering if it is possible to access the DBUS session bus from within an upstart script.

The background is this:
I am running an upstart task in user mode and replaced the Upstart.conf dbus configuration file with the one from the upstart bzr repository.

Now it would like to access the gnome keyring within that tasks script using gkeyring, which needs to access the users upstart session bus. By default, I just get the Gnome keyring not available.

When I try to export DBUS_SESSION_BUS_ADDRESS=... within the upstart script, the script/initctl command just hangs, no output anywhere.

This leads me to believe that since upstart uses DBUS as well, using the session bus is problematic. Does someone have an idea to resolve this?

  • 1
    There could be multiple session buses for a user, so this isn't an easy one to answer. Have you considered launching your app as part of the user session instead? – James Henstridge Sep 15 '12 at 0:12
  • problem with that approach, is lack of robustness on failure, upstart restarts/logs as such. – Kevin Sep 19 '14 at 4:35

this might work for you ?...

    export HOME="/home/puma"
    chdir /home/puma/apps/whatever/bin
    dbus_file=$(ls $HOME/.dbus/session-bus/ -t1 | head -1)
    . "$HOME/.dbus/session-bus/$dbus_file"
    exec su -s /bin/sh -c 'export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS;exec /home/puma/apps/whatever/bin/appname' puma 
end script

hope it helps ?

  • 1
    This worked PERFECTLY! Thank you very much, i tried all the methods superuser.com/questions/213416/… and this is what worked... bluez-mpris-player aka mpris-proxy requires access to the session bus that your mpris2 player (Audacious) is running on. Now I have working AVRCP 1.3 (track changed metadata) with Bluez 4.101 (org.bluez.MediaPlayer) on Precise 12.04.5 with my carputer, paired to A2DP Bluetooth in Toyota Corolla I hope those with google foo can find this! – Kevin Sep 19 '14 at 4:34

If for all the processes who wants to access session bus the same DBUS_SESSION_BUS_ADDRESS environment variable is set, you are going to have no problems (see the manual). But since upstart tasks are run in a "restrictive environment" you will not have access to that variable in a system job (e.g. those under /etc/init). However if you were to have it as a session job (e.g. under /usr/share/upstart/sessions) you are going to have access to a lot of more environment variables. Moreover such jobs are not executed as root but as the session user. For example:

start on started dbus
stop on stopping dbus

respawn limit 10 5

kill timeout 20


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.