问题描述
我的代码是用龙卷风编写的,我想使其像apache或nginx一样正常工作,
I have my code written with tornado and I want to make it work pretty much like apache or nginx, that is
- 即使我关闭外壳,它也必须继续监听端口.
- 它必须在系统重新启动时自动启动
即使关闭外壳,我也尝试过nohup命令使其正常工作.有用.但是我想知道是否有更清洁的选择可用于相同的选择?
I have tried nohup command to make it work even when I close the shell. It works. But I am wondering if there is a cleaner option available for the same?
推荐答案
来自官方文档这里.
大多数Tornado应用程序都作为单个进程运行.对于生产而言,这通常意味着外部流程管理和代理的直接组合.这里是一些最佳实践/资源.
Most Tornado apps are run as single processes. For production, this usually means a fairly straight-forward combination of external process management and proxying. Here are some gathered best practices/resources.
调试模式时启用后,将不会缓存模板,并且该应用将在开发过程中自动重启.但是,如果发生Python语法错误,此操作将失败. (可以使用一些其他代码或通过在开发中使用主管)
When debug mode is enabled, templates are not cached and the app will automatically restart during development. This will fail if a Python syntax error occurs, however. (This can be worked around w/ some additional code or by using Supervisor in development)
您可能希望通过终端多路复用器(如屏幕"或 tmux 可以让您更灵活地运行并跟踪致命错误.
You might want to run your app from a terminal multiplexer like screen or tmux for more flexibility in leaving things running and tracing fatal errors.
通常在生产中,使用前端代理运行多个龙卷风应用程序进程(每个内核至少一个).龙卷风开发者bdarnell有一个 tornado-production-skeleton 使用主管(流程管理)和 nginx (代理).
Typically in production, multiple tornado app processes are run (at least one per core) with a frontend proxy. Tornado developer bdarnell has a tornado-production-skeleton illustrating this using Supervisor (process management) and nginx (proxying).
传统上,Tornado应用程序是单进程的,需要外部进程管理器,但是 HTTPServer可以与多个进程一起运行.此外,还有几个其他帮助程序可以帮助您管理多个流程.
Traditionally, Tornado apps are single-process and require an external process manager, however HTTPServer can be run with multiple processes. Additionally, there are a couple additional helpers for helping out with managing multiple processes.
- 使用Supervisor管理多个Pylons应用-Supervisor入门的绝佳教程
- 部署龙卷风应用程序-带有Supervisor的简短教程和nginx设置演练
- supervisord-example.conf -这是运行4个龙卷风实例的示例cfg
- Nginx监督模块-此模块允许nginx启动/按需停止后端
- Managing multiple Pylons apps with Supervisor - an excellent tutorial for getting started with Supervisor
- Deploy tornado application - short tutorial w/ Supervisor and nginx setup walkthrough
- supervisord-example.conf - this is an example cfg for running 4 tornado instances
- Nginx Supervisod Module - this module allows nginx to start/stop backends on demand
- start-stop-daemon示例-如果您运行的是标准Linux系统,这是守护Tornado应用程序的简便方法
- Upstart示例-Upstart内置于Ubuntu,可以重新生成崩溃的实例.
- start-stop-daemon example - if you are running a standard Linux system this is an easy way to daemonize your Tornado app
- Upstart example - Upstart is built into Ubuntu and can respawn crashed instances.
如上所述,Tornado的可以配置HTTPServer 用于单个或多个套接字上的两个进程.
As mentioned above, Tornado's HTTPServer can be configured for both multiple processes on a single or multiple sockets.
官方文档包括将nginx作为负载平衡代理运行并为静态文件提供服务的示例.
- 将Python Web(Tornado)应用程序部署到多台服务器-有关在不停机的情况下使用Load Balancer进行实时迁移的简短讨论
- 带结构的滚动部署
- Python部署反模式
- buedafab -很好的Fabric集合带EC2的部署脚本
- Deploying Python web (Tornado) applications to multiple servers - short discussion on using a Load Balancer for live migration w/o downtime
- Rolling Deployment w/ Fabric
- Python Deployment Anti-Patterns
- buedafab - a nice collection of Fabricdeployment scripts w/ EC2
这篇关于Tornado Python作为守护程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!