部署 Thin 重启有什么平稳的办法?

chucai · 2012年07月20日 · 最后由 huacnlee 回复于 2012年10月08日 · 5173 次阅读

我使用如下命令重启 thin

thin restart -C thin.yml 

服务器总是会暂停几秒

后来改成了

thin restart -C thin.yml -o 3001

来启动,用户访问网页,也有可能出现 页面错误的提示

有什么办法,可以平稳的重启 Thin, 如同 使用

touch tmp/restart.txt

一样

单个 thin 的话应该没办法。

多个 thin 实例。可以 onebyone 的重启。有这么一个参数。

$ thin restart -O -C thin.yml

加了 -O 参数以后,thin 的启动会关闭一个启动一个,等启动完成以后再关闭另外一个

#2 楼 @huacnlee 谢谢。但是在启动的过程中,Nginx 有可能选择已经被我们关闭的 Thin。这怎么办? 用户访问,还是可能出现 错误提示的页面。

没用过,不过看 changlog,thin 是可以平滑重启的啊

== 0.6.2 Rambo release
 * Server now let current connections finish before stopping, fixes #18
 * Fix uploading hanging bug when body is moved to a tempfile,
   also delete the tempfile properly upon completion, fixes #25
 * 'thin restart' now sends HUP signals rather then stopping & starting, closes #17
 * HUP signal now launches a new process with the same options.

而且还可以通过发信号来日志切割:

== 1.4.0 Chromeo
 * kill -USR1 $PID for log rotation [catwell].
 * Fix HUP signal being reseted after deamonization [atotic].
 * Fix error with nil addresses in Connection#socket_address.

#4 楼 @hooopo kill -HUP $PID 难道是这个,还没试过

已经尝试,1.2.5 版本以上的 Thin 可以用下面的方法来重启

$ kill -HUP `tail tmp/pids/thin.*.pid | grep ^[0-9]`

最安全的方法是起多个实例,前端加个 nginx 代理一下,nginx reload 不会影响用户访问,可以把要重启的 thin 从 nginx 配置中注释掉,reload nginx,然后重启 thin,然后再改 nginx 配置,同样方法重启其他 thin

#8 楼 @zeeler 几十个进程的时候不搞死啊 我们经过长期的实践证明

Nginx + Haproxy + Thin 的方式来处理无缝重启很靠谱!

@huacnlee 嗯,我也去试试,虽然我们不用 thin

migrations 是什么去做的?

#11 楼 @keating 那种情况就需要特别时段处理了,在一个特别的时段处理(我们的数据库是由 DBA 来直接修改数据库,不会在 production 执行 rake db:migrate)

需要 登录 后方可回复, 如果你还没有账号请 注册新账号