Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tornado code deployment

Is there a canonical code deployment strategy for tornado-based web application deployment. Our current configuration is 4 tornado processes running behind NginX? (Our specific use case is behind EC2.)

We've currently got a solution that works well enough, whereby we launch the four tornado processes and save the PIDs to a file in /tmp/. Upon deploying new code, we run the following sequence via fabric:

  1. Do a git pull from the prod branch.
  2. Remove the machine from the load balancer.
  3. Wait for all in flight connections to finish with a sleep.
  4. Kill all the tornadoes in the pid file and remove all *.pyc files.
  5. Restart the tornadoes.
  6. Attach the machine back to the load balancer.

We've taken some inspiration from this: http://agiletesting.blogspot.com/2009/12/deploying-tornado-in-production.html

Are there any other complete solutions out there?

like image 200
NafisJamal Avatar asked Aug 18 '11 07:08

NafisJamal


People also ask

How do I run a tornado web application?

Since Tornado supplies its own HTTPServer, running and deploying it is a little different from other Python web frameworks. Instead of configuring a WSGI container to find your application, you write a main () function that starts the server: Configure your operating system or process manager to run this program to start the server.

Is there a Nginx config file for tornado?

This is a barebones nginx config file that is structurally similar to the one we use at FriendFeed. It assumes nginx and the Tornado servers are running on the same machine, and the four Tornado servers are running on ports 8000 - 8003:

How do I serve a static file from tornado?

You can serve static files from Tornado by specifying the static_path setting in your application: This setting will automatically make all requests that start with /static/ serve from that static directory, e.g. http://localhost:8888/static/foo.png will serve the file foo.png from the specified static directory.

What does autoreload do in tornado?

tornado.autoreload— Automatically detect code changes in development¶ Automatically restart the server when a source file is modified. Most applications should not access this module directly. Instead, pass the keyword argument autoreload=Trueto the tornado.web.Applicationconstructor (or debug=True, which enables this setting and several others).


1 Answers

We run Tornado+Nginx with supervisord as the supervisor.

Sample configuration (names changed)

[program:server]
process_name = server-%(process_num)s
command=/opt/current/vrun.sh /opt/current/app.py --port=%(process_num)s
stdout_logfile=/var/log/server/server.log
stderr_logfile=/var/log/server/server.err
numprocs = 6
numprocs_start = 7000

I've yet to find the "best" way to restart things, what I'll probably finally do is have Nginx have a "active" file which is updated letting HAProxy know that we're messing with configuration then wait a bit, swap things around, then re-enable everything.

We're using Capistrano (we've got a backlog task to move to Fabric), but instead of dealing with removing *.pyc files we symlink /opt/current to the release identifier.

like image 197
koblas Avatar answered Oct 03 '22 19:10

koblas