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:

1Exception 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:

1java -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:

1java -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:

 1Exception in thread "main" java.lang.RuntimeException: Unable to set up shutdown port [8008].
 2at org.ops4j.pax.runner.daemon.Daemon.await(Daemon.java:253)
 3at org.ops4j.pax.runner.daemon.Daemon.start(Daemon.java:134)
 4at org.ops4j.pax.runner.daemon.Daemon.main(Daemon.java:84)
 5at org.ops4j.pax.runner.daemon.DaemonLauncher.start(DaemonLauncher.java:91)
 6at org.ops4j.pax.runner.daemon.DaemonLauncher.main(DaemonLauncher.java:69)
 7Caused by: java.net.BindException: Address already in use: JVM_Bind
 8at java.net.TwoStacksPlainSocketImpl.socketBind(Native Method)
 9at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
10at java.net.TwoStacksPlainSocketImpl.bind(TwoStacksPlainSocketImpl.java:101)
11at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:175)
12at java.net.ServerSocket.bind(ServerSocket.java:376)
13at java.net.ServerSocket.<init>(ServerSocket.java:237)
14at java.net.ServerSocket.<init>(ServerSocket.java:128)
15at org.ops4j.pax.runner.daemon.Daemon.await(Daemon.java:250)
16... 4 more
17- 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:
1 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
  1. Pax Runner Homepage
  2. Jira Bug Ticket
  3. Pax Runner at Github
  4. Pax Runner Fork