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

I have been having a similar problem but I am not sure how to use the solution you suggested. I am simply using a .service file to start executing a .sh script in my machine. That script plays a live video stream from a camera. Manually the script is running fine and I can see the stream output. However, when the service is started there is some sort of error: Unable to init server: Could not connect: Connection refused : cannot open display:
I have tried playing around with $DISPLAY variable and xhost command but no success. Any suggestions are welcome.

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.

I have looked through the list of units provided by the systemd. I was unable to find any unit with the name graphical.service. However, there is a unit named graphical.target though, but I assume that serves a different purpose altogether. I couldn’t find out how that would help in my case.

You cannot display video without a logged in GUI context. Automatic run is occurring prior to your user logging in. Remember that commands such as xhost will only work if the server is already running and logged in to.

This should probably be a new thread, but the issue is the same as in the original topic. graphical.service makes GUI login available, but is not an actual login. What did you do to log in prior to running your script?

Earlier comments about startx are because running X via startx differs from graphical.service. graphical.service is a login service, and does not run X/GUI other than the login program. startx actually runs a logged in X/GUI session (the user logged in will be the user who ran startx).