mohit
mohit

Reputation: 2469

Python/django application not running with supervisord

I am trying to run Python Django app via supervisor with below configuration file.

[program:test3]
command=python manage.py runserver
directory=/home/ubuntu/code/example/current/project/
stdout_logfile=/var/log/test3.log
stderr_logfile=/var/log/test3.log
user=ubuntu
environment=PATH="/home/ubuntu/code/example/bin/",PROJECT_ENV="dev"
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600e
autorestart=true
startsecs=10
stopwaitsecs=600

After running I was able to see there are 2 python process running at the moment.

ubuntu   29853  0.1  2.0 354468 41196 ?        Sl   11:33   0:00 python manage.py runserver
ubuntu   29860  1.1  3.4 516944 69768 ?        Sl   11:33   0:04 /home/ubuntu/code/analytics/bin/python manage.py runserver

I have mentioned the log file under supervisord config file and was able to see the below error in "/var/log/test3.log".

Error:

ImportError: No module named pyspark.ml.evaluation

I have already fulfilled all pip requirements in the directory.

Any idea?

Upvotes: 0

Views: 1287

Answers (2)

Dalvtor
Dalvtor

Reputation: 3286

Did you install the dependencies in a virtual environment?

If so, you also need execute the python manage.py runserver command with the environment activated.

I would create a simple script that activates the virtual environment and executes the command, and then, in supervisor, just run that script.

In your supervisor config file, change the command to:

command=/usr/local/bin/run_local_server.sh

Then, create the run_local_server.sh script which first activates the virtual environment and then executes the python manage.py runserver command.

For example:

#!/bin/bash
source env/bin/activate
cd project_folder
python manage.py runserver

Also, you can specify the pythonpath in supervisor: pythonpath = '/opt/myenv/myproject' if needed.

Upvotes: 1

eugene
eugene

Reputation: 41765

Do you use virtual environment?

If that's the case, try using the python executable in the virtual environment.

i.e. change the line in the supervisor conf flie

..path/to/virtualenv/bin/python manage.py runserver

supervisor might execute the line with different user or in newly created shell process.
In either case, your VE python is not used, but systematically installed one is used.

Upvotes: 0

Related Questions