Systemd 脚本不是 运行 python 脚本 config.ini
Systemd script not running python script with config.ini
我在创建我不理解的 systemd 服务时遇到错误。
我 运行 一个 python rpi 空气质量脚本。我 运行 使用以下代码:
python3 senddata.py "./config.ini"
这个运行正确;但是,我想让它成为一个系统服务,以便稍后设置一个 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
出于好奇 - 我只用 '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' 所在位置的完整路径。试一下,看看能不能找到。
我在创建我不理解的 systemd 服务时遇到错误。
我 运行 一个 python rpi 空气质量脚本。我 运行 使用以下代码:
python3 senddata.py "./config.ini"
这个运行正确;但是,我想让它成为一个系统服务,以便稍后设置一个 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
出于好奇 - 我只用 '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' 所在位置的完整路径。试一下,看看能不能找到。