Cannot open display

Hi,
We are using Jetson nano board and try to display video on HDMI at power using service.
We are facing “cannot open display:” error. I’ve already looked at a couple of solutions,but that doesn’t work.
Can anyone suggest how to resolve above error ?

Hi,

This question is not clear enough. Could you elaborate what does “at power using service” mean here?

Hi,
Thank you for quick reply…
This is my Service File looks like :
[Unit]
Description=Ethernet Status Check
Requires=network.target
After=graphical.service

[Service]
Type=simple
Restart=always
RestartSec=10
RemainAfterExit=yes
Environment=“DISPLAY=:0” “XAUTHORITY=${XDG_RUNTIME_DIR}/gdm/Xauthority”
ExecStart=/bin/bash MyScript.sh
User=root
StandardOutput=journal+console

[Install]
WantedBy=graphical.target

In MyScript.sh, I ran my application that will display a video using opencv (i.e., imshow).
If I run my script manually from command promt, It’s working fine but the same script returns error called “Cannot open display” when it is executed with service. Please suggest …

Hi,

Are you sure you can run your script manually from command prompt as “root”?

To emphasize something @WayneWWW mentions, no X display will allow another user to remote display into it even if the $DISPLAY is otherwise correct. If your X display is not running, or if the login menu is there and login is not truly complete, or if the logged in user differs from the user running the application, then using that $DISPLAY will fail or be refused.

Also, graphical.service only guarantees a default TTY is running a login service. This does not actually log in a user, so I suspect that when graphical.service is reached there is no actual logged in X GUI session yet.

You might consider examining the “startx” script. This script is used to manually start X on a terminal, and simply runs as the user who ran the script. There is no intermediate login manager. The regular login manager could continue to be run on “:0”, and the startx could purposely start somewhere this won’t collide with, e.g., “:9”. The startx could even be set up as its own service, and if you don’t want the regular GUI login to run, then you could go to a default runlevel of “multi-user.target”, and have your service trigger upon reaching multi-user.target (and perhaps even wait for network.service if needed).