nginx 信号控制 Controlling nginx

nginx can be controlled with signals.The process ID of the master process is written to the file/usr/local/nginx/logs/nginx.pid by default.This name may be changed at configuration time, or innginx.conf using thepiddirective.The master process supports the following signals:

TERM, INTfast shutdown
QUITgraceful shutdown
HUPchanging configuration,keeping up with a changed time zone (only for FreeBSD and Linux),starting new worker processes with a new configuration,graceful shutdown of old worker processes
USR1re-opening log files
USR2upgrading an executable file
WINCHgraceful shutdown of worker processes

Individual worker processes can be controlled with signals as well,though it is not required.The supported signals are:

TERM, INTfast shutdown
QUITgraceful shutdown
USR1re-opening log files
WINCHabnormal termination for debugging(requires debug_points to be enabled)

Changing Configuration

In order for nginx to re-read the configuration file, a HUPsignal should be sent to the master process.The master process first checks the syntax validity, then triesto apply new configuration, that is, to open log files and newlisten sockets.If this fails, it rolls back changes and continues to workwith old configuration.If this succeeds, it starts new worker processes, andsends messages to old worker processes requesting them toshut down gracefully.Old worker processes close listen sockets and continue to serviceold clients.After all clients are serviced, old worker processes are shut down.

Let’s illustrate this by example.Imagine that nginx is run on FreeBSD 4.x and the command,,


BSD格式的,linux测试时,axw前面不用加-号,加了会提示warning

ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'

produces the following output:

  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND
33126     1 root     0.0  1148 pause  nginx: master process /usr/local/nginx/sbin/nginx
33127 33126 nobody   0.0  1380 kqread nginx: worker process (nginx)
33128 33126 nobody   0.0  1364 kqread nginx: worker process (nginx)
33129 33126 nobody   0.0  1364 kqread nginx: worker process (nginx)

If HUP is sent to the master process, the output becomes:

  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND
33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx
33129 33126 nobody   0.0  1380 kqread nginx: worker process is shutting down (nginx)
33134 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33135 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33136 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)

One of the old worker processes with PID 33129 still continues to work.After some time it exits:

  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND
33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx
33134 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33135 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33136 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)


后面还有下次再看,经常看英文,脑子有点儿大 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值