systemd 服务未在启动时启动,在我重新启动时启动 [英] systemd service not starting on boot, starts when i restart it

查看:90
本文介绍了systemd 服务未在启动时启动,在我重新启动时启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了这个服务文件来在我的树莓派 (4) 启动时启动一个 python 脚本:

I have made this service file to start a python script when my raspberry pi (4) boots up:

/etc/systemd/system/plants.service

[Unit]                                    
Description=plant-sender                                    
After=network.target                                    

[Service]
Type=simple                                    
User=root                                    
Group=root                                    
WorkingDirectory=/home/theo/Repos/plants-monitor/remote                                    
ExecStart=/usr/bin/python main.py                                    
Restart=on-failure                                    

[Install]                                    
WantedBy=multi-user.target

然而,一旦 pi 开启,我运行 sudo systemctl status Plants,然后得到:

However, once the pi is on, I run sudo systemctl status plants, and get:

* plants.service - plant-sender
     Loaded: loaded (/etc/systemd/system/plants.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Mon 2020-03-30 20:22:43 EDT; 1min 45s ago
    Process: 323 ExecStart=/usr/bin/python main.py (code=exited, status=1/FAILURE)
   Main PID: 323 (code=exited, status=1/FAILURE)

Mar 30 20:22:43 arpi systemd[1]: plants.service: Scheduled restart job, restart counter is at 5.
Mar 30 20:22:43 arpi systemd[1]: Stopped plant-sender.
Mar 30 20:22:43 arpi systemd[1]: plants.service: Start request repeated too quickly.
Mar 30 20:22:43 arpi systemd[1]: plants.service: Failed with result 'exit-code'.
Mar 30 20:22:43 arpi systemd[1]: Failed to start plant-sender.

但是,在运行 sudo systemctl restart Plants 后,服务启动并且一切正常.

But, after running sudo systemctl restart plants, the service starts up and everything is fine.

推荐答案

如果它在启动时没有启动,但在 systemctl restart启动,我会寻找/home/theo/Repos/plants-monitor/remote 是否安装在那个点.

If it doesn't start on boot but does on systemctl restart, I'd be looking at whether /home/theo/Repos/plants-monitor/remote is mounted at that point.

登录时可能会自动挂载或主目录挂载您的主目录.

There may be something automounting or home-mounting your home directory when you log in.

如果是这样,您可以将工作目录更改为始终存在的目录,即使只是一个测试.

If so, you could change the working directory to something that exists always, even if only a test.

此外,使用 journalctl -n 9999 -u Plants 会为您提供更多日志消息,因此您可以了解为什么失败,而不仅仅是看到尝试过"很多次,放弃"消息.

Additionally, using journalctl -n 9999 -u plants will get you more log messages, so you can see why it's failing, rather than just seeing the "tried too many times, giving up" messages.

这篇关于systemd 服务未在启动时启动,在我重新启动时启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