Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

guitest

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?

task

start on desktop-session-start  or guitest

script
    gedit
end script
share|improve this question
add comment

2 Answers

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.

Manually

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:

http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html

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]
Type=Application
Exec=/usr/bin/gedit
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=GEdit
Comment=

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.

share|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
    
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
add comment
up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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