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?
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