running gunicorn behind couchdb. that's easy

17 views
Skip to first unread message

Benoit Chesneau

unread,
Oct 5, 2010, 4:18:16 PM10/5/10
to nympho...@googlegroups.com
recently @davisp [1] writtent new_externals handler in view of
improving external scripts managements in CouchDB. So I wanted to try
with gunicorn [2] . Here is a quick way to eo it.

1. Create a launch script with the application you want to load :

http://friendpaste.com/3fhZlsQyx6BfemSfOoIwDl

2. Edit these sections in local.ini :

[httpd_global_handlers]
_gunicorn = {couch_httpd_proxy, handle_proxy_req,
<<"http://127.0.0.1:8000">>}

[os_daemons]
gunicorn = /Users/benoitc/Work/gunicorn_env/bin/test.sh

Then launch couchdb. and use cur to access :

$ curl http://127.0.0.1:5984/_gunicorn
Hello, World!

With verbose mode you can see the server headers?

enlil:couchdb benoitc$ curl -v http://127.0.0.1:5984/_gunicorn
* About to connect() to 127.0.0.1 port 5984 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> GET /_gunicorn HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0)
libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: 127.0.0.1:5984
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: gunicorn/0.11.2.ac9f38d-git, CouchDB/1.1.0a79d9dc6-git
(Erlang OTP/R14B)
< Date: Tue, 05 Oct 2010 20:13:33 GMT
< Content-type: text/plain
< Content-Length: 14
< Connection: keep-alive
<
Hello, World!
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0


Now you can try some funny stuff like reload gunicorn using pidfile :

$ kill -HUP `head -1 /tmp/gunicorn.pid`

and in the couchdb shell you see :

010-10-05 22:15:28 [2264] [INFO] Handling signal: hup
2010-10-05 22:15:28 [2264] [INFO] Hang up: Master
2010-10-05 22:15:28 [2294] [INFO] Booting worker with pid: 2294
2010-10-05 22:15:28 [2295] [INFO] Booting worker with pid: 2295
2010-10-05 22:15:28 [2296] [INFO] Booting worker with pid: 2296
2010-10-05 22:15:28 [2266] [INFO] Worker exiting (pid: 2266)
2010-10-05 22:15:28 [2267] [INFO] Worker exiting (pid: 2267)
2010-10-05 22:15:28 [2268] [INFO] Worker exiting (pid: 2268)


That's perfectly work. Thanks a lot to @davisp for that. Now it's time to play.

- benoit

[1] http://www.davispj.com/2010/09/26/new-couchdb-externals-api.html
[2] http://gunicorn.org

Reply all
Reply to author
Forward
0 new messages