【问题标题】:How to Run pygame script using systemd service?如何使用 systemd 服务运行 pygame 脚本?
【发布时间】:2019-08-18 21:35:54
【问题描述】:

我想为此使用 systemd 服务运行 pygame 脚本 按照这些步骤使用 systemd 服务运行 pygame 脚本

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

并在 my-service 不想运行 pygame 脚本以了解更多信息后重新启动系统

$ 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)

我的服务文件

#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

【问题讨论】:

  • 我得到了答案,但现在我无法决定是否应该删除这个问题。这可能会帮助其他人
  • 如果您找到了解决方案,请随时发布答案。您甚至可以接受自己的答案。

标签: python-3.x pygame raspberry-pi3 systemd


【解决方案1】:

这里是解决办法


#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

【讨论】:

  • 事实上,只要您想使用 graphics_uI 并作为 systemd 运行或可能用于玉米作业,这个解决方案就会起作用
猜你喜欢
  • 2017-08-01
  • 2021-06-21
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
  • 2021-11-27
  • 2021-02-13
  • 2015-10-09
  • 2017-04-03
相关资源
最近更新 更多