Continuous deployment of OSGi-based application on jenkins

自古美人都是妖i 提交于 2019-12-03 00:08:19

The telnet way seems to be the cleanest in my opinion.

However, if you want to be creative you can create a simple shutdown bundle that you install before you get ready to redeploy. Make sure you have auto-deploy on so the bundle is activated when installed. When this bundle activates it's job is to cleanly shutdown the current running Equinox container.

I would still suggest the telnet approach as you need to make sure your container is shutdown before you attempt to redeploy.

If you don't like any of these approaches take a look at Apache Karaf. You can send a running container commands. You can even stop, uninstall then reinstall all your bundles without ever stopping Karaf.

Karaf can run on top of Apache Felix or Eclipse Equinox.

Maybe I'm missing something, but why do you want to shutdown the whole OSGi framework when you want to redeploy/update your application? The whole point of OSGi is that you can update bundles without having to restart the whole system (remember the loved "You have to restart Windows for the changes to take effect" stuff?). What's more, restarting the whole framework will hide any errors regarding releasing resources in the stop method of your bundle, so I definitely recommend to test by updating only the bundle (and checking the logs and the resource consumption after several start/stop cycles too!)

If I was doing it, I would start an OSGi framework only once completely independently from maven, and then use one of many possible methods for deploying and updating the bundle in it without restarting the framework.

For example: * you could configure the system so that the updated version of the bundle is always put in a given location on the disk, and then use the OSGi console/telnet/whatever admin tool comes with the OSGi framework you have chosen to call "update ".

  • or you can use some tool which can connect to the running framework instance and update the bundle. For example for Eclipse there is a plugin from ProSyst which does exactly that.

  • or you can use some real remote management software, which could help you test the remote deployment on several targets at the same time and also monitor the deployment status directly. One such system is for example mPower Remote Manager

Regarding releasing the port - if you have problems with this, the reason is most probably the bundle itself, and restarting the OSGi framework won't solve it, because in a real-life scenario the fw is not supposed to be restarted upon update of a single bundle. Check whether you are stopping all threads and releasing all resources correctly in the stop() method of the BundleActivator of your bundle.

After some new insights and checking out quite a few approaches, I want to document what I found working best for my own initial question regarding continuous deployment of a OSGi-based application.

The main problem here was not to be able to update bundles in a running OSGi application just by dropping them in some directory (that could be done with org.apache.felix.fileinstall for example), but to be able to continuously deploy the current state of the software right from the SCM - automatically, via jenkins, exactly as it would look like when being deployed the very first time.

The solution for me was rather simple, really: There is a daemon version of pax-runner, which I can utilize as follows:

In jenkins project configuration, Post-steps, execute shell I put something like:

export BUILD_ID=dontKillMe
myproject/etc/scripts/postDeploy.sh &

with a postDeploy script looking like

#!/bin/bash

cd <myproject>/workspace/skysail.server.ext.osgimonitor/target
cp project.zip /somepath/pax-runner-1.8.5/

cd /somepath/pax-runner-1.8.5/

unzip project.zip

cd project
./rund.sh

with the final rund.sh script similar to

java $JAVA_OPTS -cp .:bin/pax-runner-1.8.5.jar org.ops4j.pax.runner.daemon.DaemonLauncher \
--startd --clean scan-composite:file:rund.composite \
--log=DEBUG

rund.composite is just a file referencing some provisioning files like this

scan-file:bundledefs/core.setup
scan-file:bundledefs/logging.setup
scan-file:bundledefs/restlet.setup

And, finally as an example for those files:

mvn:commons-lang/commons-lang/2.6
mvn:org.codehaus.jackson/jackson-core-lgpl/1.9.5
mvn:org.codehaus.jackson/jackson-mapper-lgpl/1.9.5
mvn:javax.xml.stream/com.springsource.javax.xml.stream/1.0.1
mvn:org.xmlpull/com.springsource.org.xmlpull/1.1.4.c
mvn:com.thoughtworks.xstream/com.springsource.com.thoughtworks.xstream/1.3.1
mvn:org.codehaus.jettison/com.springsource.org.codehaus.jettison/1.0.1
...

With this setup, whenever the project is built by jenkins, the post deploy script is triggered and the application is restarted in a clean, inital state.

In bndtools this is all automated ... Once you save a source file, it builds the jar and tells the framework which bundles to update or install when they are new. Try it, amazing short edit-compile-build-run-debug cycle of about 3 secs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!