1

I'm trying to follow the tutorial at http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. I am working with an ubuntu 14.4 instance on amazon EC2. I'm trying to deploy a django app I've developed locally with python3. So far I've got the app working following the tut as long as I manually ssh in , turn on the virtualenv and then turn on uwsgi, using :

workon env1
uwsgi --ini /home/ubuntu/mysite_uwsgi.ini

I noticed however that when I tried to send a request to the app this morning, that I was getting:

errno 5 input/output error

This was solved my manually sshing in and executing the 2 lines above. I don't understand how this works exactly , but somehow my virtualenv and uwsgi were deactivated after I logged off. I need to keep them active so that all requests can be funneled to my app. I don't know how to do this. Following the tut above , I've modified /etc/rc.local to:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.    

workon myenv
uwsgi --ini /home/ubuntu/mysite_uwsgi.ini    


exit 0

Will this solve my problem. If not what should I do?

Community
  • 1
  • 1
user1592380
  • 34,265
  • 92
  • 284
  • 515
  • I doubt EC2 instances `sleep` or terminate automatically. You should give `gunicorn` a try, which has a daemon mode so you can disconnect from your SSH connection and still have it running in the background. Very easy to set up too http://docs.gunicorn.org/en/latest/index.html – Kedar Mar 07 '15 at 18:38

2 Answers2

1

You can daemonize the process:

env = DJANGO_SETTINGS_MODULE=mysite.settings # set an environment variable
pidfile = /tmp/project-master.pid # create a pidfile
harakiri = 20 # respawn processes taking more than 20 seconds
limit-as = 128 # limit the project to 128 MB
max-requests = 5000 # respawn processes after serving 5000 requests
"uwsgi --ini uwsgi.ini --daemonize=/var/log/yourproject.log # background the
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
0

If you've followed the rest of the doc and are ready to run in "emperor" mode, add this to /etc/rc.local before exit 0:

/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
dylrei
  • 1,728
  • 10
  • 13
  • Hi, I'd love to set up emperor mode, but I ran into a problem : http://stackoverflow.com/questions/28903269/uwsgi-importerror-no-module-named-site-on-ubuntu – user1592380 Mar 07 '15 at 19:34