A have lift app starting ssh daemon in Boot.scala.
Here is the problem: when i run container:restart /
in sbt session I get Address alread in use exception.
Now two questions:
- Is it right way to start dependent service in Boot.scala?
- Anyway how is it possible to handle container:stop event?
I think the Lift-y way to do it is with
LiftRules.unloadHooks
.It's not well-documented (AFAIK), but if you look in the Lift source code, you'll see that when the
LiftServlet
isdestroy()
ed, the functions defined inLiftRules.unloadHooks
are executed.You can add functions to the
unloadHooks
RulesSeq
with theappend
orprepend
method, depending on what order you want them executed in. So, in yourbootstrap.liftweb.Boot.boot
method, you might do something like this:(Assuming that was how you started and stopped your SSH daemon.)
I'm not 100% certain the
LiftServlet.destroy()
method gets invoked when the sbt web-plugin'scontainer:restart
command is run - that's determined by the plugin and its interaction with Jetty, not by Lift - but thecontainer:stop
command should definitely do the trick.