最近在用nginx+uwsgi+djano搭建一个网站,当.py文件修改后,如果不重启uwsgi,修改无法应用。

查了下uwsgi的相关文档 ,找到几个解决方案。顺便翻译下以备查看

启动服务

  

Starting an uWSGI server is the role of the system administrator, like starting the Web server. It should not be the role of the Web server to start the uWSGI server – though you can also do that if it fits your architecture.

同启动web服务器一样,启动uWSGI服务器需要系统管理员的角色。最好不要用启动Web Server的角色启动uWSGI server-如果那样做适合你的架构的话也可以做。

How to best start uWSGI services as boot depends on the operating system you use.

On modern systems the following should hold true. On “classic” operating systems you can use init.d/rc.d scripts, or tools such as Supervisor, Daemontools or inetd/xinetd.

如何最好得启动uWSGI服务依赖于你所使用的操作系统。

以下的方法适用于现代的操作系统。在“classic"操作系统中你可以使用init.d/rc.d脚本,或者使用Supervisor, Daemontools等工具,或者inetd/xinetd.

System Method
Ubuntu Running uWSGI via Upstart (the official uwsgi package, available since Ubuntu 12.04 provides an init.d based solution. Read the README.)
Debian Running uWSGI via Upstart
Fedora SystemD
OSX launchd
Solaris SMF

Signals for controlling uWSGI

You can instruct uWSGI to write the master process PID to a file with the pidfile option.

The uWSGI server responds to the following signals.

您可以使用 pidfile选项指示uWSGI将master进程的PID写入到一个文件中。

uWSGI服务器响应以下的信号量。

Signal Description Convenience command
SIGHUP gracefully reload all the workers and the master process –reload
SIGTERM brutally reload all the workers and the master process  
SIGINT immediately kill the entire uWSGI stack –stop
SIGQUIT immediately kill the entire uWSGI stack  
SIGUSR1 print statistics  
SIGUSR2 print worker status or wakeup the spooler  
SIGURG restore a snapshot  
SIGTSTP pause/suspend/resume an instance  
SIGWINCH wakeup a worker blocked in a syscall (internal use)

Reloading the server

When running with the master process mode, the uWSGI server can be gracefully restarted without closing the main sockets.

This functionality allows you patch/upgrade the uWSGI server without closing the connection with the web server and losing a single request.

When you send the SIGHUP to the master process it will try to gracefully stop all the workers, waiting for the completion of any currently running requests.

Then it closes all the eventually opened file descriptor not related to uWSGI.

Lastly, it binary patches (using execve()) the uWSGI process image with a new one, inheriting all of the previous file descriptors.

The server will know that it is a reloaded instance and will skip all the sockets initialization, reusing the previous ones.

当运行在master处理模式时,uWSGI服务器可以优雅地重启,且不需要关闭主sockets.

这个功能允许您在不关闭链接且不丢失任何一个请求的情况下修补/升级uWSGI服务器。当您发出一个sighup到master进程的时候,它将会优雅地停止所有的工作进程,等待当前结束当前运行中的请求。然后它关闭所有最终打开的与uWSGI无关的文件描述符。最后,它通过二进制修复(使用 execve())打开一个新的uWSGI进程镜像,继承所有之前的文件描述符。服务器知道它已经重新加载了一个实例并跳过所有的sockets的初始化,复用之前的sockets。

Note

Sending the SIGTERM signal will obtain the same result reload-wise but will not wait for the completion of running requests.

发送信号量sigterm可以达到同样的reload效果,区别在于它不会等待正在运行的请求完成。

There are several ways to make uWSGI gracefully restart.

有几种使得uWSGI优雅重启的方式:

# using kill to send the signal
kill -HUP `cat /tmp/project-master.pid`
# or the convenience option --reload
uwsgi --reload /tmp/project-master.pid
# or if uwsgi was started with touch-reload=/tmp/somefile
touch /tmp/somefile

Or from your application, in Python:

uwsgi.reload()

Or in Ruby

UWSGI.reload

Stopping the server

If you have the uWSGI process running in the foreground for some reason, you can just hit CTRL+C to kill it off.

When dealing with background processes, you’ll need to use the master pidfile again. The SIGINT signal will kill uWSGI.

如果在一些情况下您的uWSGI进程在前台运行,您可以使用CTRL+C杀掉它。

如果是后台运行的话,您需要使用pidfile,信号量sigint将杀掉uWSGI。

kill -INT `cat /tmp/project-master.pid`
# or for convenience...
uwsgi --stop /tmp/project-master.pid

