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?