How to start qt application with eglfs plugin on startup without desktop environment

Hello,

I am currently working on the deployment of a qt application on jetsonTX2 (connect tech orbitty motherboard) with a graphical user interface.

I have installed l4t32.2.1 (ubuntu 18.04) on the TX2. My application uses qt, opencv (built with Cuda) and a driver for my camera.

Qt was cross compiled with the “-opengl es2” option.

My application works normally when I launch it from the TX2 (from the desktop environment), it launches full screen as expected using the eglfs plugin.

Now, I want the application to start automatically when the jetson TX2 boots. I can launch the application at startup using the auto-login function of lightdm and creating a .desktop file in the directory /etc/xdg/autostart. Everything is ok with this method.

However, I would like to achieve this without loading the graphical environment (“display manager”, desktop and so on) to have a lighter system. So, I have uninstalled the following packages: unity, lightdm and gnome-shell. The jetson TX2 then starts in console mode and asks for a login and a password. When I connect, I can launch my application with the following command:

startx my_application

Everything seems to work normally, the GUI appears and it is possible to interact normally. My problem is that I can not find a way to launch my application automatically after booting.

I have tried to create an autostart script in /etc/init.d/ and then to run it with update-rc.d autostart defaults but without success. Below are the contents of my scripts:

autostart.sh

#!/bin/sh
# https://wiki.debian.org/LSBInitScripts
### BEGIN INIT INFO
# Provides:          autostart
# Required-Start:    $all
# Required-Stop:    
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Autostart
### END INIT INFO

case "$1" in
  start)
    logger "Starting autostart scripts"

    # your scripts here
    /home/my_app/startup.sh

    logger $?
    exit 0
    ;;
  *)
    echo "It's just a startup script and has no arguments or commands"
    exit 1
    ;;
esac

startup.sh

#!/bin/sh

echo "Démarrage de mon application"

startx ./bin/my_application -platform eglfs > log.txt 2>&1 &

In the file /var/log/syslog I just have this line “Nov 8 22:18:50 pilotweeder autostart[4244]: Démarrage de mon application” but the application is not started and my “log.txt” file is empty.

Then, I have tried to make a service with systemd. Here is the content of my_app.service file:

[Unit]
Description=MyApp
#After=lightdm.service org.freedesktop.login1.service

[Service]
#Environment="DISPLAY=:0.0"
#Environment="QT_QPA_PLATFORM=eglfs"
#Environment="QT_QPA_EGLFS_PHYSICAL_WIDTH=535"
#Environment="QT_QPA_EGLFS_PHYSICAL_HEIGHT=300"
#Environment="QT_QPA_FONTDIR=/usr/share/fonts/truetype"
#Environment="XDG_RUNTIME_DIR=/tmp/runtime-nvidia"
Type=simple
TimeoutStartSec=60
WorkingDirectory=/home
#ExecStartPre=/etc/profile.d/qt_eglfs.sh
ExecStart=/home/my_app/startup.sh
Restart=always
#Restart=on-abort

[Install]
WantedBy=multi-user.target

Here is systemctl status :

● my_app.service - MyApp
   Loaded: loaded (/etc/systemd/system/my_app.service; enabled; vendor preset: enabled)
   Active: failed (Result: start-limit-hit) since Fri 2019-11-08 22:27:55 CET; 7s ago
  Process: 6949 ExecStart=/home/my_app/startup.sh (code=exited, status=0/
 Main PID: 6949 (code=exited, status=0/SUCCESS)

nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Service hold-off time over, scheduling restart.
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Scheduled restart job, restart counter is at 5.
nov. 08 22:27:55 pilotweeder systemd[1]: Stopped MyApp.
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Start request repeated too quickly.
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Failed with result 'start-limit-hit'.
nov. 08 22:27:55 pilotweeder systemd[1]: Failed to start MyApp.

And journalctl -xe

-- Subject: Unit my_app.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit my_app.service has finished shutting down.
nov. 08 22:27:55 pilotweeder systemd[1]: Started MyApp.
-- Subject: Unit my_app.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit my_app.service has finished starting up.
-- 
-- The start-up result is RESULT.
nov. 08 22:27:55 pilotweeder startup.sh[6949]: Démarrage de mon application
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Service hold-off time over, scheduling restart.
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Automatic restarting of the unit my_app.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
nov. 08 22:27:55 pilotweeder systemd[1]: Stopped MyApp.
-- Subject: Unit my_app.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit my_app.service has finished shutting down.
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Start request repeated too quickly.
nov. 08 22:27:55 pilotweeder systemd[1]: my_app.service: Failed with result 'start-limit-hit'.
nov. 08 22:27:55 pilotweeder systemd[1]: Failed to start MyApp.
-- Subject: Unit my_app.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit my_app.service has failed.

I think that the problem may come from the fact that I am not yet logged in when I run the service. But even if this is the explanation, I have no idea how to resolve this issue. Any idea from anyone would be greatly appreciated !

1 Like

Hi,
For running init script, we have tried to launch a gstreamer pipeline in rc.local
https://devtalk.nvidia.com/default/topic/1065398/jetson-nano/omxh264enc-and-nvvidconv-not-working-unless-/post/5396372/#5396372
The pipeline can be launched without login. Not sure if it can be applied to running qt5 application.

We have also tried reboot stress test by putting following commands at end of /etc/profile:

sleep 10 
reboot

And enable auto login in [System Settings] → [User Accounts]

Hope the cases we have tried/run can help your usecases.

Hi DaneLLL,

Thanks for your reply. I am not sure that this method can apply in my case, because I would like to do it without the login manager (lightdm) and the desktop environment (unity). In the procedure you’re describing, I feel like you have to keep both of them : “And enable auto login in [System Settings] → [User Accounts]”. Am I right?

I would like to boot in console mode, login in console mode (if needed) and launch my application directly, without any login mananger or desktop environment.

Thanks.

Hi,
In the first method( enable rc.local ), we can run the gstreamer pipeline without login. But not sure if it is same in running qt5 application.

Hi,
I tested the method with rc.local and it works. The application starts well but after 10 min the screen goes to sleep. I tried this command

setterm -powerdown 0

but it does not change anything. I also tried to stop these services

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

but it does not work either. Does someone have an idea ?

Thanks.

Hi,
Does it work if you login once to change the setting in [System Settings] → [Brightness & Lock]?

Hi,

No, I can’t because I uninstalled the entire graphical environment. However, here is the result of the dmesg command just after the screen goes to sleep and once it comes out to sleep.

[  613.459925] tegradc 15210000.nvdisplay: blank - powerdown
[  613.512005] extcon-disp-state external-connection:disp-state: cable 47 state 0
[  613.512008] Extcon AUX1(HDMI) disable
[  613.534349] tegra_nvdisp_handle_pd_disable: Powergated Head2 pd
[  613.534446] tegra_nvdisp_handle_pd_disable: Powergated Head1 pd
[  613.535276] tegra_nvdisp_handle_pd_disable: Powergated Head0 pd
[  630.476058] tegradc 15210000.nvdisplay: unblank
[  630.476878] tegra_nvdisp_handle_pd_enable: Unpowergated Head0 pd
[  630.476970] tegra_nvdisp_handle_pd_enable: Unpowergated Head1 pd
[  630.477052] tegra_nvdisp_handle_pd_enable: Unpowergated Head2 pd
[  630.478364] Parent Clock set for DC plld2
[  630.481267] tegradc 15210000.nvdisplay: hdmi: tmds rate:71000K prod-setting:prod_c_hdmi_54m_111m
[  630.482498] tegradc 15210000.nvdisplay: hdmi: get RGB quant from EDID.
[  630.482504] tegradc 15210000.nvdisplay: hdmi: get YCC quant from EDID.
[  630.519005] extcon-disp-state external-connection:disp-state: cable 47 state 1
[  630.519009] Extcon AUX1(HDMI) enable
[  630.521507] tegradc 15210000.nvdisplay: unblank

I think there is something with nvdisplay but I don’t know how to configure this.

thanks.