Is there a way to tell when Lucee is shutting down...
# lucee
b
Is there a way to tell when Lucee is shutting down, for example restarting Lucee or the server receives a shutdown signal. I know there is
onApplicationEnd
but it doesn't fire at all for me and I am using Lucee 5.3.8-206 and appears to be a known bug https://luceeserver.atlassian.net/browse/LDEV-1944
d
Lucee does have some support for Server.cfc, but it looks like it might only suypport onServerStart and not onServerEnd: https://docs.lucee.org/guides/cookbooks/Startup_Listeners.html
s
would you mind sharing what you want to do on shutdown?
there may be some other ways to approach the problem
b
Lucee attempts to register a listener in the servlet to tell when the servlet is being undeployed
but Lucee's code to do this fails miserably on Undertow (CommandBox) because Lucee attemps to break the spec in doing so
That MAY be part of it, it's hard to say as there's a lot of moving pieces and a lot of ways Lucee can be "shut down"
i.e. • the restart button in the Lucee admin • undeploying the context in your servlet • shutting down the servlet/JVM • Shutting down a Docker container (which sends a stop or an interrupt signal to the process)
b
I am more interested in the docker container shutdown which I believe is a SIGHUP. But also the restart button. I need to clean up connections to our message queue by calling
disconnect
and
unsubscribe
so that the cluster knows those consumers are no longer available to receive messages.
b
I went through this with CommandBox Task Runners that I was using in "daemon" tasks on Docker Swarm with Rabbit Consumer threads. CommandBox itself has a JVM shutdown hook that will interrupt the main thread and wait up to 10 seconds for it to complete which triggers an interrupt of my task runners, allowing them to shutdown the rabbit listeners.
For a web server, it probably depends on how you have it started. if you don't have a finalized image, then the entry point of the container is the shell script that basically calls
box server start --console
which, when interrupted, will stop the server
When CommandBox stops a server, it asks Undertow to undeploy its servlet contexts first
What I'm not 100% on is exactly how that works (or IF it works correctly) and if at any point, Lucee actually gets told what's happening.
And of course, if you're on the tomcat-based docker images I have no earthly clue what happens there.
I do know the
restart
button int he Lucee adimin does not undeploy the servlet context, it just unloads Lucee itself and reloads it without the servlet knowing or caring.
b
I am using the tomcat based docker image
b
You're on your own then 😉
b
I am following the code path for
restart
currently
b
I've spent a lot of time digging into how CommandBox/Runwar/undertow shuts down, but I don't know how Tomcat does it.
Unless you're planning on using the restart button in prod, that's probably a waste of time as it's nothing like the code path that an actual JVm shutdown takes
I don't even know if the tomcat based images bother to interrupt Tomcat, or if they just murder it in cold blood
Docker often likes to just murder containers once it doesn't want them
b
We aren't it is mostly for development purposes
👍 1
s

https://danielmg.org/uploads/posts/1618838103-docker.png