控制uwsgi 的信号量的更多相关文章

  1. Linux中信号量处理

    参考文章: http://blog.csdn.net/qinxiongxu/article/details/7830537/ 信号量一. 什么是信号量信号量的使用主要是用来保护共享资源,使得资源在一个 ...

  2. c++11信号量实现

    c++11中有 mutex (互斥量),有 condition_variable (条件变量),并没有 semaphore (信号量).信号量,操作系统中一般都有提,后来 google 说可以使用 m ...

  3. 【uWSGI】实战之Django配置经验

    uWSGI 是应用服务器,实现了uwsgi, wsgi等协议,可以运行wsgi 应用 uwsgi 是协议名 Django配置 下面是自己经常用的一个配置模板,基于1.9以上的版本使用的, 主要基于dj ...

  4. linux内核剖析(十)进程间通信之-信号量semaphore

    信号量 什么是信号量 信号量的使用主要是用来保护共享资源,使得资源在一个时刻只有一个进程(线程)所拥有. 信号量的值为正的时候,说明它空闲.所测试的线程可以锁定而使用它.若为0,说明它被占用,测试的线 ...

  5. linux信号量(转载)

    本文转载自http://blog.csdn.net/qinxiongxu/article/details/7830537 信号量一.什么是信号量信号量的使用主要是用来保护共享资源,使得资源在一个时刻只 ...

  6. CentOS 傻瓜式部署uWSGI + nginx + flask

    交代背景 这篇帖子是为了提供我自己的July Novel站点的小说数据支撑.解决分布式部署爬虫程序的繁琐过程,由于本人对shell编程并不熟悉,故而先逐步记录操作步骤,通过以下操作达到节省时间的方式. ...

  7. linux系统编程之(一) 信号量

    信号量 一.什么是信号量 信号量的使用主要是用来保护共享资源,使得资源在一个时刻只有一个进程(线程)所拥有. 信号量的值为正的时候,说明它空闲.所测试的线程可以锁定而使用它.若为0,说明 它被占用,测 ...

  8. 管理uWSGI服务器

    管理uWSGI服务器 官网参考 如果您正在管理多个应用程序或高容量站点,请查看 uwsgi皇帝-多应用程序部署 虫族模式 UWSGI订阅式服务器 启动uwsgi服务器 以系统管理员身份启动 uwsgi ...

  9. IPC进程间通信---信号量

    信号量 信号量:信号量是一个计数器,常用于处理进程或线程的同步问题,特别是对于临界资源访问的同步.临界资源可以 理解为在某一时刻只能由一个进程或线程操作的资源,这里的资源可以是一段代码.一个变量或某种 ...

随机推荐

  1. 一次利用MSSQL的SA账户提权获取服务器权限

    遇到小人,把服务器整走了 自己手里只有sql server的sa账号密码 模糊记起之前用这个账户提权读取文件的事 百度之,发现相关信息一堆堆 各种工具也用了不少 发现不是语法错误就是权限不够 无奈之下 ...

  2. (转)基于PHP的cURL快速入门

    1. 原文:基于PHP的cURL快速入门 英文原文:http://net.tutsplus.com/tutorial ... for-mastering-curl/ 原文作者:Burak Guzel ...

  3. ASP.NET如何发布更新

    如果一个应用程序迭代开发后,我们如何来进行发布更新呢? 这里,我用Visual Studio 2008和SQL server来演示. 一.程序修改完毕后,我们要进行以下操作: 1.1 点击解决方案,重 ...

  4. Typescript 团队合作的利器

    前言 在介绍Typescript 之前,我需要隆重介绍一个人: 安德斯·海尔斯伯格(Anders Hejlsberg,1960.12~),丹麦人,Turbo Pascal编译器的主要作者,Delphi ...

  5. iOS7初体验(1)——第一个应用程序HelloWorld

    iOS7 Beta已经发布了,迫不及待地下载了iOS 7及Xcode 5并体验了一下.先做一个简单的Hello World看看都有哪些变化吧. 1. 启动Xcode5-DP: 2. 从菜单选择File ...

  6. 子树大小平衡树(Size Balanced Tree,SBT)操作模板及杂谈

    基础知识(包括但不限于:二叉查找树是啥,SBT又是啥反正又不能吃,平衡树怎么旋转,等等)在这里就不(lan)予(de)赘(duo)述(xie)了. 先贴代码(数组模拟): int seed; int ...

  7. 【POJ3468】【树状数组区间修改】A Simple Problem with Integers

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  8. centos安装nodejs和mongodb

    安装nodejs: Run as root on RHEL, CentOS or Fedora, for Node.js v4 LTS Argon: curl --silent --location ...

  9. PHP不依赖系统自动执行机制

    不依赖系统,以及不依赖yii事物机制,则考虑人为触发.触发可以写在总体的公共页面上,但是考虑到对数据库以及WWW服务器的压力问题,程序的延迟问题,需要对执行函数进行一些优化. 首先,我们考虑对数据库的 ...

  10. iOS适配:Masonry介绍与使用实践:快速上手Autolayout

    随着iPhone的手机版本越来越多, 那么对于我们广大的开发者来说就是很悲催,之前一直使用代码里面layout的约束来适配, 现在推荐一个第三方Masonry,上手块,操作简单,只能一个字形容他 “爽 ...