I need to issue Karaf shell commands non-interactively, preferably from a script. More specifically, I need to tell Karaf to feature:install
a set of features in an automated way.
# Attempt to install a feature in a way I could script
bash> bin/karaf feature:install myFeature
# Drops me into Karaf shell
karaf> feature:uninstall myFeature
Error executing command: Feature named 'myFeature' is not installed
# Feature wasn't installed
Is this possible? Is there a different way of solving this issue (automated install of a set of Karaf features) that I'm missing?
Karaf provides a powerful console and a set of commands that can be used to perform various tasks. Commands can be located in the root shell or in a sub-shell.
Apache Karaf is powered by OSGi (but you don't need to know what OSGi is to use Karaf). Apache Karaf uses either the Apache Felix or Eclipse Equinox OSGi frameworks, providing additional features on top of the framework.
With bin/karaf you start Karaf with a login prompt, if you want to start Karaf so you can issue commands you first need to start Karaf in server mode. For this use the bin/start shell script. Now you can use either the bin/client or the bin/shell commands to communicate with Karaf in a headless mode.
For example:
./bin/client list
START LEVEL 100 , List Threshold: 50
ID | State | Lvl | Version | Name
----------------------------------------------------------------------------------
72 | Active | 80 | 0 | mvn_org.ops4j.pax.web.samples_war_4.1.0-SNAPSHOT_war
This should work for all versions of Karaf already (maybe not the 2.2.x line ;-) )
If the version you're using is a 3.0.x or higher you might need to add a user to the command.
./bin/client -u karaf list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With