Fresh from the oven: Knapsack for Apache Felix
by kengilmer
Both for my various weekend projects and on the BUG, I’ve been unhappy with the bundled launcher that comes with Felix. Equinox is no better. Typically people use the Eclipse tooling to create and configure framework instances, but when setting up for production or working with embedded targets this is often not possible. So I set out to make something that would allow me to easily get a framework up and running from the terminal. Luckily, Felix has excellent embedding support and documentation so it was pretty easy to get started.
What is it? Essentially an alternative launcher for the Felix OSGi framework (3.2.2) that uses the OS’s native shell for framework management, and creates all of the configuration files automatically, letting the user just download, run, and start adding their application bundles, with interactive feedback.
I’ve much more detail on the design details and usage on the project page and in the readme.
However, here is the summary of how to go from Zero to OSGi in 30 seconds*:
$ mkdir foo && cd foo $ wget https://leafcutter.ci.cloudbees.com/job/knapsack/lastSuccessfulBuild/artifact/knapsack.jar $ java -jar knapsack.jar &
* Depending, of course, on your copy-paste skillz.
[...] framework instances, but when setting up for production or working with embedded targets… Read more… Categories: Eclipse Share | Related [...]
Interesting! Was just trying it out on mac (OSX Snow Leopard) but it looks like things aren’t working as they should as bin/bundles and bin/help don’t print out anything (both on iTerm and Terminal). Any ideas?
$ java -jar knapsack.jar &
[davidb@pop ~/temp/knapsack $ INFO: Bundle org.apache.felix.framework [0] Scanning bundle directory: /Volumes/temp_encrypted/knapsack/bundle
INFO: SvcRef [org.knapsack.init.pub.KnapsackInitService] ServiceEvent REGISTERED
INFO: Bundle org.apache.felix.framework [0] Knapsack 0.6.0 running in /Volumes/temp_encrypted/knapsack
INFO: Bundle org.apache.felix.framework [0] BundleEvent STARTED
INFO: Bundle org.apache.felix.framework [0] FrameworkEvent STARTED
INFO: Framework started in 0.125 seconds with activators: [org.apache.felix.log.Activator@6fc5f743, org.apache.felix.cm.impl.ConfigurationManager@2dec8909, org.knapsack.Activator@418c56d]
INFO: Bundle org.apache.felix.framework [0] A new set of commands available: class org.knapsack.shell.BuiltinCommands
DEBUG:Bundle org.apache.felix.framework [0] Created symlink shutdown-knapsack
DEBUG:Bundle org.apache.felix.framework [0] Created symlink help
DEBUG:Bundle org.apache.felix.framework [0] Created symlink bundles
DEBUG:Bundle org.apache.felix.framework [0] Created symlink services
DEBUG:Bundle org.apache.felix.framework [0] Created symlink log
DEBUG:Bundle org.apache.felix.framework [0] Created symlink update
DEBUG:Bundle org.apache.felix.framework [0] Created symlink printconfig
DEBUG:Bundle org.apache.felix.framework [0] Created symlink headers
INFO: SvcRef [org.knapsack.shell.pub.IKnapsackCommandSet] ServiceEvent REGISTERED
INFO: Bundle org.apache.felix.framework [0] Created shell socket on port 12318
davidb@pop ~/temp/knapsack $ bin/bundles
davidb@pop ~/temp/knapsack $ bin/help
davidb@pop ~/temp/knapsack $
Hi David,
Hmm, I don’t have an OS X machine to test on. Do you have netcat installed? The shell script requires it to work, and presently doesn’t do any error checking: https://github.com/kgilmer/knapsack/blob/master/scripts/.knapsack-command.sh
Hi Ken,
Yes, I do have netcat on OSX:
$ nc
usage: nc [-46DdhklnrtUuvz] [-i interval] [-p source_port]
[-s source_ip_address] [-w timeout] [-X proxy_version]
[-x proxy_address[:port]] [hostname] [port[s]]
To avoid the issue, I just tried it out on Fedora 15 and it works fine there.
BTW I like the concept!
David, thanks for your feedback. I’ve created a github issue and I’ll update it when I can get access to an OS X machine to debug with.
https://github.com/kgilmer/knapsack/issues/1
cheers,
ken
David, a new version 0.7.0 is available that I hope should fix your issue: https://leafcutter.ci.cloudbees.com/job/knapsack/
Hi Ken,
I get a new error now, both on Fedora 15 and on Mac OSX Lion:
…
INFO: Bundle org.apache.felix.framework [0] Created shell socket on port 12299
$ bin/help
nc: invalid option — ‘q’
usage: nc [-46CDdhklnrStUuvz] [-I length] [-i interval] [-O length]
[-P proxy_username] [-p source_port] [-s source] [-T ToS]
[-V rtable] [-w timeout] [-X proxy_protocol]
[-x proxy_address[:port]] [destination] [port]
David, alas there are many netcats and they all have different interfaces. I’ve just pushed and built 0.8.0 that uses a new strategy (java client) that is slower but should work on all platforms. Additionally, the client can be customized (ie switch to your netcat with proper parameters) for additional performance. I hope this works for you!
It works, both on Mac and Fedora
Many thanks & very cool indeed!
David
Nice work! You might also be interested in my Groovy DSL for OSGi, which provides script based launching of an OSGi framework. See http://blog.jetztgrad.net/2011/01/groovyx-osgi-osgi-dsl-for-groovy/ for the introduction and https://github.com/jetztgradnet/groovyx-osgi/ for the code.
Hi Wolfgang,
I was not aware of your project. It looks very cool! I also don’t know much about groovy but can appreciate the functional simplicity of your code examples. But unlike Peter, I generally prefer “dependencies in code” (aka ServiceTracker) versus “dependencies via declaration” (aka DS), because I can always step through the debugger to find out whats going on…
Very cool! However, I tried this on my Nexus One (unlocked, 2.3.3 build) and it didn’t work. Please advise.
Thanks Boris. For Android support you’ll likely have to compile via the Android SDK and be sure to install BusyBox such that netcat is available.
I have the same problem on Ubuntu 10.10 that David described for Mac.
Hi Dominik,
Hmm, what version of netcat are you running? I have:
$ nc -v
This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
[-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
[-x proxy_address[:port]] [hostname] [port[s]]
Hi Ken,
$ nc -v
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
[-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
[-x proxy_address[:port]] [hostname] [port[s]]
Hi Dominik,
Thanks for your help with debugging. I was able to repro the issue on an Ubuntu server I have at home. I think I have it fixed although more work needs to be done for busybox compatibility. Please have a look at the 0.7.0 build here: https://leafcutter.ci.cloudbees.com/job/knapsack/
Hi Ken,
Thanks for the fix. It works! I will take a closer look to Knapsack now.