I’m encountering a FileNotFound error when running my Flask app with Supervisor. The code works fine when running the Flask app normally. Below is my Supervisor configuration and the Python code snippet:
Supervisor Configuration:
[supervisord]
[program:app_server]
directory=/home/user/project/directory
user=username
command=/bin/bash -c 'cd /home/user/project/directory/src && export PATH=$PATH && source ../venv/bin/activate && export APP_ENV=local && gunicorn --bind 0.0.0.0:5000 main:application'
autostart=true
autorestart=true
stderr_logfile_maxbytes=5MB
stderr_logfile=/home/user/project/my-files/app-server_error.log
stdout_logfile_maxbytes=5MB
stdout_logfile=/home/user/project/my-files/app-server_output.log
Python Code Snippet:
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
In the command, I’m trying to run a CLI tool command. I attempted to move that CLI executable file to the project directory, but it didn’t work. Also, I have a Celery worker which also uses the same CLI tool, and it works fine. I’m getting the error in the Flask API only where I’m executing the command with subprocess.
Celery Worker Configuration:
[program:celery_worker]
user=username
command=/bin/bash -c 'cd /home/user/project/directory/src && source ../venv/bin/activate && export APP_ENV=local && celery --app app.celery worker --loglevel=info --queues celery-local.fifo --max-tasks-per-child=20 --concurrency=4'
autostart=true
autorestart=true
stderr_logfile_maxbytes=5MB
stderr_logfile=/home/user/project/my-files/celery_worker_error.log
stdout_logfile_maxbytes=5MB
stdout_logfile=/home/user/project/my-files/celery_worker_output.log
How can I resolve this FileNotFound error when using Supervisor to run my Flask app?