如何干净地关闭嵌入式JRuby以响应SIGTERM到JVM进程? [英] How do I cleanly shut down an embedded JRuby in response to a SIGTERM to the JVM process?
问题描述
我使用 org.jruby.embed.ScriptingContainer
API在JVM进程内运行JRuby上的Middleman(使用Webrick)服务器。
I am running a Middleman (which uses Webrick) server on JRuby inside a JVM process using the org.jruby.embed.ScriptingContainer
API.
如果我干净地关闭并从JVM内部停止服务器,一切都按预期工作。
If I shutdown cleanly and stop the server from inside the JVM, everything works as expected.
但是如果我发送一个SIGTERM到JVM进程(例如,通过在命令行中按ctrl + C),控制台返回但JVM进程没有终止 - 它无限期地挂起,直到我发送一个SIGKILL。
But if I send a SIGTERM to the JVM process (for example, by hitting ctrl+C at the command line), the console returns but the JVM process does not terminate - it hangs around indefinitely until I send it a SIGKILL.
我尝试注册JVM关闭挂钩来终止 ScriptingContainer
实例,但挂钩永远不会触发。我不知道为什么......或许JRuby以某种方式吞下了SIGTERM?
I tried registering a JVM shutdown hook to terminate the ScriptingContainer
instance, but the hook never fires. I'm not sure why... perhaps JRuby is swallowing the SIGTERM somehow?
我怎样才能让JVM完全关闭,干净利落,即使它包含正在运行的Webrick服务器?
How can I get the JVM to shut all the way down, cleanly, even if it contains a running Webrick server?
推荐答案
看起来像 kill -9
不会触发shutdownHook,但是 kill -15
会。
Looks like kill -9
does not trigger the shutdownHook, but kill -15
does.
这个StackOverflow问题详细解答了同一个问题。
This StackOverflow question has a detailed answer to the same problem.
底线是,你搞砸了,因为似乎没有办法拦截 kill -9
在JVM停止之前发出信号并执行一些维护任务。
Bottom line is, you're screwed, as there doesn't seem to exist any way to intercept a kill -9
signal and perform some maintenance tasks before the JVM halts.
这篇关于如何干净地关闭嵌入式JRuby以响应SIGTERM到JVM进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!