検索

このコンテンツは選択した言語では利用できません。

Chapter 13. Introduction to the Deploying into Apache Karaf user guide

download PDF

Abstract

Before you use this User Guide section of the Deploying into Apache Karaf guide, you must have installed the latest version of Red Hat Fuse, following the instructions in Installing on Apache Karaf.

13.1. Introducing Fuse Configuration

Abstract

The OSGi Configuration Admin service specifies the configuration information for deployed services and ensures that the services receive that data when they are active.

13.2. OSGi configuration

A configuration is a list of name-value pairs read from a .cfg file in the FUSE_HOME/etc directory. The file is interpreted using the Java properties file format. The filename is mapped to the persistent identifier (PID) of the service that is to be configured. In OSGi, a PID is used to identify a service across restarts of the container.

13.3. Configuration files

You can configure the Red Hat Fuse runtime using the following files:

Table 13.1. Fuse Configuration Files
FilenameDescription

config.properties

The main configuration file for the container.

custom.properties

The main configuration file for custom properties for the container.

keys.properties

Lists the users who can access the Fuse runtime using the SSH key-based protocol. The file’s contents take the format username=publicKey,role

org.apache.karaf.features.repos.cfg

The features repository URLs.

org.apache.karaf.features.cfg

Configures a list of feature repositories to be registered and a list of features to be installed when Fuse starts up for the first time.

org.apache.karaf.jaas.cfg

Configures options for the Karaf JAAS login module. Mainly used for configuring encrypted passwords (disabled by default).

org.apache.karaf.log.cfg

Configures the output of the log console commands.

org.apache.karaf.management.cfg

Configures the JMX system.

org.apache.karaf.shell.cfg

Configures the properties of remote consoles.

org.ops4j.pax.logging.cfg

Configures the logging system.

org.ops4j.pax.transx.tm.narayana.cfg

Narayana transaction manager configuration

org.ops4j.pax.url.mvn.cfg

Configures additional URL resolvers.

org.ops4j.pax.web.cfg

Configures the default Jetty container (Web server). See olink:FMQSecurity/WebConsole.

startup.properties

Specifies which bundles are started in the container and their start-levels. Entries take the format bundle=start-level.

system.properties

Specifies Java system properties. Any properties set in this file are available at runtime using System.getProperties().

users.properties

Lists the users who can access the Fuse runtime either remotely or via the web console. The file’s contents take the format username=password,role

setenv or setenv.bat

This file is in the /bin directory. It is used to set JVM options. The file’s contents take the format JAVA_MIN_MEM=512M, where 512M is the minimum size of Java memory. See the section called “Setting Java Options” for more information.

Configuration file naming convention

The file naming convention for configuration files depends on whether the configuration is intended for an OSGi Managed Service or for an OSGi Managed Service factory.

The configuration file for an OSGi Managed Service obeys the following naming convention:

<PID>.cfg

Where <PID> is the persistent ID of the OSGi Managed Service (as defined in the OSGi Configuration Admin specification). A persistent ID is normally dot-delimited—for example, org.ops4j.pax.web.

The configuration file for an OSGi Managed Service Factory obeys the following naming convention:

<PID>-<InstanceID>.cfg

Where <PID> is the persistent ID of the OSGi Managed Service Factory. In the case of a managed service factory’s <PID>, you can append a hyphen followed by an arbitrary instance ID, <InstanceID>. The managed service factory then creates a unique service instance for each <InstanceID> that it finds.

Setting Java Options

Java Options can be set using the /bin/setenv file in Linux, or the bin/setenv.bat file for Windows. Use this file to directly set a group of Java options: JAVA_MIN_MEM, JAVA_MAX_MEM, JAVA_PERM_MEM, JAVA_MAX_PERM_MEM. Other Java options can be set using the EXTRA_JAVA_OPTS variable.

For example, to allocate minimum memory for the JVM use

JAVA_MIN_MEM=512M # Minimum memory for the JVM
To set a Java option other than the direct options, use
EXTRA_JAVA_OPTS="Java option"
For example,
EXTRA_JAVA_OPTS="-XX:+UseG1GC"

13.4. Config Console Commands

There are a number of console commands that can be used to change or interrogate the configuration of Fuse 7.1.

See the Config section in the Apache Karaf Console Reference for more details about the config: commands.

13.5. JMX ConfigMBean

On the JMX layer, the MBean is dedicated to configuration management.

