【问题标题】:Issues using Systemd to start a python script (code=exited, status=2/INVALIDARGUMENT)使用 Systemd 启动 python 脚本的问题(code=exited,status=2/INVALIDARGUMENT)
【发布时间】:2019-04-15 18:24:01
【问题描述】:

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

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

【问题讨论】:

    标签: linux raspberry-pi raspbian systemd


    【解决方案1】:

    您正在尝试使用bash exec 运行py 文件。

    需要阅读:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-24
      • 2020-12-18
      • 2022-08-17
      • 2022-11-02
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2022-12-01
      相关资源
      最近更新 更多