How to start GUI application with upstart?
Create a file $HOME/.config/upstart/myGuiStart.conf
Content:
start on desktop-start
stop on desktop-end
respawn
exec firefox
or another example with a delay:
start on desktop-start
stop on desktop-end
respawn
script
sleep 30
firefox
end script
description of respawn:
respawn
A service or task with this stanza will be automatically started
if it should stop abnormally. All reasons for a service stopping,
except the stop(8) command itself, are considered abnormal. Tasks
may exit with a zero exit status to prevent being respawned.
More info:
http://ifdeflinux.blogspot.de/2013/04/upstart-user-sessions-in-ubuntu-raring.html
http://upstart.ubuntu.com/
Respawn bug? -> https://askubuntu.com/a/62461/265974
The problem you are facing is that when upstart
(or systemd
, or the scripts in /etc/rc.d/
) are run, there is normally no graphic service ("the X server") running.
Moreover, the availability of the graphic subsystem in Unix is strictly bond to the concept that a user has done a graphic login, and just this user has the right to use the graphic environment. It is customary NOT to start a graphic subsytem for root --- and the upstart scripts are run by root.
To automatically start a graphic application at the start of the system, my approach would be:
create a user for this purpose. Set it up so that its session will autostart.
set up a startup application for this user with the program you want; choose "startup application" in the dash:
-
for restarting the application when it exits/crashes, you can simply embed it in a script:
#!/bin/bash # while true; do /full/path/to/start_myapp.sh # NO background (&)! # if we land here it exited sleep 5 done
If you use this script, it is really important that the command start_myapp.sh
should not launch the application in background. Otherwise, more complex strategies are required to auto-restart...
Notice that you can use your normal user in parallel too; just choose "switch user" from the panel (adapt to your flavor of Ubuntu) and you will have another graphical login screen; you can switch back-an-forth using CTRL-ALT-F7 and CTRL-ALT-F8...