gunicorn #1
Description
Gunicorn or Green Unicorn is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resources, and fairly speedy.
The providers of the wsgi relation must provide working_dir, plus optionally any of the charm's config directives, which will override the current config for the charm.
- Tags:
- misc ›
Gunicorn
Author:
- Patrick Hetu patrick@koumbit.org
How to configure the charm
To deploy a charm with this subordinate it must minimally:
- Provide the wsgi interface.
- Set the
working_dir
relation variable in the wsgi hook.
The configuration of Gunicorn will use the variable pass by the relation hook first. If there are not define it will fallback to the global configuration of the charm.
Example deployment
-
Deployment with python-django for example::
juju bootstrap juju deploy python-django juju deploy postgresql juju deploy gunicorn juju add-relation python-django postgresql:db juju add-relation gunicorn python-django juju expose python-django
-
Accessing your new django app should be ready at::
http://<machine-addr>:8080/
To find out the public address of gunicorn/python-django, look for it in
the output of the juju status
command.
I recommend using a reverse proxy like Nginx in front of Gunicorn.
Changelog
4:
Notable changes:
- re-add support for env_extra parameter that was dropped in r3, but with new standard shell format. e.g. env_extra="FOO=BAR BAZ=QUX". Also supports old r2 format (env_extra="'foo': 'bar', 'baz': 'qux'") to provide an upgrade path.
- if upgrading from r1 or r2, the old gunicorn config is removed, leaving just the custom upstart job.
No backwards incompatible changes.
3:
Notable changes:
- Rewrite the charm using python instead of BASH scripts
- add listen_ip configuration variable
Backwards incompatible changes:
- Remove the Django mode since Gunicorn is not recommending it anymore.
- Use Upstart to manage daemons
- no start/stop hook anymore use related charms instead.
- no configuration change directly on the charm anymore, use related charms instead.
- no access logging by default
- exposing a port must now be done in the linked charm instead of this one
Configuration
- env_extra
- (string) List of environment variables for the wsgi process. e.g. FOO="bar" BAZ="1 2 3"
- listen_ip
- (string) IP adresses that Gunicorn will listen on. By default we listen on all of them.
- 0.0.0.0
- pid_file
- (string) Background PID file.
- /tmp/gunicorn.pid
- port
- (int) Port the application will be listenning.
- 8080
- python_path
- (string) Set an additionnal PYTHONPATH to the project.
- wsgi_access_logfile
- (string) The Access log file to write to.
- wsgi_access_logformat
- (string) The Access log format. Don't forget to escape all quotes and round brackets.
- wsgi_backlog
- (int) The maximum number of pending connections.
- 2048
- wsgi_extra
- (string) Space separated extra settings. For example: --debug
- wsgi_group
- (string) Switch worker process to run as this group. A valid group id (as an int) or the name.
- www-data
- wsgi_keep_alive
- (int) Keep alive time in seconds.
- 2
- wsgi_log_file
- (string) The log file to write to. If empty the logs would be handle by upstart.
- -
- wsgi_log_level
- (string) The granularity of Error log outputs.
- info
- wsgi_max_requests
- (int) The maximum number of requests a worker will process before restarting.
- wsgi_timeout
- (int) Timeout of a request in seconds.
- 30
- wsgi_timestamp
- (string) The variable to modify to trigger Gunicorn reload.
- wsgi_umask
- (string) A bit mask for the file mode on files written by Gunicorn. The number 0 means Python guesses the base. Note that this affects unix socket permissions.
- 0
- wsgi_user
- (string) Switch worker processes to run as this user. User id (as an int) or the name.
- www-data
- wsgi_worker_class
- (string) Gunicorn workers type. Can be: sync, eventlet, gevent, tornado
- sync
- wsgi_worker_connections
- (int) The maximum number of simultaneous clients.
- 1000
- wsgi_workers
- (int) The number of worker process for handling requests. 0 for count(cpu) + 1
- wsgi_wsgi_file
- (string) The name of the WSGI application.
- wsgi