Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Gunicorn/Nginx #73

Merged
merged 7 commits into from Nov 13, 2014
Merged

Conversation

hectcastro
Copy link
Contributor

This changeset makes Gunicorn the application server for Django across environments. In addition, Upstart handles launching the Gunicorn worker pool and Nginx reverse proxies requests to it.

It is also important to note that when the application is provisioned in the development and test environments, the Gunicorn --reload flag is used. This provides automatic Gunicorn worker reloads when code changes occur. I tested application reloading by making source code changes via the Vagrant shared folder and worker PIDs changed as expected.

For more discussion, see: #71

listen *:80;
server_name _;

root {{ app_home }}/static;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, what does root do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets the static files directory as the web root for this site configuration. This works with try_files to determine if a file exists before passing the request through the proxy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. The static directory isn't the right directory to serve static assets from though. static/ is where I intend gulp to put them into, once we wire it in place, but they'll get collected into assets/ (though an open PR of mine changes this to the more obviously named collected_static/)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this needs to change to /assets?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was a little unclear. My PR is merged, so this should change to collected_static/

@maurizi
Copy link
Contributor

maurizi commented Nov 10, 2014

+1

I was on the fence about this, but I've been convinced.
Hopefully this helps us avoid some bugs that only appear in gunicorn.

BTW, you should probably change the README to remove references to runserver

user: name=nyc-trees
system=yes
createhome=no
shell=/bin/false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're curious, I took a look at the desirability of setting shell= to /bin/false, /dev/null, and /sbin/nologin, because I'd seen /dev/null here in the past.
http://serverfault.com/questions/519215/what-is-the-difference-between-sbin-nologin-and-bin-false

Didn't come up with anything that is best by test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some good detail in there.

I've been using /bin/false for a while and was only recently (in the past few years) exposed to /sbin/nologin. My decision to go with /bin/false has a lot to do with its use by existing UNIX accounts:

vagrant@app:~$ cat /etc/passwd | grep false
syslog:x:101:104::/home/syslog:/bin/false
messagebus:x:102:106::/var/run/dbus:/bin/false
landscape:x:103:109::/var/lib/landscape:/bin/false
pollinate:x:105:1::/var/cache/pollinate:/bin/false
statd:x:106:65534::/var/lib/nfs:/bin/false
puppet:x:107:112:Puppet configuration management daemon,,,:/var/lib/puppet:/bin/false
ntp:x:108:113::/home/ntp:/bin/false
colord:x:109:115:colord colour management daemon,,,:/var/lib/colord:/bin/false
nyc-trees:x:999:999::/home/nyc-trees:/bin/false

That said, there are several that make use of /usr/sbin/nologin too. ¯\_(ツ)_/¯

@steventlamb
Copy link
Contributor

+1

@steventlamb
Copy link
Contributor

Whoops, I intended to push a branch of the same name to my (not yet existent) fork, and I instead pushed commits onto @hectcastro's branch. Sorry for the inconvenience. If we end up keeping them, we can just merge. If not, I can do some git cleaning.

I pulled down this branch and everything appeared to work, but some of the gunicorn options (including ones that were suggested by me) are not supported by version 1.19, and/or did not produce the desired affect. I updated the config and also moved it to a new file. I can now use gunicorn interactively by running the included script.

@hectcastro
Copy link
Contributor Author

Does it make sense to keep the Gunicorn configuration trim and within the Upstart script leaving pdb or ipdb support as a special case that still occurs via runserver? Don't know how the debugger is used with Django, but I only find myself reaching for the debugger when I'm in a tough spot, and at that point I'm digging into something specific in the application code vs. the framework around it.

@maurizi
Copy link
Contributor

maurizi commented Nov 12, 2014

@hectcastro I can't speak for other developers, but I use the Python debugger basically every single day. Its not something I reserve for "hard" situations.

@steventlamb
Copy link
Contributor

@hectcastro There's nothing wrong with that idea, because it essentially reflects what we've been doing already on other projects. The consequence, at least for me, is that I never use the gunicorn appserver in development. I like to always be running a live-reloading appserver that supports interactive debugging, because I place breakpoints in my code frequently.

@RickMohr
Copy link
Contributor

I use PyCharm for debugging, and it looks like it's workable with gunicorn. (http://stackoverflow.com/a/17191033/362702)

@jwalgran
Copy link
Member

+1

Hector Castro and others added 6 commits November 13, 2014 11:31
This changeset makes Gunicorn the application server for Django across
environments. In addition, Upstart handles launching the Gunicorn worker
pool and Nginx reverse proxies requests to it.

It is also important to note that when the application is provisioned in
the development and test environments, the Gunicorn `--reload` flag is
used. This provides automatic Gunicorn worker reloads when code changes
occur. I tested application reloading by making source code changes via
the Vagrant shared folder and worker PIDs changed as expected.

For more discussion, see: #71
In addition, I set `timeout` to 30 minutes and lowered it to 60 in the
`else` because the ELB terminates requests at 60 seconds anyway.
This will make it easier to use the same config in multiple places
@steventlamb
Copy link
Contributor

Ok, I'm pretty sure this is ready, with a +1 and no further objection. I'm going to rebase, clean and merge shortly.

@hectcastro
Copy link
Contributor Author

+1

@steventlamb
Copy link
Contributor

@azavea-bot rebuild

steventlamb pushed a commit that referenced this pull request Nov 13, 2014
@steventlamb steventlamb merged commit a25e53f into develop Nov 13, 2014
@steventlamb steventlamb deleted the feature/unicorn-nginx branch November 13, 2014 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants