Showing posts with label Apache Felix. Show all posts
Showing posts with label Apache Felix. Show all posts

Monday, September 09, 2013

Apache Felix fails to run in background (including nohup case)

How to run Apache Felix in background with nohup. Solution is here. In my case I faced the problem when tried to run Squash TM in background. That application is built over Apache Felix and the exceptions told something like:

java.util.zip.ZipException: ZipFile closed
at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:642)
at java.util.zip.ZipFile.access$1300(ZipFile.java:56)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:675)
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:413)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at org.apache.felix.framework.util.WeakZipFileFactory$WeakZipFile$WeakZipInputStream.read(WeakZipFileFactory.java:707)

or

Spring DM context shutdown thread WARN 06/09 14:35:39 [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Exception
thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context:
OsgiBundleXmlApplicationContext(bundle=org.squashtest.tm.plugin.testautomation.jenkins, config=osgibundle:/META-INF/spring/*.xml): startup date
[Fri Sep 06 14:35:34 BST 2013]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:340)

Certain amount of investigation shown that the common solution in such the case is to exclude the application binding to the console. So do the following:

  1. As it's recommended here check if you have ConsoleHandler enabled for your Log4j and disable it using the following entry: java.util.logging.ConsoleHandler.level = OFF (if you're using property file to configure your logging. otherwise use the xml equivalent)
  2. Drop the bundles holding -shell suffix from your Bundles folder. They could look like the following:
    1. org.apache.felix.shell.tui-version.jar
    2. org.apache.felix.gogo.shell-version.jar
  3. As the alternative of the previous step you may add -Dgosh.args=--nointeractive  option to the jvm arguments on calling your app from sh sctipt
  4. Run your application in the regular way like nohup ./startup.sh &
This should help.