Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 7872  / 2 Years ago, sun, january 16, 2022, 12:28:41

I have struggled with this problem for three days and I have tried many ways to solve it but not successful yet. I hope you guys can help me...



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) ?


More From » scripts

 Answers
7

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:




  1. create a user for this purpose. Set it up so that its session will autostart.

    enter image description here


  2. set up a startup application for this user with the program you want; choose "startup application" in the dash:
    enter image description here


  3. 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...


[#23798] Sunday, January 16, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ncharm

Total Points: 255
Total Questions: 105
Total Answers: 118

Location: Virgin Islands (U.S.)
Member since Sat, May 6, 2023
1 Year ago
ncharm questions
;