systemd 服务无法启动 bash 脚本

systemd service failed to start bash script

我正在 运行将 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 脚本是 运行ning 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

我该如何解决这个问题?

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

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

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