Closed art-solopov closed 4 years ago
mount does not do anything special on Ctrl+C
. On JVM this is usually handled with a shutdown hook. Here is an example:
(defn -main [& args]
(mu/on-upndown :info mu/log :before)
(log/info "launching app...")
(.addShutdownHook (Runtime/getRuntime)
(Thread. #(mount/stop)))
(mount/start))
this will call (mount/stop)
on kill -X
/Ctrl+C
. here are the Java docs for it.
let me know if it helps
It works, thank you! But is it an idiomatic way to manage mount state (esp. in production)?
yes it is. this is not exactly mount
specific. if any of components you start need to be stopped on a forceful program exit, such as Ctrl + C
/ kill -X
, you should register a JVM shutdown hook.
I see, thank you!
I'm trying to understand mount and how it plays with states and services (such as an HTTP server). I'm currently having an http-kit server:
And a module using mount to launch it:
Now, I start it with
lein run -m clojure-play.play-mt.core
, do a couple requests to check the server works, and interrupt it via Ctrl+C. I get those logs:Why doesn't mount stop the states on Ctrl+C? Is there something in configuration I'm missing?