Questo contenuto non è disponibile nella lingua selezionata.
Chapter 4. Installing Apache Karaf as a Service
This chapter provides information on how you can start an Apache Karaf instance as a system service using the provided templates.
4.1. Overview
Using the service script templates, you can run a Karaf instance with the help of operating system specific init scripts. You can find these templates under the bin/contrib
directory.
4.2. Running Karaf as a Service
The karaf-service.sh
utility helps you to customize the templates. This utility automatically identifies the operating system and the default init system and generates ready-to-use init scripts. You can also customize the scripts to adapt them to the environment, by setting JAVA_HOME
and a few other environment variables.
The generated scripts are composed of two files:
- The init script
- The init configuration file
4.3. Systemd
When the karaf-service.sh
utility identifies systemd
, it generates three files:
-
A
systemd
unit file to manage the root Apache Karaf container. -
A
systemd
environment file with variables used by the root Apache Karaf container. -
(Not supported) A
systemd
template unit file to manage Apache Karaf child containers.
For example, to set up a service for a Karaf instance installed at /opt/karaf-4
, giving the service the name, karaf-4
:
$ ./karaf-service.sh -k /opt/karaf-4 -n karaf-4 Writing service file "/opt/karaf-4/bin/contrib/karaf-4.service" Writing service configuration file ""/opt/karaf-4/etc/karaf-4.conf" Writing service file "/opt/karaf-4/bin/contrib/karaf-4@.service" $ sudo cp /opt/karaf-4/bin/contrib/karaf-4.service /etc/systemd/system $ sudo systemctl enable karaf-4.service
4.4. SysV
When the karaf-service.sh
utility identifies a SysV system, it generates two files:
- An init script to manage the root Apache Karaf container.
- An environment file with variables used by the root Apache Karaf container.
For example, to set up a service for a Karaf instance installed at /opt/karaf-4
, giving the service the name, karaf-4
:
$ ./karaf-service.sh -k /opt/karaf-4 -n karaf-4 Writing service file "/opt/karaf-4/bin/contrib/karaf-4" Writing service configuration file "/opt/karaf-4/etc/karaf-4.conf" $ sudo ln -s /opt/karaf-4/bin/contrib/karaf-4 /etc/init.d/ $ sudo chkconfig karaf-4 on
To enable the service startup upon boot, refer to your operating system init guide.
4.5. Solaris SMF
When the karaf-service.sh
utility identifies a Solaris operating system, it generates a single file.
For example, to set up a service for a Karaf instance installed at /opt/karaf-4
, giving the service the name, karaf-4
:
$ ./karaf-service.sh -k /opt/karaf-4 -n karaf-4 Writing service file "/opt/karaf-4/bin/contrib/karaf-4.xml" $ sudo svccfg validate /opt/karaf-4/bin/contrib/karaf-4.xml $ sudo svccfg import /opt/karaf-4/bin/contrib/karaf-4.xml
The generated SMF descriptor is defined as transient, so that you can execute the start method only once.
4.6. Windows
Installation of Apache Karaf as Windows service is supported through winsw
.
To install Apache Karaf as Windows service, perform the following steps:
-
Rename the
karaf-service-win.exe
file tokaraf-4.exe
. -
Rename the
karaf-service-win.xml
file tokaraf-4.xml
. - Customize the service descriptor as required.
- Use the service executable to install, start and stop the service.
For example:
C:\opt\apache-karaf-4\bin\contrib> karaf-4.exe install C:\opt\apache-karaf-4\bin\contrib> karaf-4.exe start
4.7. karaf-service.sh Options
You can specify options to the karaf-service.sh
utility either as command-line options or by setting environment variables, as follows:
Command Line Option | Environment Variable | Description |
---|---|---|
|
| Karaf installation path |
|
|
Karaf data path (defaults to |
|
|
Karaf configuration file (defaults to |
|
|
Karaf |
|
|
Karaf PID path (defaults to |
|
|
Karaf service name (defaults to |
|
|
Specifies an environment variable setting, |
|
| Karaf user |
|
|
Karaf group (defaults to |
|
|
Karaf console log (defaults to |
|
| Template file to use |
|
|
Karaf executable name (defaults to |
| Help message |