python - unable to start gunicorn with fabric -


my code lies in /home/ubuntu/api in remote server. wsgi object named app , present in /home/ubuntu/api/api.py. gunicorn conf file called gunicorn.conf.py , present in /home/ubuntu/api

my gunicorn.conf.py

import multiprocessing  bind = "127.0.0.1:8000" workers = multiprocessing.cpu_count() * 2 + 1 backlog = 2048 worker_class = 'gevent' daemon = true debug = true loglevel = 'debug' accesslog = '/mnt/log/gunicorn_access.log' errorlog = '/mnt/log/gunicorn_error.log' max_requests = 1000 graceful_timeout = 20 

i trying start gunicorn on server remotely through fabric. fabric code looks this

@roles('stag_api') def run_server():     cd('/home/ubuntu/api'):         sudo('gunicorn -c gunicorn.conf.py api:app') 

now fabric not show error gunicorn not start.

so created __init__.py in /home/ubuntu/api make package. wrote in __init__.py file

from api import app 

this makes wsgi app available in package's namespace. changed fabric code this

@roles('stag_api') def run_server():     sudo('gunicorn -c /home/ubuntu/api/gunicorn.conf.py api:app') 

even fabric not show error gunicorn not start.

so created shell script called server , code looks this

if [ "$1" = "start" ];         echo 'starting'         gunicorn -c /home/ubuntu/api/gunicorn.conf.py api:app fi  if [ "$1" = "stop" ];         echo 'stopping'         pkill gunicorn fi  if [ "$1" = "restart" ];         echo 'restarting'         pkill gunicorn         gunicorn -c /home/ubuntu/api/gunicorn.conf.py api:app fi 

i place shell script in /home/ubuntu/api

now fabric code looks

@roles('stag_api') def stag_server(action='restart'):     if action not in ['start', 'stop', 'restart']:         print 'not valid action. valid actions start, stop , restart'         return     sudo('./server %s' % action) 

now when try start server through fabric print starting shell script executing , if block reached still not able start server through fabric.

but if ssh server , sudo ./server start, gunicorn starts.

can explain doing wrong?

it's related these 2 faq points:

http://www.fabfile.org/faq.html#init-scripts-don-t-work

http://www.fabfile.org/faq.html#why-can-t-i-run-programs-in-the-background-with-it-makes-fabric-hang


Comments