How do I cleanly shut down an embedded JRuby in response to a SIGTERM to the JVM process?

前端 未结 2 1028
梦毁少年i
梦毁少年i 2021-02-18 15:09

I am running a Middleman (which uses Webrick) server on JRuby inside a JVM process using the org.jruby.embed.ScriptingContainer API.

If I shutdown cleanly a

相关标签:
2条回答
  • 2021-02-18 15:26

    First, a debugging trick: you can send a SIGQUIT to a Java process to get it to print the current stack traces of all running threads. This can help you diagnose which threads are causing the JVM to not exit.

    Sending a SIGINT, SIGHUP, or SIGTERM causes Java to run its shutdown hooks, then exit. You can see this in java.lang.Terminator. Once the signal is received, java.lang.Shutdown handles running all the shutdown hooks before terminating the process. Shutdown.halt() is not called until after the shutdown hooks have all finished, which suggests you have a shutdown hook that is hanging.

    Without actual code or stack traces it's difficult to provide a more precise answer than that, but a JVM that stays alive after you send a SIGINT is usually doing something strange in its shutdown hooks. If this isn't enough to go on try sending a SIGINT, waiting a few seconds, then sending a SIGQUIT, and adding the resulting stack traces to the question.

    0 讨论(0)
  • 2021-02-18 15:27

    Looks like kill -9 does not trigger the shutdownHook, but kill -15 does.

    This StackOverflow question has a detailed answer to the same problem.

    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.

    0 讨论(0)
提交回复
热议问题