The ConfigMBean object name is: org.apache.karaf:type=config,name=*`.

14.1.2.1. Attributes

The config MBean contains a list of all configuration PIDs.

14.1.2.2. Operations

Table 13.2. JMX MBean Operations
Operation nameDescription

listProperties(pid)

returns the list of properties (property=value formatted) for the configuration pid.

deleteProperty(pid, property)

deletes the property from the configuration pid.

appendProperty(pid, property, value)

appends value at the end of the value of the property of the configuration pid.

setProperty(pid, property, value)

sets value for the value of the property of the configuration pid.

delete(pid)

deletes the configuration identified by the pid.

create(pid)

creates an empty (without any property) configuration with pid.

update(pid, properties)

updates a configuration identified with pid with the provided properties map.

13.6. Using the console

13.6.1. Available commands

To see a list of the available commands in the console, you can use the help:

karaf@root()> help
bundle                            Enter the subshell
bundle:capabilities               Displays OSGi capabilities of a given bundles.
bundle:classes                    Displays a list of classes/resources contained in the bundle
bundle:diag                       Displays diagnostic information why a bundle is not Active
bundle:dynamic-import             Enables/disables dynamic-import for a given bundle.
bundle:find-class                 Locates a specified class in any deployed bundle
bundle:headers                    Displays OSGi headers of a given bundles.
bundle:id                         Gets the bundle ID.
...

You have the list of all commands with a short description.

You can use the tab key to get a quick list of all commands:

karaf@root()> Display all 294 possibilities? (y or n)
...

13.6.2. Subshell and completion mode

The commands have a scope and a name. For instance, the command feature:list has feature as scope, and list as name.

Karaf "groups" the commands by scope. Each scope form a subshell.

You can directly execute a command with its full qualified name (scope:name):

karaf@root()> feature:list
...

or enter in a subshell and type the command contextual to the subshell:

karaf@root()> feature
karaf@root(feature)> list

You can note that you enter in a subshell directly by typing the subshell name (here feature). You can "switch" directly from a subshell to another:

karaf@root()> feature
karaf@root(feature)> bundle
karaf@root(bundle)>

The prompt displays the current subshell between ().

The exit command goes to the parent subshell:

karaf@root()> feature
karaf@root(feature)> exit
karaf@root()>

The completion mode defines the behaviour of the tab key and the help command.

You have three different modes available:

  • GLOBAL
  • FIRST
  • SUBSHELL

You can define your default completion mode using the completionMode property in etc/org.apache.karaf.shell.cfg file. By default, you have:

completionMode = GLOBAL

You can also change the completion mode “on the fly” (while using the Karaf shell console) using the shell:completion command:

karaf@root()> shell:completion
GLOBAL
karaf@root()> shell:completion FIRST
karaf@root()> shell:completion
FIRST

shell:completion can inform you about the current completion mode used. You can also provide the new completion mode that you want.

GLOBAL completion mode is the default one in Karaf 4.0.0 (mostly for transition purpose).

GLOBAL mode doesn’t really use subshell: it’s the same behavior as in previous Karaf versions.

When you type the tab key, whatever in which subshell you are, the completion will display all commands and all aliases:

karaf@root()> <TAB>
karaf@root()> Display all 273 possibilities? (y or n)
...
karaf@root()> feature
karaf@root(feature)> <TAB>
karaf@root(feature)> Display all 273 possibilities? (y or n)

FIRST completion mode is an alternative to the GLOBAL completion mode.

If you type the tab key on the root level subshell, the completion will display the commands and the aliases from all subshells (as in GLOBAL mode). However, if you type the tab key when you are in a subshell, the completion will display only the commands of the current subshell:

karaf@root()> shell:completion FIRST
karaf@root()> <TAB>
karaf@root()> Display all 273 possibilities? (y or n)
...
karaf@root()> feature
karaf@root(feature)> <TAB>
karaf@root(feature)>
info install list repo-add repo-list repo-remove uninstall version-list
karaf@root(feature)> exit
karaf@root()> log
karaf@root(log)> <TAB>
karaf@root(log)>
clear display exception-display get log set tail

SUBSHELL completion mode is the real subshell mode.

If you type the tab key on the root level, the completion displays the subshell commands (to go into a subshell), and the global aliases. Once you are in a subshell, if you type the TAB key, the completion displays the commands of the current subshell:

karaf@root()> shell:completion SUBSHELL
karaf@root()> <TAB>
karaf@root()>
* bundle cl config dev feature help instance jaas kar la ld lde log log:list man package region service shell ssh system
karaf@root()> bundle
karaf@root(bundle)> <TAB>
karaf@root(bundle)>
capabilities classes diag dynamic-import find-class headers info install list refresh requirements resolve restart services start start-level stop
uninstall update watch
karaf@root(bundle)> exit
karaf@root()> camel
karaf@root(camel)> <TAB>
karaf@root(camel)>
backlog-tracer-dump backlog-tracer-info backlog-tracer-start backlog-tracer-stop context-info context-list context-start context-stop endpoint-list route-info route-list route-profile route-reset-stats
route-resume route-show route-start route-stop route-suspend

13.6.3. Unix like environment

Karaf console provides a full Unix like environment.

13.6.3.1. Help or man

We already saw the usage of the help command to display all commands available.

But you can also use the help command to get details about a command or the man command which is an alias to the help command. You can also use another form to get the command help, by using the --help option to the command.

So these commands

karaf@root()> help feature:list
karaf@root()> man feature:list
karaf@root()> feature:list --help

All produce the same help output:

DESCRIPTION
        feature:list

        Lists all existing features available from the defined repositories.

SYNTAX
        feature:list [options]

OPTIONS
        --help
                Display this help message
        -o, --ordered
                Display a list using alphabetical order
        -i, --installed
                Display a list of all installed features only
        --no-format
                Disable table rendered output

13.6.3.2. Completion

When you type the tab key, Karaf tries to complete:

  • subshell
  • commands
  • aliases
  • command arguments
  • command options

13.6.3.3. Alias

An alias is another name associated to a given command.

The shell:alias command creates a new alias. For instance, to create the list-installed-features alias to the actual feature:list -i command, you can do:

karaf@root()> alias "list-features-installed = { feature:list -i }"
karaf@root()> list-features-installed
Name       | Version | Required | State   | Repository     | Description
------------------------------------------------------------------------------------------------------------------------------
feature    | 4.0.0   | x        | Started | standard-4.0.0 | Features Support
shell      | 4.0.0   | x        | Started | standard-4.0.0 | Karaf Shell
deployer   | 4.0.0   | x        | Started | standard-4.0.0 | Karaf Deployer
bundle     | 4.0.0   | x        | Started | standard-4.0.0 | Provide Bundle support
config     | 4.0.0   | x        | Started | standard-4.0.0 | Provide OSGi ConfigAdmin support
diagnostic | 4.0.0   | x        | Started | standard-4.0.0 | Provide Diagnostic support
instance   | 4.0.0   | x        | Started | standard-4.0.0 | Provide Instance support
jaas       | 4.0.0   | x        | Started | standard-4.0.0 | Provide JAAS support
log        | 4.0.0   | x        | Started | standard-4.0.0 | Provide Log support
package    | 4.0.0   | x        | Started | standard-4.0.0 | Package commands and mbeans
service    | 4.0.0   | x        | Started | standard-4.0.0 | Provide Service support
system     | 4.0.0   | x        | Started | standard-4.0.0 | Provide System support
kar        | 4.0.0   | x        | Started | standard-4.0.0 | Provide KAR (KARaf archive) support
ssh        | 4.0.0   | x        | Started | standard-4.0.0 | Provide a SSHd server on Karaf
management | 4.0.0   | x        | Started | standard-4.0.0 | Provide a JMX MBeanServer and a set of MBeans in

At login, the Apache Karaf console reads the etc/shell.init.script file where you can create your aliases. It’s similar to a bashrc or profile file on Unix.

ld = { log:display $args } ;
lde = { log:exception-display $args } ;
la = { bundle:list -t 0 $args } ;
ls = { service:list $args } ;
cl = { config:list "(service.pid=$args)" } ;
halt = { system:shutdown -h -f $args } ;
help = { *:help $args | more } ;
man = { help $args } ;
log:list = { log:get ALL } ;

You can see here the aliases available by default:

  • ld is a short form to display log (alias to log:display command)
  • lde is a short form to display exceptions (alias to log:exception-display command)
  • la is a short form to list all bundles (alias to bundle:list -t 0 command)
  • ls is a short form to list all services (alias to service:list command)
  • cl is a short form to list all configurations (alias to config:list command)
  • halt is a short form to shutdown Apache Karaf (alias to system:shutdown -h -f command)
  • help is a short form to display help (alias to *:help command)
  • man is the same as help (alias to help command)
  • log:list displays all loggers and level (alias to log:get ALL command)

You can create your own aliases in the etc/shell.init.script file.

13.6.3.4. Key binding

Like on most Unix environment, Karaf console support some key bindings:

  • the arrows key to navigate in the commands history
  • CTRL-D to logout/shutdown Karaf
  • CTRL-R to search previously executed command
  • CTRL-U to remove the current line

13.6.3.5. Pipe

You can pipe the output of one command as input to another one. It’s a pipe, using the | character:

karaf@root()> feature:list |grep -i war
pax-war                       | 4.1.4                            |          | Uninstalled | org.ops4j.pax.web-4.1.4  | Provide support of a full WebContainer
pax-war-tomcat                | 4.1.4                            |          | Uninstalled | org.ops4j.pax.web-4.1.4  |
war                           | 4.0.0                            |          | Uninstalled | standard-4.0.0           | Turn Karaf as a full WebContainer
blueprint-web                 | 4.0.0                            |          | Uninstalled | standard-4.0.0           | Provides an OSGI-aware Servlet ContextListener fo

13.6.3.6. Grep, more, find, …​

Karaf console provides some core commands similar to Unix environment:

  • shell:alias creates an alias to an existing command
  • shell:cat displays the content of a file or URL
  • shell:clear clears the current console display
  • shell:completion displays or change the current completion mode
  • shell:date displays the current date (optionally using a format)
  • shell:each executes a closure on a list of arguments
  • shell:echo echoes and prints arguments to stdout
  • shell:edit calls a text editor on the current file or URL
  • shell:env displays or sets the value of a shell session variable
  • shell:exec executes a system command
  • shell:grep prints lines matching the given pattern
  • shell:head displays the first line of the input
  • shell:history prints the commands history
  • shell:if allows you to use conditions (if, then, else blocks) in script
  • shell:info prints various information about the current Karaf instance
  • shell:java executes a Java application
  • shell:less file pager
  • shell:logout disconnects shell from current session
  • shell:more is a file pager
  • shell:new creates a new Java object
  • shell:printf formats and prints arguments
  • shell:sleep sleeps for a bit then wakes up
  • shell:sort writes sorted concatenation of all files to stdout
  • shell:source executes commands contained in a script
  • shell:stack-traces-print prints the full stack trace in the console when the execution of a command throws an exception
  • shell:tac captures the STDIN and returns it as a string
  • shell:tail displays the last lines of the input
  • shell:threads prints the current thread
  • shell:watch periodically executes a command and refresh the output
  • shell:wc prints newline, words, and byte counts for each file
  • shell:while loop while the condition is true

You don’t have to use the fully qualified name of the command, you can directly use the command name as long as it is unique. So you can use 'head' instead of 'shell:head'

Again, you can find details and all options of these commands using help command or --help option.

13.6.3.7. Scripting

The Apache Karaf Console supports a complete scripting language, similar to bash or csh on Unix.

The each (shell:each) command can iterate in a list:

karaf@root()> list = [1 2 3]; each ($list) { echo $it }
1
2
3
Note

The same loop could be written with the shell:while command:

karaf@root()> a = 0 ; while { %((a+=1) <= 3) } { echo $a }
1
2
3

You can create the list yourself (as in the previous example), or some commands can return a list too.

We can note that the console created a "session" variable with the name list that you can access with $list.

The $it variable is an implicit one corresponding to the current object (here the current iterated value from the list).

When you create a list with [], Apache Karaf console creates a Java ArrayList. It means that you can use methods available in the ArrayList objects (like get or size for instance):

karaf@root()> list = ["Hello" world]; echo ($list get 0) ($list get 1)
Hello world

We can note here that calling a method on an object is directly using (object method argument). Here ($list get 0) means $list.get(0) where $list is the ArrayList.

The class notation will display details about the object:

karaf@root()> $list class
...
ProtectionDomain     ProtectionDomain  null
 null
 <no principals>
 java.security.Permissions@6521c24e (
 ("java.security.AllPermission" "<all permissions>" "<all actions>")
)


Signers              null
SimpleName           ArrayList
TypeParameters       [E]

You can "cast" a variable to a given type.

karaf@root()> ("hello world" toCharArray)
[h, e, l, l, o,  , w, o, r, l, d]

If it fails, you will see the casting exception:

karaf@root()> ("hello world" toCharArray)[0]
Error executing command: [C cannot be cast to [Ljava.lang.Object;

You can "call" a script using the shell:source command:

karaf@root> shell:source script.txt
True!

where script.txt contains:

foo = "foo"
if { $foo equals "foo" } {
  echo "True!"
}
Note

The spaces are important when writing script. For instance, the following script is not correct:

if{ $foo equals "foo" } ...

and will fail with:

karaf@root> shell:source script.txt
Error executing command: Cannot coerce echo "true!"() to any of []

because a space is missing after the if statement.

As for the aliases, you can create init scripts in the etc/shell.init.script file. You can also named you script with an alias. Actually, the aliases are just scripts.

See the Scripting section of the developers guide for details.

13.6.4. Security

The Apache Karaf console supports a Role Based Access Control (RBAC) security mechanism. It means that depending of the user connected to the console, you can define, depending of the user’s groups and roles, the permission to execute some commands, or limit the values allowed for the arguments.

Console security is detailed in the Security section of this user guide.

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.