Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run Django as a service?

I am having difficulty running Django on my Ubuntu server. I am able to run Django but I don't know how to run it as a service.

Distributor ID:    Ubuntu
Description:       Ubuntu 10.10
Release:           10.10
Codename:          maverick

Here is what I am doing:

  1. I log onto my Ubuntu server
  2. Start my Django process: sudo ./manage.py runserver 0.0.0.0:80 &
  3. Test: Traffic passes and the app displays the right page.
  4. Now I close my terminal window and it all stops. I think I need to run it as a service somehow, but I can't figure out how to do that.

How do I keep my Django process running on port 80 even when I'm not logged in?

Also, I get that I should be linking it through Apache, but I'm not ready for that yet.

like image 425
codingJoe Avatar asked May 04 '12 17:05

codingJoe


1 Answers

Don't use manage.py runserver to run your server on port 80. Not even for development. If you need that for your development environment, it's still better to redirect traffic from 8000 to 80 through iptables than running your django application as root.

In django documentation (or in other answers to this post) you can find out how to run it with a real webserver.

If, for any other reason you need a process to keep running in background after you close your terminal, you can't just run the process with & because it will be run in background but keep your session's session id, and will be closed when the session leader (your terminal) is terminated.

You can circunvent this behaviour by running the process through the setsid utility. See your manpage for setsid for more details.

like image 90
Miguel Ventura Avatar answered Oct 09 '22 14:10

Miguel Ventura