【问题标题】:Systemd script not running python script with config.iniSystemd 脚本未使用 config.ini 运行 python 脚本
【发布时间】:2021-02-13 02:53:22
【问题描述】:

我在创建一个我不理解的 systemd 服务时出错。

我在 rpi 上运行了一个用于空气质量的 python 脚本。我使用以下代码运行它:

python3 senddata.py "./config.ini"

这运行正确;但是,我想让它成为一个 systemd 服务,以便以后设置一个 cron 作业。我起草了这个:

[Unit]
Description=aqi
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/.../senddata.py "./config.ini"

[Install]
WantedBy=multi-user.target

当我运行它时,我重新加载守护程序并重新启动服务,但收到以下错误:

python3[...]: KeyError parsing config.ini file.

尝试运行时是否不理解我对 config.ini 的引用?

谢谢!

资源: https://ayeks.de/post/2018-05-29-bme680-influxdb-grafana/ https://github.com/ayeks/bme680_to_influxdb/blob/master/grafana_dashboard.json

【问题讨论】:

  • 放上config.ini文件的完整路径

标签: python-3.x linux cron raspberry-pi systemd


【解决方案1】:

出于好奇 - 我只使用“ls”创建了一个自定义服务 - 在使用 systemctl 启动服务时查看当前目录是哪个目录。

系统日志中的输出让我相信它是以“/”开头的当前目录。我从 /etc/systemd/system 执行了 'systemctl start test' - 而不是在 "/"..

[Unit]
Description=aqi
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/ls

[Install]
WantedBy=multi-user.target



Oct 30 13:11:40 oelinux2 ls[1951]: bin
Oct 30 13:11:40 oelinux2 ls[1951]: boot
Oct 30 13:11:40 oelinux2 ls[1951]: dev
Oct 30 13:11:40 oelinux2 ls[1951]: etc
Oct 30 13:11:40 oelinux2 ls[1951]: home
Oct 30 13:11:40 oelinux2 ls[1951]: lib
Oct 30 13:11:40 oelinux2 ls[1951]: lib64
Oct 30 13:11:40 oelinux2 ls[1951]: media
Oct 30 13:11:40 oelinux2 ls[1951]: mnt
Oct 30 13:11:40 oelinux2 ls[1951]: opt
Oct 30 13:11:40 oelinux2 ls[1951]: proc
Oct 30 13:11:40 oelinux2 ls[1951]: root
Oct 30 13:11:40 oelinux2 ls[1951]: run
Oct 30 13:11:40 oelinux2 ls[1951]: sbin
Oct 30 13:11:40 oelinux2 ls[1951]: srv
Oct 30 13:11:40 oelinux2 ls[1951]: sys
Oct 30 13:11:40 oelinux2 ls[1951]: tmp
Oct 30 13:11:40 oelinux2 ls[1951]: usr
Oct 30 13:11:40 oelinux2 ls[1951]: var

ls 命令在同一台机器上来自 /

[root@oelinux2 /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@oelinux2 /]#

我的第一个想法..是将“./config”更改为“config”所在位置的完整路径。试试看能不能找到。

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2012-11-15
    • 2015-01-06
    • 1970-01-01
    • 2019-08-18
    • 2020-11-20
    相关资源
    最近更新 更多