使用Systemd启动python脚本时出现的问题(代码=退出,状态= 2 / INVALIDARGUMENT)

时间:2019-04-15 18:24:02

标签: 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

我不知道为什么会出现语法错误,非常感谢您提供有关此问题的帮助。

1 个答案:

答案 0 :(得分:0)

您正在尝试使用py执行程序来运行bash文件。

需要阅读:

ExecStart=/usr/bin/python /home/pi/Systemd_test.py

假设,您的Python库位于/usr/bin/python