Script Shell Commands Karaf?

I need to issue the Karaf shell commands not interactively, preferably from a script. In particular, I need to tell Karaf feature:install set of functions in an automatic 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 it possible? Is there any other way to solve this problem (automatic installation of the Karaf feature set) that I am missing?

+6
source share
3 answers

With bin / karaf, you start Karaf with a login prompt if you want to start Karaf so that you can issue the commands that you first need to run Karaf in server mode. To do this, use the bin / start shell script. Now you can use the bin / client or bin / shell commands to communicate with Karaf in silent mode.

For instance:

 ./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 for version 2.2.x ;-))
If the version you are using is 3.0.x or higher, you may need to add the user to the team.

 ./bin/client -u karaf list 
+3
source

It is possible to issue non-interactive Karaf shell commands using sshpass if password security is not important.

 sshpass -p karaf ssh -tt -p 8101 -o StrictHostKeyChecking=no karaf@localhost feature:install odl-l2switch-switch-ui 

Working example in the OpenDaylight Vagrant-based L2Switch Tutorial .

+1
source

So the general practice is to install this function, and then in the loop: list | grep bundleName to find out if the packages you need are installed. Then you continue the test.

-1
source

Source: https://habr.com/ru/post/976893/


All Articles