1

I am running a bash script as systemd service but it is giving me this error

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. My bash scrip is running 2 Python scripts and it runs fine when I run it from terminal as
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

code of my systemd service 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

how can I resolve this issue ?

2
  • Possible duplicate of linux start up script in systemd Commented Feb 8, 2019 at 12:26
  • @jww No it's not. I am facing a different problem. Kindly, re read my question. Commented Feb 12, 2019 at 7:07

1 Answer 1

3

You have to set the shebang line and permission to the script, for systemd to execute.

Add #!/bin/bash to the start of the bash script. And do the following,

chmod 755 /home/pipeline/entity-extraction/start_consumer.sh
Sign up to request clarification or add additional context in comments.

4 Comments

PermissionError: [Errno 13] Permission denied: '/data/runtime/run/ee-consumer-B.pid' Now I am getting this error. That's the file where my Consumer.py script writes PID
Check the persmission on the /data/runtime/run/ directory. ls -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 both consumer's pid files has root permission
Okay. The problem is you have not specified which user should be used to run this bash script. Put User=root after the line [Service] in the ee-consumer.service file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.