【问题标题】:Program fails as Linux systemctl service but runs when called directly程序作为 Linux systemctl 服务失败,但在直接调用时运行
【发布时间】:2020-10-22 04:03:30
【问题描述】:

我有一个脚本(网络监听器),它可以自行运行而没有问题:

> /usr/bin/python3 /home/[user]/scripts/CrossPlatform/workflow_trigger.py 

我已经有一个运行良好的不同服务。所以,我以新名称 /etc/systemd/system/my_workflow.service 复制了该文件:

Description=My Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/python3 /home/[user]/scripts/CrossPlatform/workflow_trigger.py

[Install]
WantedBy=multi-user.target

ExecStart 行是成功运行的命令的直接副本。

然后我运行:

systemctl daemon-reload
systemctl start my_service.service 

它在没有消息的情况下运行。不幸的是:

systemctl status my_service.service 

演出:

my_service.service - My Service
   Loaded: loaded (/etc/systemd/system/my_service.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Wed 2020-07-01 10:57:35 CDT; 958ms ago
  Process: 2722 ExecStart=/usr/bin/python3 /home/[user]/scripts/CrossPlatform/workflow_trigger.py (code=exited, status=1/FAILURE)
 Main PID: 2722 (code=exited, status=1/FAILURE)

操作系统是:

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"

什么可能是修复? 非常感谢, 波格丹

【问题讨论】:

    标签: linux service systemctl


    【解决方案1】:

    首先在 [service] 之后移动 ExecStart 并从服务中删除 user=root。在服务中也提到了 ExecStop。

    Description=My Service
    After=network.target
    StartLimitIntervalSec=0
    
    [Service]
    ExecStart=/usr/bin/python3 /home/[user]/scripts/CrossPlatform/workflow_trigger.py
    Type=simple
    Restart=always
    RestartSec=1
    
    [Install]
    WantedBy=multi-user.target
    

    【讨论】:

      【解决方案2】:

      这似乎是一个访问问题。该服务设置为以 User=root 身份运行,同时将数据(默认情况下)放到单个用户的文件夹中。将保存路径修复为更通用的目录或将用户更改为主文件夹的所有者可以解决此问题。

      【讨论】:

        猜你喜欢
        • 2021-11-04
        • 1970-01-01
        • 2017-08-27
        • 2016-06-09
        • 1970-01-01
        • 1970-01-01
        • 2019-02-16
        • 2014-09-05
        • 1970-01-01
        相关资源
        最近更新 更多