The ingredients of this recipe include the Apache Karaf distribution kit, access to JDK, and a source code editor. The sample wrapper configuration for this recipe is available at https://github.com/jgoodyear/ApacheKarafCookbook/tree/master/chapter1/chapter1-recipe7.
The first step is installing the service wrapper feature. Apache Karaf utilizes a service wrapper feature to handle gathering and deploying of the required resources for your host operating environment. We begin its installation by invoking the following command:
The service wrapper feature URL is included in Karaf by default; so, no additional step is required to make it available.
karaf@root()>wrapper:install –s AUTO_START –n Karaf3 –D "Apache Karaf Cookbook"
wrapper:installcommand invocation includes three flags:
-sfor the start type,
-nfor the service name, and
–Dfor the service description. The start type can be one of two options:
AUTO_START, to automatically start the service on boot, and
DEMAND_START, to start only when manually invoked. The service name is used as an identifier in the host's service registry. The description provides system administrators with a brief description of your Karaf installation. After executing the
installcommand, the Karaf console will display the libraries, scripts, and configuration files that the wrapper generates. You'll now need to exit Karaf to continue the service installation.
The final step is integrating it in to the host operating system. This step will require administrator level permissions to execute the generated Karaf service wrapper installation scripts.
The following command installs the service natively into Windows:
C:> C:\Path\To\apache-karaf-3.0.0\bin\Karaf3-service.bat install
netcommands allow an administrator to start or stop the Karaf service:
C:> net start "Karaf3" C:> net stop "Karaf3"
Linux integration will vary based on distribution. The following commands will work on Debian- or Ubuntu-based systems:
jgoodyear@ubuntu1204:~$ ln –s /Path/To/apache-karaf-3.0.0/bin/Karaf3-service /etc/init.d jgoodyear@ubuntu1204:~$ update-rc.d Karaf3-service defaults jgoodyear@ubuntu1204:~$ /etc/init.d/Karaf3-service start jgoodyear@ubuntu1204:~$ /etc/init.d/Karaf3-service stop
The first command creates a symbolic link from the service script in Karaf's
binfolder to the
init.ddirectory and then updates the startup scripts to include the Karaf service to automatically start during boot. The remaining two commands can be used to manually start or stop the Karaf service.
The wrapper service feature integrates Karaf into the host operating system's service mechanism. This means that on a Windows- or Linux-based system, Karaf will avail of the available fault, crash, processing freeze, out of memory, or similar event detections and automatically attempt to restart Karaf.