I am seeking help with the following. I want a python script that includes a Pygame gui to run at startup without the need to log in. I am running a Raspberry Pi 4 with a RPI touch screen.
The script works fine when I enable auto-login in raspi-config.
The systemd config file I use (/etc/systemd/system/SecurityPanel.service):
[Unit]
Description=SecurityPanel
After=multi-user.target
[Service]
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
ExecStart=/usr/bin/python3 /home/pi/SecurityPanel/main.py
Restart=always
RestartSec=10s
KillMode=process
TimeoutSec=infinity
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=SecurityPanel
User=root
Group=root
[Install]
WantedBy=multi-user.target
Setting the user was my latest attempt, without success. I also tried to use graphical.target, also without success.
The error I get (journalctl):
Jan 06 19:35:56 raspberrypi systemd[1]: Started SecurityPanel.
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: Invalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: Traceback (most recent call last):
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: File "/home/pi/SecurityPanel/main.py", line 116, in <module>
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: ui = UI()
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: File "/home/pi/SecurityPanel/SecurityPanel/ui.py", line 59, in __init__
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: pygame.init()
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: File "/home/pi/SecurityPanel/main.py", line 86, in sig_end_SC
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: end_SC()
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: File "/home/pi/SecurityPanel/main.py", line 78, in end_SC
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: ts.stop()
Jan 06 19:35:57 raspberrypi SecurityPanel[605]: NameError: name 'ts' is not defined
Jan 06 19:35:58 raspberrypi SecurityPanel[605]: pygame 1.9.4.post1
Jan 06 19:35:58 raspberrypi SecurityPanel[605]: Hello from the pygame community. https://www.pygame.org/contribute.html
Jan 06 19:35:58 raspberrypi SecurityPanel[605]: starting output to /home/pi/SecurityPanel/logs/SC9.log
Jan 06 19:35:58 raspberrypi systemd[1]: SecurityPanel.service: Main process exited, code=exited, status=1/FAILURE
Jan 06 19:35:58 raspberrypi systemd[1]: SecurityPanel.service: Failed with result 'exit-code'.
Jan 06 19:36:08 raspberrypi systemd[1]: SecurityPanel.service: Service RestartSec=10s expired, scheduling restart.
Jan 06 19:36:08 raspberrypi systemd[1]: SecurityPanel.service: Scheduled restart job, restart counter is at 1.
Jan 06 19:36:08 raspberrypi systemd[1]: Stopped SecurityPanel.
Output who:
pi pts/0 Jan 6 20:03 (<MY_IP>)
Output echo $DISPLAY
<nothing>
Host +local:
not found: 3(NXDOMAIN)
I think the latter is the issue, but no clue how to resolve it...
Any help would be very much appreciated!
Thanks, J
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…