linux - 使用 Systemd 启动 python 脚本的问题(code=exited,status=2/INVALIDARGUMENT)

标签 linux raspberry-pi raspbian systemd

我目前正在尝试在我使用引导的 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/

相关文章:

python - Python 中的 Raspberry PI 服务器/客户端套接字

node.js - wifi 掉线时本地套接字绑定(bind)失败

linux - nginx: [emerg] 未知指令 ""在/etc/nginx/sites-enabled/example.com:3

linux - 编写脚本以删除服务器上 7 天前的文件

python - 在 Ubuntu 上使用 python MSS 库时出现 XGetImage Failed 错误

python - 树莓派运行时错误 : Conflicting edge detection already enabled for this GPIO channel

r - 在 Wheezy 7.8 (Raspbian) 上安装 R 3.1.2 失败

ssh - Raspberry Pi 在重启时不会终止 SSH 连接

c++ - 如何实现shell的作业控制

c - 确定网络接口(interface)是无线的还是有线的