I have a python gtk app I need to run when a user logs in. I can't get upstart to launch any gui app, even if x is running.

When I'm signed into X, and I emit the event from the upstart script below


with initctl, I get

initctl: Event failed

Here is an example of my script, except I've replaced gedit with my app. How can I modify this script so gedit or my python gtk app will launch?


start on desktop-session-start  or guitest

end script

Upstart is primarily for managing system services. If you want to run an application as part of the user session, there are better tools.

Via the GUI

You can configure a startup application in a user's session by picking Startup Applications... from the cog menu in the top right of the screen, and then pick Add and fill in the details for gedit.

When you log in next time, the application should start with the session.


If you can't use the UI to configure this, it is possible to configure it by dropping a .desktop file in one of the autostart directories according to the Autostart specification:


If you want it to affect every user on the system, place the file in /etc/xdg/autostart. If you only want to affect a single user, place the file in ~/.config/autostart.

The .desktop file should look something like:

[Desktop Entry]

If you place the file in the user's home directory, make sure you set the execute bit on the file. This is part of a security measure to stop programs unintentionally writing working .desktop files due to bugs.

| improve this answer | |
  • The script must run as root. Would it be possible to do it your way by adding a the user to the sudoers file for that specific script? – bambuntu Feb 24 '12 at 9:16
  • 1
    You could do that by running /usr/bin/gksudo gedit as the command. That will prompt the user for their password in the standard Ubuntu configuration though. – James Henstridge Feb 24 '12 at 9:44

I've found a workaround. If anyone else know 'the right way', please let me know.

The upstart script needs to write a flag file. Another process that is started by the user will be constantly looking for this flag file to be created. The upstart script can leave any relevant information in the flag file. A regular user of course or root has not problem running gui apps. Why upstart does have a problem, remains to be answered.

| improve this answer | |

I was able to get this to work with a QT application by setting a "USER" environment variable and a "DISPLAY" environment variable in the upstart script.

# gui - auto launch daemon

description     "gui daemon"

start on desktop-session-start
stop on desktop-shutdown

env HOME=/home/user

    export DISPLAY=:0
end script

It's limited to the given user of course so may not be a valid option for some usecases, but for my case it works perfect.

| improve this answer | |

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.