【问题标题】:systemd service failed to start bash scriptsystemd 服务无法启动 bash 脚本
【发布时间】:2019-02-08 12:15:19
【问题描述】:

我正在运行一个 bash 脚本作为 systemd 服务,但它给了我这个错误

Failed at step EXEC spawning /home/pipeline/entity-extraction/start_consumer.sh: Permission denied Feb 8 11:59:58 irum systemd[1]: ee-consumer.service: main process exited, code=exited, status=203/EXEC Feb 8 11:59:58 irum systemd[1]: Unit ee-consumer.service entered failed state. 我的 bash 脚本正在运行 2 个 Python 脚本,当我从终端以
sudo bash start_consumer.sh 运行它时,它运行良好
start_consumer.sh

while true
do
    echo "starting FIRST Consumer.py : $(date +"%T")"
    python3 /home/irum/Desktop/Marketsyc/Consumer.py &
    pid=$!
    echo "pid:$pid"
    sleep 60

    echo "starting SECOND Consumer.py : $(date +"%T")"
    python3 /home/irum/Desktop/Marketsyc/Consumer.py &
    new_pid=$!
    echo "new_pid:$new_pid"
    # Here I want to kill FIRST Consumer.py
    echo "killing first consumer"
    kill "$pid"
    sleep 60

    # Here I want to kill SECOND Consumer.py
    echo "killing second consumer"
    kill "$new_pid"
done

我的 systemd 服务代码 ee-consumer.service

[Unit]
Description=Entity extraction - consumer
After=default.target
[Service]
Type=simple
Restart=always
User=pipeline
ExecStart=/home/pipeline/entity-extraction/start_consumer.sh

我该如何解决这个问题?

【问题讨论】:

标签: python linux bash systemd


【解决方案1】:

您必须将shebang 行和permission 设置为脚本,systemd 才能执行。

#!/bin/bash 添加到 bash 脚本的开头。并执行以下操作,

chmod 755 /home/pipeline/entity-extraction/start_consumer.sh

【讨论】:

  • PermissionError: [Errno 13] Permission denied: '/data/runtime/run/ee-consumer-B.pid' 现在我收到此错误。那是我的 Consumer.py 脚本写入 PID 的文件
  • 检查/data/runtime/run/ 目录中的persmissionls -l /data/runtime/run/
  • -rw-r--r-- 1 pipeline pipeline 5 Feb 8 12:23 ee-aggregator.pid -rwxr-xr-x 1 root root 6 Feb 8 10:32 ee-consumer-B.pid -rw-r--r-- 1 root root 6 Feb 8 09:03 ee-consumer.pid -rw-r--r-- 1 pipeline pipeline 6 Feb 8 12:26 ee-dbwriter.pid 两个消费者的pid文件都有root权限
  • 好的。问题是您没有指定应该使用哪个用户来运行这个 bash 脚本。在ee-consumer.service 文件中的[Service] 行之后放置User=root
猜你喜欢
  • 1970-01-01
  • 2015-11-17
  • 2017-08-17
  • 2020-05-11
  • 1970-01-01
  • 2018-06-07
  • 1970-01-01
相关资源
最近更新 更多