Linux Service Cannot Open Display
up vote
1
down vote
favorite
On my Odroid running Ubuntu 16.04.3 LTS I have a python2 program that interacts with a display device (projector). When I run this program from the command line:
python ~/imgProc/torcam.py
everything works fine. I want this program to run at startup so I created a service file:
/lib/systemd/system/torcam.service
It contains the following:
[Unit]
Description=Torcam Service
After=rc-local.service network-online.target
[Service]
User=root
ExecStart=/home/odroid/imgProc/starttor.sh
[Install]
WantedBy=multi-user.target
The startup script, starttor.sh contains:
#!/bin/bash
export DISPLAY=:0
cd /home/odroid/imgProc
python ./torcam.py
If I run this script from the command line everything works fine, but when I run this at boot or using systemctl I get an error saying "cannont open display: :0"
Here's how I installed the service:
odroid@odroid:~/imgProc$ sudo systemctl enable torcam
odroid@odroid:~/imgProc$ sudo systemctl start torcam
odroid@odroid:~/imgProc$ sudo systemctl status torcam
Here's the output:
odroid@odroid:~/imgProc$ sudo systemctl status torcam
● torcam.service - Torcam Service
Loaded: loaded (/lib/systemd/system/torcam.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2016-02-12 08:39:21 EST; 6min ago
Process: 1807 ExecStart=/home/odroid/imgProc/starttor.sh (code=exited, status=1/FAILURE)
Main PID: 1807 (code=exited, status=1/FAILURE)
Feb 12 08:39:19 odroid systemd[1]: Started Torcam Service.
Feb 12 08:39:19 odroid systemd[1807]: torcam.service: Executing: /home/odroid/imgProc/starttor.sh
Feb 12 08:39:21 odroid starttor.sh[1807]: No protocol specified
Feb 12 08:39:21 odroid starttor.sh[1807]: (test:1808): Gtk-WARNING **: cannot open display: :0
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Unit entered failed state.
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Failed with result 'exit-code'.
I understand that the problem is related to starting a service that interacts with the display, but I'm stuck on how to enable this so it works on boot. Any suggestions?
linux x11 display systemctl
New contributor
add a comment |
up vote
1
down vote
favorite
On my Odroid running Ubuntu 16.04.3 LTS I have a python2 program that interacts with a display device (projector). When I run this program from the command line:
python ~/imgProc/torcam.py
everything works fine. I want this program to run at startup so I created a service file:
/lib/systemd/system/torcam.service
It contains the following:
[Unit]
Description=Torcam Service
After=rc-local.service network-online.target
[Service]
User=root
ExecStart=/home/odroid/imgProc/starttor.sh
[Install]
WantedBy=multi-user.target
The startup script, starttor.sh contains:
#!/bin/bash
export DISPLAY=:0
cd /home/odroid/imgProc
python ./torcam.py
If I run this script from the command line everything works fine, but when I run this at boot or using systemctl I get an error saying "cannont open display: :0"
Here's how I installed the service:
odroid@odroid:~/imgProc$ sudo systemctl enable torcam
odroid@odroid:~/imgProc$ sudo systemctl start torcam
odroid@odroid:~/imgProc$ sudo systemctl status torcam
Here's the output:
odroid@odroid:~/imgProc$ sudo systemctl status torcam
● torcam.service - Torcam Service
Loaded: loaded (/lib/systemd/system/torcam.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2016-02-12 08:39:21 EST; 6min ago
Process: 1807 ExecStart=/home/odroid/imgProc/starttor.sh (code=exited, status=1/FAILURE)
Main PID: 1807 (code=exited, status=1/FAILURE)
Feb 12 08:39:19 odroid systemd[1]: Started Torcam Service.
Feb 12 08:39:19 odroid systemd[1807]: torcam.service: Executing: /home/odroid/imgProc/starttor.sh
Feb 12 08:39:21 odroid starttor.sh[1807]: No protocol specified
Feb 12 08:39:21 odroid starttor.sh[1807]: (test:1808): Gtk-WARNING **: cannot open display: :0
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Unit entered failed state.
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Failed with result 'exit-code'.
I understand that the problem is related to starting a service that interacts with the display, but I'm stuck on how to enable this so it works on boot. Any suggestions?
linux x11 display systemctl
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
On my Odroid running Ubuntu 16.04.3 LTS I have a python2 program that interacts with a display device (projector). When I run this program from the command line:
python ~/imgProc/torcam.py
everything works fine. I want this program to run at startup so I created a service file:
/lib/systemd/system/torcam.service
It contains the following:
[Unit]
Description=Torcam Service
After=rc-local.service network-online.target
[Service]
User=root
ExecStart=/home/odroid/imgProc/starttor.sh
[Install]
WantedBy=multi-user.target
The startup script, starttor.sh contains:
#!/bin/bash
export DISPLAY=:0
cd /home/odroid/imgProc
python ./torcam.py
If I run this script from the command line everything works fine, but when I run this at boot or using systemctl I get an error saying "cannont open display: :0"
Here's how I installed the service:
odroid@odroid:~/imgProc$ sudo systemctl enable torcam
odroid@odroid:~/imgProc$ sudo systemctl start torcam
odroid@odroid:~/imgProc$ sudo systemctl status torcam
Here's the output:
odroid@odroid:~/imgProc$ sudo systemctl status torcam
● torcam.service - Torcam Service
Loaded: loaded (/lib/systemd/system/torcam.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2016-02-12 08:39:21 EST; 6min ago
Process: 1807 ExecStart=/home/odroid/imgProc/starttor.sh (code=exited, status=1/FAILURE)
Main PID: 1807 (code=exited, status=1/FAILURE)
Feb 12 08:39:19 odroid systemd[1]: Started Torcam Service.
Feb 12 08:39:19 odroid systemd[1807]: torcam.service: Executing: /home/odroid/imgProc/starttor.sh
Feb 12 08:39:21 odroid starttor.sh[1807]: No protocol specified
Feb 12 08:39:21 odroid starttor.sh[1807]: (test:1808): Gtk-WARNING **: cannot open display: :0
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Unit entered failed state.
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Failed with result 'exit-code'.
I understand that the problem is related to starting a service that interacts with the display, but I'm stuck on how to enable this so it works on boot. Any suggestions?
linux x11 display systemctl
New contributor
On my Odroid running Ubuntu 16.04.3 LTS I have a python2 program that interacts with a display device (projector). When I run this program from the command line:
python ~/imgProc/torcam.py
everything works fine. I want this program to run at startup so I created a service file:
/lib/systemd/system/torcam.service
It contains the following:
[Unit]
Description=Torcam Service
After=rc-local.service network-online.target
[Service]
User=root
ExecStart=/home/odroid/imgProc/starttor.sh
[Install]
WantedBy=multi-user.target
The startup script, starttor.sh contains:
#!/bin/bash
export DISPLAY=:0
cd /home/odroid/imgProc
python ./torcam.py
If I run this script from the command line everything works fine, but when I run this at boot or using systemctl I get an error saying "cannont open display: :0"
Here's how I installed the service:
odroid@odroid:~/imgProc$ sudo systemctl enable torcam
odroid@odroid:~/imgProc$ sudo systemctl start torcam
odroid@odroid:~/imgProc$ sudo systemctl status torcam
Here's the output:
odroid@odroid:~/imgProc$ sudo systemctl status torcam
● torcam.service - Torcam Service
Loaded: loaded (/lib/systemd/system/torcam.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2016-02-12 08:39:21 EST; 6min ago
Process: 1807 ExecStart=/home/odroid/imgProc/starttor.sh (code=exited, status=1/FAILURE)
Main PID: 1807 (code=exited, status=1/FAILURE)
Feb 12 08:39:19 odroid systemd[1]: Started Torcam Service.
Feb 12 08:39:19 odroid systemd[1807]: torcam.service: Executing: /home/odroid/imgProc/starttor.sh
Feb 12 08:39:21 odroid starttor.sh[1807]: No protocol specified
Feb 12 08:39:21 odroid starttor.sh[1807]: (test:1808): Gtk-WARNING **: cannot open display: :0
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Unit entered failed state.
Feb 12 08:39:21 odroid systemd[1]: torcam.service: Failed with result 'exit-code'.
I understand that the problem is related to starting a service that interacts with the display, but I'm stuck on how to enable this so it works on boot. Any suggestions?
linux x11 display systemctl
linux x11 display systemctl
New contributor
New contributor
New contributor
asked Dec 4 at 17:13
cce1911
82
82
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Your torcam needs an X server, and systemd scripts are not meant to use the X server (it may not even have started when the scripts are run).
If you need this program to access the display device/projector independent of the user logging in via keyboard/monitor, consider using two X servers (one for the monitor, one for the projector), and starting torcam with correct authentication (man xauth
etc.) when the X server for the projector has started.
You'll need to read up on xorg.conf
, and how to restrict the X server to just some outputs (assuming it's a single graphics card with multiple outputs). You'll also need to read up on how an X server is started (display manager like xdm
etc., what you need for your monitor, vs. directly).
add a comment |
up vote
0
down vote
As kirkt mentioned, my problem was related to trying to use the X server running as root. After modifying my startup script, I was able to get the service to start correctly.
starrtor.sh:
#!/bin/bash
sleep 10
export DISPLAY=:0
cd /home/odroid/imgProc
exec sudo -u odroid /bin/sh - << eof
python ./torcam.py
New contributor
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Your torcam needs an X server, and systemd scripts are not meant to use the X server (it may not even have started when the scripts are run).
If you need this program to access the display device/projector independent of the user logging in via keyboard/monitor, consider using two X servers (one for the monitor, one for the projector), and starting torcam with correct authentication (man xauth
etc.) when the X server for the projector has started.
You'll need to read up on xorg.conf
, and how to restrict the X server to just some outputs (assuming it's a single graphics card with multiple outputs). You'll also need to read up on how an X server is started (display manager like xdm
etc., what you need for your monitor, vs. directly).
add a comment |
up vote
1
down vote
accepted
Your torcam needs an X server, and systemd scripts are not meant to use the X server (it may not even have started when the scripts are run).
If you need this program to access the display device/projector independent of the user logging in via keyboard/monitor, consider using two X servers (one for the monitor, one for the projector), and starting torcam with correct authentication (man xauth
etc.) when the X server for the projector has started.
You'll need to read up on xorg.conf
, and how to restrict the X server to just some outputs (assuming it's a single graphics card with multiple outputs). You'll also need to read up on how an X server is started (display manager like xdm
etc., what you need for your monitor, vs. directly).
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Your torcam needs an X server, and systemd scripts are not meant to use the X server (it may not even have started when the scripts are run).
If you need this program to access the display device/projector independent of the user logging in via keyboard/monitor, consider using two X servers (one for the monitor, one for the projector), and starting torcam with correct authentication (man xauth
etc.) when the X server for the projector has started.
You'll need to read up on xorg.conf
, and how to restrict the X server to just some outputs (assuming it's a single graphics card with multiple outputs). You'll also need to read up on how an X server is started (display manager like xdm
etc., what you need for your monitor, vs. directly).
Your torcam needs an X server, and systemd scripts are not meant to use the X server (it may not even have started when the scripts are run).
If you need this program to access the display device/projector independent of the user logging in via keyboard/monitor, consider using two X servers (one for the monitor, one for the projector), and starting torcam with correct authentication (man xauth
etc.) when the X server for the projector has started.
You'll need to read up on xorg.conf
, and how to restrict the X server to just some outputs (assuming it's a single graphics card with multiple outputs). You'll also need to read up on how an X server is started (display manager like xdm
etc., what you need for your monitor, vs. directly).
answered 2 days ago
dirkt
16.4k21335
16.4k21335
add a comment |
add a comment |
up vote
0
down vote
As kirkt mentioned, my problem was related to trying to use the X server running as root. After modifying my startup script, I was able to get the service to start correctly.
starrtor.sh:
#!/bin/bash
sleep 10
export DISPLAY=:0
cd /home/odroid/imgProc
exec sudo -u odroid /bin/sh - << eof
python ./torcam.py
New contributor
add a comment |
up vote
0
down vote
As kirkt mentioned, my problem was related to trying to use the X server running as root. After modifying my startup script, I was able to get the service to start correctly.
starrtor.sh:
#!/bin/bash
sleep 10
export DISPLAY=:0
cd /home/odroid/imgProc
exec sudo -u odroid /bin/sh - << eof
python ./torcam.py
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
As kirkt mentioned, my problem was related to trying to use the X server running as root. After modifying my startup script, I was able to get the service to start correctly.
starrtor.sh:
#!/bin/bash
sleep 10
export DISPLAY=:0
cd /home/odroid/imgProc
exec sudo -u odroid /bin/sh - << eof
python ./torcam.py
New contributor
As kirkt mentioned, my problem was related to trying to use the X server running as root. After modifying my startup script, I was able to get the service to start correctly.
starrtor.sh:
#!/bin/bash
sleep 10
export DISPLAY=:0
cd /home/odroid/imgProc
exec sudo -u odroid /bin/sh - << eof
python ./torcam.py
New contributor
New contributor
answered 2 days ago
cce1911
82
82
New contributor
New contributor
add a comment |
add a comment |
cce1911 is a new contributor. Be nice, and check out our Code of Conduct.
cce1911 is a new contributor. Be nice, and check out our Code of Conduct.
cce1911 is a new contributor. Be nice, and check out our Code of Conduct.
cce1911 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485955%2flinux-service-cannot-open-display%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown