Edit: It is now possible to install karaf on debian without building it yourself, the package installed is not the one described here, but the new and improved package built from source with native debian packaging tools, that can be found here https://github.com/steinarb/karaf-debian
Apache karaf is an OSGi container/application server with some nice properties:
- It has an SSH server you can log into and a command line where you can inspect and configure the karaf instance
- It can be provisioned using apache maven, basically you can start with an empty karaf, ssh into the SSH server and pull in and start your application using “maven magic”
- It is much simpler to get an OSGi application up and running in apache karaf, than in any other system I have tried, since I first was to introduced to OSGi in 2006
- Karaf can also be used to run non-OSGi applications packaged as jar or war files
- In a development setting is very simple to deploy new versions of the code using maven and remote debug the deployed code frome eclipse or IntelliJ
Running karaf on a debian GNU/linux system is a little hampered by there not being a native .deb package. I have opened an RFP (Request For Packaging) bug for karaf in the debian bug tracker. When/if that issue is ever resolved as done, karaf will be easily availabel on debian and also on all of the distros that are based on debian (e.g. ubuntu and mint).
Until then do my own debian packaging. I forked the packaging I found at https://github.com/DemisR/karaf-deb-packaging and made some changes:
- Switched from oracle JDK 8, to openjdk 8
- Updated to karaf version 4.0.7 (the currently newest stable release at the time of forking), later upgraded to karaf 4.1.1 and again upgraded to karaf 4.1.2
- Use /var/lib/karaf/data instead of /usr/local/karaf/data
- Use package version “-1” instead of “-3”
- Switched from using the the service wrapper (karaf-wrapper) to plain systemd start using the scripts and config from bin/contrib in the karaf distribution
- Made the stop of running services more robust
The resulting .deb package will follow the usual service pattern of a debian service: the service will run with a user named after the service (i.e. user “karaf” which is the single member of group “karaf” and the owner of all files the service need to touch). The service will log to the regular debian syslog. The configuration will end up in /etc/karaf and all files not part of the installation will be left untouched on a .deb package uninstall and upgrade.
My fork of the packaging, lives at https://github.com/steinarb/karaf-deb-packaging
To create the package and install karaf, do the following steps:
- Log in as root on a debian system
- Install the prequisites for building the package, debian packages and ruby gem:
apt-get update apt-get install git maven openjdk-8-jdk postgresql ruby ruby-dev build-essential gem install fpm
- Clone the packaging project and build the deb package:
cd /tmp git clone https://github.com/steinarb/karaf-deb-packaging cd karaf-deb-packaging ./dist_karaf.sh mkdir -p /root/debs cp *.deb /root/debs
- Install the .deb package:
dpkg --install karaf_4.1.4-1_all.deb
After karaf has been installed it is possible to log in as user “karaf”, with the following command
ssh -p 8101 karaf@localhost
The password is also “karaf” (without the quotes).
This opens the karaf console command line
__ __ ____ / //_/____ __________ _/ __/ / ,< / __ `/ ___/ __ `/ /_ / /| |/ /_/ / / / /_/ / __/ /_/ |_|\__,_/_/ \__,_/_/ Apache Karaf (4.1.4) Hit '<tab>' for a list of available commands and '[cmd] --help' for help on a specific command. Hit 'system:shutdown' to shutdown Karaf. Hit '<ctrl-d>' or type 'logout' to disconnect shell from current session. karaf@root()>
At this command line, you can eg.
- install an application
- start, stop and list running applications
- set the configuration used by the applications
But all of these except for the first, will be items for later posts.