0
votes

Hi guys I have a head ache running this as a service I am really stuck here and have wasted quite the hours here, i am on ubuntu 20 LTS.

I have a celery worker which is waiting for an audio to transform using ffmpeg python library.

If I run it like this:

source venv/bin/activate && Celery -A tasks worker -l info It works without a problem and complete the tasks.

but when I run it as a service in systemd I get this error:

[Errno 20] Not a directory: 'ffmpeg'
                                              Traceback (most recent call last):
                                                File "/home/ubuntu/p1-react-flask-app/app/tasks.py", line 58, in transform_audio_format
                                                  output.run()
                                                File "/home/ubuntu/p1-react-flask-app/app/venv/lib/python3.8/site-packages/ffmpeg/_run.py", line 313, in run
                                                  process = run_async(
                                                File "/home/ubuntu/p1-react-flask-app/app/venv/lib/python3.8/site-packages/ffmpeg/_run.py", line 284, in run_async
                                                  return subprocess.Popen(
                                                File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
                                                  self._execute_child(args, executable, preexec_fn, close_fds,
                                                File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
                                                  raise child_exception_type(errno_num, err_msg, err_filename)
                                              NotADirectoryError: [Errno 20] Not a directory: 'ffmpeg'

I really do not know why and have tried different ways. python os can access the audio folder and files without problem but the problem here, I think, is that my systemd service does not find ffmpeg.exe, but how do I specify it to my service?

My celery config file:

# The names of the workers. This example create one worker
CELERYD_NODES="worker1"

# The name of the Celery App, should be the same as the python file
# where the Celery tasks are defined
CELERY_APP="tasks"

# Log and PID directories
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Log level
CELERYD_LOG_LEVEL=INFO

# Path to celery binary, that is in your virtual environment
CELERY_BIN=/home/ubuntu/venv/bin/celery

# Options for Celery Beat
CELERYBEAT_PID_FILE="/var/run/celery/beat.pid"
CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"

my celeryd.service:

[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=ubuntu
Group=ubuntu
EnvironmentFile=/etc/default/celeryd
WorkingDirectory=/home/ubuntu/p1/app
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
--pidfile=${CELERYD_PID_FILE}'
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

[Install]
WantedBy=multi-user.target

My python code:

@app.task
def transform_audio_format(url_original,url_destiny):
    input = ffmpeg.input(url_original)
    
    output = ffmpeg.output(input,url_destiny,shell=True)

    output.run()

any help would be appreciated.

UPDATE:

I added to my .service file: Environment="PATH=/home/ubuntu/p1-react-flask-app/app:/usr/local/bin"

but nothing changed.

then I tried with:

Environment="PATH=/home/ubuntu/p1-react-flask-app/app:/usr/bin" and got:

ffmpeg error (see stderr output for detail)
                                              Traceback (most        recent call last):
                                                File "/home/ubuntu/p1-react-flask-app/app/tasks.py", line 58, in transform_audio_format
                                                  output.run()
                                                File "/home/ubuntu/p1-react-flask-app/app/venv/lib/python3.8/site-packages/ffmpeg/_run.py", line 325, in run
                                                  raise Error('ffmpeg', out, err)
                                              ffmpeg._run.Error: ffmpeg error (see stderr output for detail)

I do not know what to do.

There are multiple ffmpeg libraries on PyPI; which one exactly are you using? github.com/kkroening/ffmpeg-python this one? Or pypi.org/project/python-ffmpeg this?tripleee
What's with the shell=True?tripleee