ruby-on-rails - RubyMine 停止按钮在 Rails 应用程序中创建僵尸 Puma 服务器
问题描述
未直接解决此问题的相关问题/问题
- 使用 ctrl-c 杀死 Rails 服务器时 Puma 不会死
- 无法终止进程 - 停止 Rails 服务器
- 不可阻挡的服务器 - rails
- 如何在 rubymine 中停止/终止服务器(开发)
- 无法停止 Rails 服务器
- 停止按钮发出的信号
- 向正在运行的程序发送 SIGINT 信号。
- 通过(在集群模式下)运行时向服务器进程发送 SIGTERM
rails s
无法成功停止服务器 - 通过SIGTERM关闭时适当等待worker子进程
- 信号陷阱以状态 0 退出而不是杀死自己的进程
- Rails 服务器不会停止 Windows bash 杀戮
- 带有基于 WSL 的解释器的 Windows 上的 Rubymine:Puma 终止时无法终止服务器进程
- WSL 进程树在 taskkill 中幸存下来
- [WSL] Rubymine 不会杀死 rails 进程,需要手动执行。
规格
- 通过适用于 Linux 的 Windows 子系统运行Ubuntu 18.04.1 LTS的 Windows 10(10.0.17134 Build 17134 和功能更新 1803)
- 红宝石矿 2018.2.3
- 彪马 3.12.0
- 导轨 5.1.4
- 红宝石 2.5.1p57
问题
在 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 的一章)。
解决方案
推荐阅读
- amazon-web-services - 自定义注册表的示例对象路径
- azure - 将多容器组部署到 Azure Serverless
- node.js - 如何传递多个中间件nodejs之一
- amazon-web-services - 即使子网位于不同的可用区,也无法创建 RDS 实例
- blazor - Blazor .net core (3.1) 托管的 webassembly 应用程序从 .Client 应用程序获取 apsettings.json
- c# - 在创建更新场景中处理私有 setter 和 id
- c# - 从 response.Content.ReadAsStringAsync() 中恢复对象
- postgresql - 我可以在 LIMIT 子句中使用百分比而不是数字吗
- tensorflow - 我正在使用 tensorflow 在 colab 中进行编码。我遇到了这个错误。我该如何进行。我尝试安装各种版本的 tf 以及 tf.hub
- flutter - flutter reactive_forms ReactiveForm.of noSuchMethod