2

I have an GUI application. I want to start this application automatically. And when it goes down or closed unexpectedly, I want to reopen this application.

I tried to use upstart script, however although there is no problem about services with upstart, GUI application is not starting with upstart script. It says cannot connect X server..

Should I add or change some settings to open with upstart or is there any way to open GUI application automatically when unexpected exit or shut down occurs (not just once after login I mean not with Startup) ?

EDIT : Here is my current step for upstart:

I am trying to start GUI application with upstart script on CentOS. I have test script located /etc/init/ folder.

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

respawn

script
export DISPLAY=:0
sleep 5
exec /.1/Projects/UpstartTest/start.sh &

end script

start.sh scripts is running binary files for GUI application.

After reboot my computer. When I typed:

[root@mg-CentOS ~]# initctl status test
test stop/waiting

So my upstart is not runnig. When i type

initctl start test

manually it works fine without any problem.

How can I run this upstart script after user login (desktop started) ?

  • You have crossposted on stackOverflow, SuperUser, and AskUbuntu and received answers there. Crossposting is against the rules, on top of wasting the time of people who'll write answers you already got elsewhere. mtac already gave you a link to the Upstart documentation below. – Leiaz Aug 7 '14 at 8:55
2

Upstart is probably not the best way to start GUI applications as it was designed to start daemons. However, you can still use it if you follow the right startup sequence (the X server needs to be started before you start the GUI app).

To avoid the 'cannot connect to X server' error, you need to set the DISPLAY variable in your startup script (and make sure the app is running as the same user running the X server). You can do this with:

export DISPLAY=:0.0
  • yes i used export DISPLAY, but my script is working just once. After that it is not restarting again.. – goGud Aug 6 '14 at 10:33
  • That would be good information to add in your original question. Upstart is notoriously difficult to get it to restart applications, because it needs precise instructions on which process to monitor. You should probably check out the expect section of the Upstart manual (upstart.ubuntu.com/cookbook/#expect) – mtak Aug 6 '14 at 10:37

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.