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 and stop the server from inside the JVM, everything works as expected.
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.
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?
How can I get the JVM to shut all the way down, cleanly, even if it contains a running Webrick server?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With