Automatic start of a GUI program


I’ve browsed through multiple threads on this topic, but I’m still quite confused (and many of them are unsolved or updated only with further problems). I’m hoping someone can help me out on what seemed at first like a simple issue…

I am using JetPack4.2.1, flashed from Ubuntu 16.04… Let me know if additional info is needed please.

I have a Python program that takes information from a camera connected by USB and runs a GUI. I would like that program to open automatically, without input from the user, after the board powers on.

Adding regular programs to the Start Up Applications menu (Chromium or Solitaire, for example) seems to work fine, simply by clicking Add and typing in the command for the program. I’ve tried adding mine that way, and I’ve also tried adding it with “sleep 50” beforehand thinking maybe it was booting too soon, but no luck.

What can I do to make the GUI open automatically?

These are the threads I tried looking at:
And this one seemed the most promising:
but not quite sure I follow.

From these, I tried writing the following script:

#! /bin/sh
sleep 20
python3 <path to program>
@reboot sleep 20 && python3 <path to program>

and then inserting it into the folder /etc/init.d/ but nothing happened.

Hoping someone can point out my mistake or give me some better advice :(

Edit to add -
I also tried adding the line that runs the script to the file in /etc/profile.d as suggested here:
but didn’t work. Another answer there suggest adding to the folder /etc/rc.local, but that doesn’t seem to exist on my board…

You might try this:

Some notes which may help:

  • GUI applications need to be run from the same user as the GUI is run under (there are ways around this, but significant effort would be required).
  • If the application cannot run manually in the GUI, then it won't run automatically either.
  • Running CUDA apps in a GUI tends to require the user be in group "video". If the app runs under that user, then you can assume the user is already a member of "video".
  • Any app run directly inside of a GUI will inherit the "DISPLAY" environment variable. To see which "DISPLAY" you are using, run this while in the GUI:
    echo $DISPLAY
  • Any script which is not run from in the GUI will require "DISPLAY" be set to the same as the "DISPLAY" from the GUI. If the GUI is not already running with that DISPLAY, then it will be impossible to open the app.
  • The file "/etc/rc.local" can be created if it doesn't already exist. It should be owned by root and have root execute permissions.
  • The file "rc.local" is not what you want if the command runs as someone other than root. You could use an "sudo" statement in the run, but keep in mind that if you relate to a GUI, then the GUI has to already be running and the DISPLAY must be correct...none of which exists at the time in boot where rc.local is run.

Hi linuxdev, thanks for the response!
The instructions in the link are similar to the first thing I tried (mentioned in my post, adding to Start Up Applications). For some reason, this works for other programs (like Firefox as mentioned in the tutorial), but not my Python program.

Re your notes:
What do you mean by “if it cannot run manually in the GUI”? Not sure I understood correctly what you mean, but if I type in the command in terminal after the computer has started up, the program works. If I copy that same command to Start Up Applications, it does not start up automatically.

echo $DISPLAY gives me :0, but I’m not entirely sure what to do with this. Should I have added this somewhere in my shell script?

Sounds like rc.local is indeed not the place for my script. Is there a different folder that runs after the desktop is set up that I should try instead? Or is the /profile.d folder the last thing that runs automatically?

That was what I meant. Since manual start works, then it is probably a missing environment variable needed for automatic startup.

rc.local is rarely the place to start a CUDA or GUI program. This runs prior to any GUI login.

What you might try is launching your program from a script. Let’s say the script runs program “hello”, you could do something like this to set environment within the auto start area (not rc.local):


DISPLAY=:0 /where/ever/it/is/hello

When an environment variable is provided on the command line like this it will be inherited by the program at the end of the command line. Alternately:


export DISPLAY=:0

I am having the same problem.
Python GUI is running when I manually open it from Terminal
But it is not running automatically.
I tried it by using startup application, crontab and even tried to create service but it is not working.

You should probably start a new topic. However, for a new topic, post the following:

  • When it works, then what do you see from this in the terminal it works from? “echo $DISPLAY”.
  • How is the program being started, e.g., from the user’s login triggering it, versus from the system without a user login.

Do note that the program might rely on a “DISPLAY” context, and if it does, then the GUI must be running (either a real GUI or a virtual one).

1 Like

Thank you for your response. I solved the problem. 😊