You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Raman Gupta <ro...@gmail.com> on 2012/11/26 20:33:15 UTC

Hook into Karaf shutdown process

I have an application in which, when it's given the stop command, I'd
like to finish some work in progress before shutting down bundle 0.
This is because the bundle shutdown starts prematurely shutting down
services and such that are necessary for the work to complete.

For now, I've implemented this with a custom Karaf command that
executes my application shutdown, and then delegates to the Karaf
StopCommand to shutdown Karaf itself.

However, this is not an ideal solution as it requires my custom
command to be explicitly executed. For example, it will not run when a
user does a normal kill or Ctrl-D.

Ideally, Karaf would have a "ShutdownHook" interface/service I could
implement in my bundles -- for each one of these registered, Karaf
would execute them before stopping the framework bundles. If someone
could give me some starting pointers, I could look into implementing
this...

Regards,
Raman

Re: Hook into Karaf shutdown process

Posted by Raman Gupta <ro...@gmail.com>.
On 11/26/2012 02:33 PM, Raman Gupta wrote:
> Ideally, Karaf would have a "ShutdownHook" interface/service I could
> implement in my bundles -- for each one of these registered, Karaf
> would execute them before stopping the framework bundles. If someone
> could give me some starting pointers, I could look into implementing
> this...

I believe I found the right place to do this...

./main/src/main/java/org/apache/karaf/main/Main.java

Just before the call to framework.stop(), we use the BundleContext to
obtain and execute a shutdown method on all services that implement a
new "FrameworkShutdownHook" interface.

Then, proceed to framework.stop().

Thoughts?

Regards,
Raman Gupta
Principal
VIVO Systems