Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script Karaf shell commands?

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?

like image 375
dfarrell07 Avatar asked Oct 17 '14 22:10

dfarrell07


People also ask

What is Karaf console?

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.

Is Karaf a OSGi?

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.


1 Answers

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
like image 100
Achim Nierbeck Avatar answered Sep 29 '22 11:09

Achim Nierbeck