我目前正在尝试在我使用引导的 Raspberry Pi 3 时启动程序。该程序控制一架无人机,在启动前需要网络连接。当我尝试使用 Systemd 启动此程序时,我收到此错误消息;
droneStartup.service - The Drone Startup service.
Loaded: loaded (/etc/systemd/system/droneStartup.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-04-15 14:06:24 EDT; 1s ago
Process: 1895 ExecStart=/bin/bash /home/pi/Systemd_test.py (code=exited, status=2)
Main PID: 1895 (code=exited, status=2)
Apr 15 14:06:24 pi systemd[1]: Started The Drone Startup service..
Apr 15 14:06:24 pi bash[1895]: from: can't read /var/mail/time
Apr 15 14:06:24 pi bash[1895]: /home/pi/Systemd_test.py: line 4: syntax error near unexpected token `'Looping...''
Apr 15 14:06:24 pi bash[1895]: /home/pi/Systemd_test.py: line 4: ` print('Looping...')'
Apr 15 14:06:24 pi systemd[1]: droneStartup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 15 14:06:24 pi systemd[1]: droneStartup.service: Unit entered failed state.
Apr 15 14:06:24 pi systemd[1]: droneStartup.service: Failed with result 'exit-code'.
这是我用来测试启动的占位符程序;
from time import sleep
while True :
print('Looping...')
sleep(1)
这是我正在使用的 .service 文件;
[Unit]
Description=The Drone Startup service.
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/bin/bash /home/pi/Systemd_test.py
[Install]
WantedBy=multi-user.target
我不知道它为什么会出现语法错误,非常感谢任何对此问题的帮助。
最佳答案
您正在尝试使用 bash
exec 运行 py
文件。
需要阅读:
ExecStart=/usr/bin/python /home/pi/Systemd_test.py
假设您的 Python 库位于 /usr/bin/python
关于linux - 使用 Systemd 启动 python 脚本的问题(code=exited,status=2/INVALIDARGUMENT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55695180/