How to Run pygame script using systemd service?

随声附和 提交于 2019-12-10 19:37:16

问题


I Wanted to run pygame script using systemd service for that followed these steps to run a pygame script using systemd service

sudo systemctl daemon-reload sudo systemctl enable service_name sudo systemctl start service_name

and rebooted the system after that my-service don't want to run a pygame script for more understading

$ sudo journalctl -f -u rpi -- Logs begin at Thu 2016-11-03 22:46:42 IST. -- Mar 28 12:19:11 raspberrypi systemd[1]: Started RPi-Service.

$sudo systemctl status rpi rpi.service - RPi-Service Loaded: loaded (/lib/systemd/system/rpi.service; enabled; vendor preset: enabled) Active: inactive (dead) since Thu 2019-03-28 12:19:14 IST; 22min ago Process: 689 ExecStart=/home/pi/Documents/project1/allnewone (code=killed, signal=HUP) Main PID: 689 (code=killed, signal=HUP)

My Service File

#rpi.service
[Unit]
Description= RPi-Service
After = multi-user.target

[Service]
Type = simple
ExecStart = /usr/bin/python3  /home/pi/Documents/project1/allnewone.py
Restart = on-abort
RestartSec = 5
KillMode = process
SendSIGHUP = no


[Install]
WantedBy=multi-user.target

回答1:


Here is the solution


#rpi.service 
[Unit]
Description= RPi-Service
After = multi-user.target

[Service]
Type = simple
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart = /usr/bin/python3  /home/pi/Documents/project1/allnewone.py
Restart = always
RestartSec = 5
KillMode = process
SendSIGHUP = no


[Install]
WantedBy= graphical.target


来源:https://stackoverflow.com/questions/55392107/how-to-run-pygame-script-using-systemd-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!