0

I have a Django app running under CentOS 6. I want now to add an LSB script to make it running on startup. I googled the topic and didn't really find any intersting stuff.

Do you have some recommendations? some samples? some docs? best practices?

Regards

hzrari
  • 1,803
  • 1
  • 15
  • 26
  • A) What do you mean by LSB? Linux Standards Base? B) How are you running the Django app? Best practice is decidely not to run it with the dev server; if you're running it under apache, chkconfig is your friend to make apache (httpd) start on boot – Foon Oct 09 '14 at 15:17
  • currently I am running it: python manage.py runserver 0.0.0.0:8000 Yes LSB as Linux Standards Base. The app is not a production app at all, and I don't have any intention to put it in a production node. There is no apache, in front of it... and I don't want to install and configure one... However, even if, I place an apache, my question is how to start the Django application at startup? Behind an apache or not... – hzrari Oct 09 '14 at 16:24

1 Answers1

0

Apache way:

  1. Setup apache (sudo yum install httpd mod_wsgi)
  2. Configure apache to use your wsgi.py as described in the DJango docs
  3. /sbin/service httpd restart
  4. chkconfig httpd on #this causes apache to start on boot
  5. modify settings.py to put static files in /var/www/html/static and serve them as /static
  6. mkdir /var/www/html/static
  7. sudo python manage.py collectstatic; sudo chown -R apache:apache /var/www/html/static
  8. make sure your wsgi.py etc. is readable by apache
  9. point web browser at http://yourserver.com/

Exampel django.conf to go in /etc/httpd/conf.d

Alias /static/ /var/www/html/static/

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Foon
  • 6,148
  • 11
  • 40
  • 42
  • Thank you Foon for the answer, does that mean that mod_wsgi will take car of starting/stopping/restarting Django apps when apache start/stop/restart ? – hzrari Oct 10 '14 at 15:24
  • More or less. Note that if you make changes to your code while apache is running and you're in debug mode, it should reload but you may need to do an apache httpd reload. Also note that as far as I know, it doesn't really start django apps until you make a request from the browser – Foon Oct 10 '14 at 17:43