【问题标题】:Systemd service wont execute at bootSystemd 服务不会在启动时执行
【发布时间】:2020-04-02 12:14:30
【问题描述】:

我已经使用 systemd 创建了自己的服务。它应该在启动时运行一次 python 脚本。它会发送一封带有 IP 地址和 Teamviewer id 的电子邮件,这就是为什么我会延迟处理它,否则我会收到无法解析邮件服务器域的错误消息。由于 30 秒的延迟,脚本应该在后台运行。 该脚本位于 /usr/bin/glatv.py 并且是可执行的,脚本运行没有问题。该构造在带有 Raspian Buster 的 Raspberry Pi4 上运行 2020-02-13

Service 位于 /etc/systemd/system/ 中,可以执行和启用:

[Unit]
Description=My Own Service

[Service]
Type=oneshot
ExecStart=/usr/bin/glatv.py &

[Install]
WantedBy=reboot.target

但是

systemctl start myservice 

工作没有问题

 ● glatvd.service - My Own Service
   Loaded: loaded (/etc/systemd/system/glatvd.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

Apr 02 12:52:31 raspberrypi systemd[1]: Starting My Own Service...
Apr 02 12:53:02 raspberrypi systemd[1]: glatvd.service: Succeeded.
Apr 02 12:53:02 raspberrypi systemd[1]: Started My Own service.

重启后没有通话或日志

【问题讨论】:

    标签: linux service systemd raspberry-pi4


    【解决方案1】:

    不要有任意的 30 秒延迟,而是将其添加到您的服务文件中:

    After=network-online.target
    Wants=network-online.target
    

    【讨论】:

      【解决方案2】:

      您应该尝试运行此命令以使您的服务能够在重启后运行

      systemctl enable myservice
      

      对于日志,我相信您必须将此参数放入服务的配置文件中

      StandardOutput=/path/to/info/log/info_log.log
      StandardError=/path/to/error/log/error_log.log
      

      我得到了这个参考:How to redirect output of systemd service to a file

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-10
        • 2017-05-07
        • 1970-01-01
        • 2021-01-08
        • 2020-07-01
        • 2017-08-11
        相关资源
        最近更新 更多