I have a django application running in a virtual environment using supervisor . Supervisor is run by root and application is run by user ubuntu .
I want to check whether a database exist in postgres or not. My function below works well in normal python shell (Repl) and even when I run my application using python migrate.py runserver and even in django shell .
However as soon as I start the application using supervisor and that code block executes , I get the following exception -
Exception Type: OSError
Exception Value:[Errno 2] No such file or directory
Here's the function which is
def database_exists(database_name):
try:
db= "anydbname"
c1 = "psql -U postgres -lqt"
c2 = "cut -d | -f 1"
c3 = "grep -w " + db
ps1 = subprocess.Popen(c1.split(),stdout=subprocess.PIPE)
ps2 = subprocess.Popen(c2.split(),stdin=ps1.stdout, stdout=subprocess.PIPE)
ps3 = subprocess.Popen(c3.split(),stdin=ps2.stdout , stdout=subprocess.PIPE)
result = ps3.communicate()[0] # if empty , db not found
result = result.strip()
if result == "" :
return False
else :
return True
except Exception, e:
raise e
return False, str(e)
I failed to understand what is the exact directory or file it wants to find.Is it any kind of permission issue ? But even the normal shells are run using ubuntu user so doesn't seem to be permission error . How to debug it which file not found when run in supervisor ? I added the logs in supervisor but it only shows <request url > HTTP/1.0" 500 so no clues about it .
Here's the supervisor config
[program:myprog]
environment=PATH="/home/ubuntu/.virtualenvs/myvirtualenv/bin"
command=python /var/www/myapp/manage.py rungevent 127.0.0.1:8010 250
directory=/var/www/myapp
autostart=true
autorestart=true
redirect_stderr=True
killasgroup=true
stopasgroup=true
user=ubuntu
stdout_logfile = /var/log/supervisor/myapp.log
stderr_logfile = /var/log/supervisor/myapp-err.log
psqlcommand. Try giving complete path wherepsqlis present.