我正在运行一个 bash 脚本作为 systemd 服务,但它给了我这个错误
在步骤 EXEC 生成/home/pipeline/entity-extraction/start_consumer.sh 时失败:权限被拒绝
Feb 8 11:59:58 irum systemd[1]:ee-consumer.service:主进程退出,代码=退出,状态=203/EXEC
Feb 8 11:59:58 irum systemd[1]:单元 ee-consumer.service 进入失败状态。
我的 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
我该如何解决这个问题?
最佳答案
您必须为脚本设置 shebang
行和 permission
,systemd 才能执行。
将 #!/bin/bash
添加到 bash 脚本的开头。并执行以下操作,
chmod 755 /home/pipeline/entity-extraction/start_consumer.sh
关于python - systemd 服务无法启动 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54592279/