首页 > 解决方案 > RubyMine 停止按钮在 Rails 应用程序中创建僵尸 Puma 服务器

问题描述

未直接解决此问题的相关问题/问题

规格

问题

在 RubyMine 中使用绿色开始箭头启动开发环境会按预期启动 Puma 服务器。服务器控制台日志显示:

]0;Ubuntu^Z
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
[2331] Puma starting in cluster mode...
[2331] * Version 3.9.1 (ruby 2.5.1-p57), codename: Private Caller
[2331] * Min threads: 5, max threads: 5
[2331] * Environment: development
[2331] * Process workers: 2
[2331] * Preloading application
[2331] * Listening on tcp://127.0.0.1:3000
[2331] Use Ctrl-C to stop
[2331] - Worker 0 (pid: 2339) booted, phase: 0
[2331] - Worker 1 (pid: 2343) booted, phase: 0

(不确定顶部 Ubuntu 周围的损坏字符是什么,但这是另一个问题......)

ps aux | grep puma我可以通过在控制台中发出命令来监视服务器。输出如下:

samort7   2456 16.9  0.3 430504 66420 tty5     Sl   23:58   0:05 puma 3.9.1 (tcp://127.0.0.1:3000) [rails-sample-app]
samort7   2464  1.6  0.3 849172 54052 tty5     Sl   23:58   0:00 puma: cluster worker 0: 2456 [rails-sample-app]
samort7   2468  1.5  0.3 849176 54052 tty5     Sl   23:58   0:00 puma: cluster worker 1: 2456 [rails-sample-app]
samort7   2493  0.0  0.0  14804  1200 tty4     S    23:59   0:00 grep --color=auto puma

单击 IntelliJ 中的红色“停止”按钮会导致此行显示在服务器控制台日志中:

Process finished with exit code 1

但是,ps aux| grep puma再次运行表明 puma 服务器仍在运行:

samort7   2464  0.2  0.3 849172 54340 ?        Sl   Oct12   0:00 puma: cluster worker 0: 2456 [rails-sample-app]
samort7   2468  0.2  0.3 849176 54332 ?        Sl   Oct12   0:00 puma: cluster worker 1: 2456 [rails-sample-app]
samort7   2505  0.0  0.0  14804  1200 tty4     S    00:01   0:00 grep --color=auto puma

反复点击启动和停止会导致越来越多的僵尸进程被创建。这些进程可以通过发出pkill -9 -f puma命令来终止,但这并不理想,并且违背了停止按钮的全部目的。

预期结果

直接从终端运行服务器rails s -b 127.0.0.1 -p 3000并像以前一样启动服务器,然后按Ctrl+C给出以下输出并且不会创建僵尸进程:

[2688] - Gracefully shutting down workers...
[2688] === puma shutdown: 2018-10-13 00:12:00 -0400 ===
[2688] - Goodbye!
Exiting

分析

根据RubyMine 文档,单击停止按钮:

调用终止允许应用程序捕获SIGINT事件并执行正常终止(在 Windows 上,模拟Ctrl+C事件)。

尽管文件声称,这似乎并没有发生。似乎停止按钮实际上是在发出SIGKILL信号,停止进程而不允许它优雅地清理。

我还注意到,如果我关闭 RubyMine 内部和外部的所有终端窗口,然后打开一个新的终端窗口,僵尸进程就消失了。

问题

如何让 RubyMineSIGINT在按下红色停止按钮时发出正确的信号,以便在不创建僵尸进程的情况下优雅地关闭 Puma 服务器?

作为参考,我在我的代码库的这个提交中遇到了这个问题( Michael Hartle's Rails Tutorial 的一章)。

标签: ruby-on-railsrubyruby-on-rails-5rubyminepuma

解决方案


推荐阅读