linux - Program fails as Linux systemctl service but runs when called directly
问题描述
I have a script (a web listener) which runs on its own without problem:
> /usr/bin/python3 /home/[user]/scripts/CrossPlatform/workflow_trigger.py
I already have a different service that works well. So, I copied that file under a new name /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
The ExecStart line is a direct copy of the command that runs successfully.
I then run:
systemctl daemon-reload
systemctl start my_service.service
It runs without a message. Unfortunately:
systemctl status my_service.service
Shows:
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)
The OS is:
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
What might be a fix? Many thanks, Bogdan
解决方案
首先在 [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
推荐阅读
- scip - SCIP:孩子vs父母vs兄弟姐妹
- typescript - 条件类型和在 typescript 中推断以减少 redux 样板
- java - 基于spring配置文件导入bean资源
- swift - 如何断言结构符合协议?
- python - 如何使用 BrowserStack Appium 和 Python 创建移动自动化应用程序测试?
- python-3.x - 获取在消息上添加表情符号的用户列表
- scheduling - 活动运行的 iCalendar 重复规则:每两周,周一和周三,活动一天内的每 30 分钟?
- php - PHP - 从连接数组中删除键
- reactjs - 以用户身份从前端下载图像(我有链接)?
- go - 当 NextDecoder 依赖于上一层而不是当前层时,如何正确编写自定义层?