有没有办法在不重新启动服务器的情况下使用 Tornado/Python 部署新代码? [英] Is there a way to deploy new code with Tornado/Python without restarting the server?

查看:35
本文介绍了有没有办法在不重新启动服务器的情况下使用 Tornado/Python 部署新代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始尝试使用 Python 和 Tornado Web 服务器/框架进行 Web 开发.以前,我在 LAMP 堆栈上使用 PHP 和我自己的框架.使用 PHP,由于 mod_php 和 Apache 的交互方式,部署更新的代码/新代码就像将其上传到服务器一样简单.

I've recently started to experiment with Python and Tornado web server/framework for web development. Previously, I have used PHP with my own framework on a LAMP stack. With PHP, deploying updated code/new code is as easy as uploading it to the server because of the way mod_php and Apache interact.

当我在 Python/Tornado 中添加新代码或更新代码时,是否需要重新启动 Tornado 服务器?如果您有大量活跃用户,我会发现这会带来问题.

When I add new code or update code in Python/Tornado, do I need to restart the Tornado server? I could see this being problematic if you have a number of active users.

(a) 我必须重新启动服务器,还是有其他/更好的方法?

(a) Do I have to restart the server, or is there another/better way?

(b) 如果是这样,我怎样才能避免用户断开连接/出现错误等.重新启动时(可能需要几秒钟)?

(b) If so, how can I avoid users being disconnected/getting errors/etc. while it's restarting (which could take a few seconds)?

[一种可能的想法是使用 Nginx 指向服务器的页面翻转范式,使用更新的代码启动新的服务器实例,将 Nginx 重定向到那里并关闭原始服务器......?]

[One possible thought is to use the page flipping paradigm with Nginx pointing to a server, launch the new server instance with updated code, redirect Nginx there and take down the original server...?]

推荐答案

似乎最好的方法是将 Nginx 与多个 Tornado 实例一起使用,正如我在原始问题中提到的和 Cole 提到的那样.Nginx 可以即时重新加载其配置文件.所以这个过程是这样的:

It appears the best method is to use Nginx with multiple Tornado instances as I alluded to in my original question and as Cole mentions. Nginx can reload its configuration file on the fly . So the process looks like this:

  1. 更新 Python/Tornado 网络应用程序代码
  2. 在不同的端口上启动应用程序的新实例
  3. 更新Nginx的配置文件指向新实例(先测试配置文件的语法)
  4. 使用 kill -HUP 命令重新加载 Nginx 配置文件
  5. 停止旧的 Python/Tornado 网络服务器实例
  1. Update Python/Tornado web application code
  2. Start a new instance of the application on a different port
  3. Update the configuration file of Nginx to point to the new instance (testing the syntax of the configuration file first)
  4. Reload the Nginx configuration file with a kill -HUP command
  5. Stop the old instance of Python/Tornado web server

Nginx 上关于热插拔配置文件的一些有用资源:

A couple useful resources on Nginx regarding hot-swapping the configuration file:

https://calomel.org/nginx.html(在解释 nginx 中的指令"中.conf"部分)http://wiki.nginx.org/CommandLine(在使用信号加载新配置"部分)

https://calomel.org/nginx.html (in "Explaining the directives in nginx.conf" section) http://wiki.nginx.org/CommandLine (in "Loading a New Configuration Using Signals" section)

这篇关于有没有办法在不重新启动服务器的情况下使用 Tornado/Python 部署新代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