Commands work in terminal but not in systemd unit file?

nanok666

New Member
Joined
Mar 4, 2021
Messages
2
Reaction score
0
Credits
33
Hi,

I am running Raspbian Lite on a RPi and trying to get systemd to start a graphical python app. The weird thing is I can enter 2 commands into terminal and get my graphical app to run but the same commands in systemd unit file does not work! It seems the unit file is running but my ExecStart is failing.


In the folder /etc/systemd/system I have a file called kegwasher.service which looks like this:

[Unit]
Description=Keg Washer

[Service]
User=pi
Environment=DISPLAY=:0
ExecStart=/bin/bash /home/pi/appstart & startx
Restart=always
RestartSec=20s
KillMode=process
TimeoutSec=infinity

[Install]
WantedBy=graphical.target


In the folder /home/pi I have a file called "appstart" which looks like this:

#! /bin/bash
sleep 1
sudo chvt 1
python3 /home/pi/KegWasher.py


Here are the results from typing "sudo systemctl status kegwasher.service":

kegwasher.service - Keg Washer
Loaded: loaded (etc/systemd/system/kegwasher.service; ...............)
Active: activating (auto-restart) (Result: exit-code)
Process: 527 ExecStart=/bin/bash /home/pi/appstart & startx (code-exited, status=1/FAILURE


My graphical python app works perfectly (and my appstart script works) by typing the following commands into terminal:

export DISPLAY=:0
/home/pi/appstart & startx



Some tutorials said I needed to perform the command "sudo chmod +x appstart" and to perform "sudo chmod 644 kegwasher.service" but I still get FAILURE.

To test I am running "sudo systemctl daemon-reload" and then "sudo systemctl start kegwasher.service" but my only result is FAILURE.

Can anyone tell me what I am doing wrong?
 
Last edited:


Update: it may have something to do with ~/.Xauthority. I read this question which says that not only DISPLAY needs to be set but my app also needs info from .Xauthority. I have added a line to my service file (unit file) as follows:

Environment=XAUTHORITY=/home/pi/.Xauthority

but still does not work!

In the link I referred to, the person answering said that systemd is meant for system processes and does not do well opening X window sessions. They said to use another daemon. I'm not super familiar with linux so if anyone has a suggestion of a different daemon to use, I'm all ears!
 

Staff online


Top