SKM IT World

Just another blog about IT


Leave a comment

Launching Several Pax Runner Daemons With The Same User

I use Pax Runner to provisioning my OSGi applications. I want to use several OSGi applications on my test server. As soon as you start the second OSGi application provisioned by Pax Runner, you get the following exception:


Exception in thread "main" java.lang.RuntimeException: org.ops4j.pax.runner.daemon.lock exists. Please make sure that the Pax Runner daemon is not already running.

As per Google search it is a bug in Pax Runner. The source code of  Pax Runner is hosted by Github, so I create a fork for fixing this issue.

My first idea was to add a new runner option. Problem is that the method, which build the path for the daemon home directory, is static, so I have no chance to read the runner option without a big refactoring. I decided to add a new Java property relative.runner.home., so I need to change only one method getRunnerHomeDir. Now, the path of the daemon runner home directory is user.home/.pax/relative.runner.home. If this property is not set, the default path will be  user.home/.pax/runner (like the behaviour before this change).

With this change, the start call of the Pax Runner looks like that:


java -Drelative.runner.home=app1 -cp pax-runner-1.7.6-SKM-PATCH.jar org.ops4j.pax.runner.daemon.DaemonLauncher --start

and the stop call of the Pax Runner looks like that:


java -Drelative.runner.home=app1 -cp pax-runner-1.7.6-SKM-PATCH.jar org.ops4j.pax.runner.daemon.DaemonLauncher --stop

For the second OSGi application, you have to change the value of relative.runner.home. But the second application will not start because of the following exception:


Exception in thread "main" java.lang.RuntimeException: Unable to set up shutdown port [8008].
at org.ops4j.pax.runner.daemon.Daemon.await(Daemon.java:253)
at org.ops4j.pax.runner.daemon.Daemon.start(Daemon.java:134)
at org.ops4j.pax.runner.daemon.Daemon.main(Daemon.java:84)
at org.ops4j.pax.runner.daemon.DaemonLauncher.start(DaemonLauncher.java:91)
at org.ops4j.pax.runner.daemon.DaemonLauncher.main(DaemonLauncher.java:69)
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.TwoStacksPlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
at java.net.TwoStacksPlainSocketImpl.bind(TwoStacksPlainSocketImpl.java:101)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:175)
at java.net.ServerSocket.bind(ServerSocket.java:376)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at java.net.ServerSocket.<init>(ServerSocket.java:128)
at org.ops4j.pax.runner.daemon.Daemon.await(Daemon.java:250)
... 4 more
-> Pax Runner daemon stopped.

Pax Runner uses a shutdown port to close the application, so every application needs its own shutdown port. You have two possibilities to set the shutdown port.

  1. You create a file called runner.args the same directory where the pax runner jar is and add the option –org.ops4j.pax.runner.daemon.shutdown.port=8008 in this file.
  2. You get this option to the DaemonLauncher, directly:
    java -Drelative.runner.home=app2 -cp pax-runner-1.7.6-SKM-PATCH.jar org.ops4j.pax.runner.daemon.DaemonLauncher --start --org.ops4j.pax.runner.daemon.shutdown.port=8008
    

Links

  1. Pax Runner Homepage
  2. Jira Bug Ticket
  3. Pax Runner at Github
  4. Pax Runner Fork
Advertisements


Leave a comment

Reading tips for OSGi Beginner

In the last weeks I familiarised myself with OSGi. Two books were very helpful:

Modular Java: Creating Flexible Applications with OSGi and Spring by Craig Walls

OSGi für Praktiker – Prinzipien, Werkzeuge und praktische Anleitungen auf dem Weg zur kleinen SOA by Bernd Weber,  Patrick Baumgartner, Oliver Braun (in German)

Both books are similar organised.  They introduce OSGi by an example project form the first source code till the deployment.  These projects are not ‘Hello World’ projects, so you can adopt the way of working with OSGi for your real OSGi projects.

After the books show the classic way to coding with OSGi, they show how you can use dependency injection in OSGi applications with Spring DM.

Both books work with the PAX Tooling of OPS4J. They are Maven Plugins and track the ‘pom-first’ way to build OSGi applications.  These books have a good introduction to the PAX tooling, too. It is very helpful, when you want to use a continuous integration environment for your development (Of course, you want 🙂 ).

The book ‘Modular Java’ has one minor flaw. It was written in 2009, so it use elder version of the tools.