Search code examples
osgiapache-karafosgi-bundle

Identify OSGI Bundle failure in Karaf programmatically


We are using Karaf-4 as OSGI container. We have several bundles associated with a feature. When any bundle fails in a feature, we want to identify programmatically. We tried BundleTracker and BundleListener, but we are not getting notification when a bundle fails after waiting in "GracePeriod" state.

We are able to view the status of failure bundle using "list" command in karaf console. We want to achieve this programmatically through notification rather than we execute "list" command in the karaf console.


Solution

  • You can use the BundleService as an OSGi service. The method getInfo gives you among other the BundleState. For failed bundles you can then call getDiag to get the detailed status.

    Actually this is what the diag command does internally.