我怎么能告诉独角兽了解Heroku的信号? [英] How can I tell unicorn to understand Heroku's signals?

查看:166
本文介绍了我怎么能告诉独角兽了解Heroku的信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许你已经看到了这个...

 
2012-03-07T15:36:25 + 00:00 heroku [web .1]:用SIGTERM
停止进程2012-03-07T15:36:36 + 00:00 heroku [web.1]:用SIGKILL停止进程
2012-03-07T15:36:36+ 00:00 heroku [web.1]:错误R12(退出超时) - > SIGTERM
2012-03-07T15:36:38 + 00:00之后10秒内无法退出进程heroku [web.1] :进程已退出,状态为137

运行 heroku 上的独角兽 ...





我可以说heroku发送 SIGQUIT ?或者我可以告诉独角兽将 SIGTERM 视为优雅关机?

解决方案

这是一个黑客攻击,但我已经成功创建了一个捕获 TERM 信号的独角兽配置文件​​,防止独角兽收到并执行其快速关机。然后,我的信号处理程序将 QUIT 信号发送回自己,以触发独角兽正常关机。



测试Ruby 1.9。 2,Unicorn 4.0.1和4.2.1,Mac OS X。

  listen 9292 
worker_processes 1

#这是一个破解。该代码在'before_fork'中运行,所以它在* Unicorn安装自己的TERM信号处理程序(这使
#高度依赖于Unicorn实现细节)后运行
#*。

#我们为TERM安装自己的信号处理程序,并简单地重新发送一个QUIT
#信号给我们自己。
before_fork | _server,_worker |
Signal.trap'TERM'do
puts'拦截TERM并发送自己QUIT,而不是'
Process.kill'QUIT',Process.pid
end
end

一个问题是(我相信)这个信号处理程序是由工作进程继承的。但是,工作进程安装了自己的 TERM 处理程序,它应该覆盖这个处理程序,所以我不会指望有任何问题。 (见 Unicorn :: HttpServer#init_worker_process @ lib / unicorn / http_server.rb:551



编辑:1更多细节,这个安装信号处理程序的模块将在每个工作进程中运行一次(因为 before_fork ),但这只是多余的,不会影响任何内容。 b $ b

Perhaps you've seen this...

2012-03-07T15:36:25+00:00 heroku[web.1]: Stopping process with SIGTERM
2012-03-07T15:36:36+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-03-07T15:36:36+00:00 heroku[web.1]: Error R12 (Exit timeout) -> Process failed to exit within 10 seconds of SIGTERM
2012-03-07T15:36:38+00:00 heroku[web.1]: Process exited with status 137

This is a well known problem when running unicorn on heroku...

Can I tell heroku to send SIGQUIT? Or can I tell unicorn to treat SIGTERM as graceful shutdown?

解决方案

This is a hack, but I've successfully created a unicorn config file that traps the TERM signal, preventing unicorn from receiving it and performing its quick shutdown. My signal handler then sends QUIT signal back to itself to trigger the unicorn graceful shutdown.

Tested with Ruby 1.9.2, Unicorn 4.0.1 and 4.2.1, Mac OS X.

listen 9292
worker_processes 1

# This is a hack.  The code is run with 'before_fork' so it runs
# *after* Unicorn installs its own TERM signal handler (which makes
# this highly dependent on the Unicorn implementation details).
#
# We install our own signal handler for TERM and simply re-send a QUIT
# signal to our self.
before_fork do |_server, _worker|
  Signal.trap 'TERM' do
    puts 'intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end
end

One concern is that (I believe) this signal handler is inherited by worker processes. But, the worker process installs its own TERM handler, which should overwrite this one, so I would not expect any issue. (See Unicorn::HttpServer#init_worker_process @ lib/unicorn/http_server.rb:551.

Edit: one more detail, this block that installs the signal handler will run once per worker process (because before_fork), but this merely redundant and won't affect anything.

这篇关于我怎么能告诉独角兽了解Heroku的信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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