9/05/2014

Building and installing Apache Karaf 2.2.5 or 2.3.11 from sources (no sudo needed)

In my ~/.m2/settings.xml, I have a separate profile which uses a local Nexus repository as a proxy to all the remotes. It is not active by default, only activated with the -P local switch. Thus please don't update your settings.xml like this if you don't have a local Nexus proxy (and you won't need the "-P local" switch later neither in this case). The relevant part of my settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>local</id>
            <!--<activation>-->
            <!--<activeByDefault>true</activeByDefault>-->
            <!--</activation>-->
            <properties>
                <repos.release.url>http://127.0.0.1:8081/content/groups/public</repos.release.url>
                <repos.snapshot.url>http://127.0.0.1:8081/content/groups/public</repos.snapshot.url>
            </properties>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>public</name>
                    <url>http://127.0.0.1:8081/content/groups/public</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <name>snapshots</name>
                    <url>http://127.0.0.1:8081/content/repositories/snapshots</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>false</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </repository>
                <repository>
                    <id>releases</id>
                    <name>releases</name>
                    <url>http://127.0.0.1:8081/content/repositories/releases</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>public</name>
                    <url>http://127.0.0.1:8081/content/groups/public</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <name>snapshots</name>
                    <url>http://127.0.0.1:8081/content/repositories/snapshots</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>false</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </pluginRepository>
                <pluginRepository>
                    <id>releases</id>
                    <name>releases</name>
                    <url>http://127.0.0.1:8081/content/repositories/releases</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

...and the script for the build for version 2.2.5:
mkdir -p ~/tools
cd ~/tools
wget http://archive.apache.org/dist/karaf/2.2.5/apache-karaf-2.2.5-src.tar.gz
tar xvzf apache-karaf-2.2.5-src.tar.gz
cd apache-karaf-2.2.5/src
mvn clean install -DskipTests -P local
sudo mkdir -p /opt
cd /opt
sudo tar xvzf ~/tools/apache-karaf-2.2.5/src/assemblies/apache-karaf/target/apache-karaf-2.2.5.tar.gz
sudo ln -s apache-karaf-2.2.5 karaf

For version 2.3.11

mkdir -p ~/tools
cd ~/tools
wget http://archive.apache.org/dist/karaf/2.3.11/apache-karaf-2.3.11-src.tar.gz
tar xvzf apache-karaf-2.3.11-src.tar.gz
cd apache-karaf-2.3.11/src
mvn clean install -DskipTests -P local
sudo mkdir -p /opt
cd /opt
sudo tar xvzf ~/tools/apache-karaf-2.3.11/src/assemblies/apache-karaf/target/apache-karaf-2.3.11.tar.gz
sudo ln -s apache-karaf-2.3.11 karaf

Autostart on Ubuntu: to wrap or not to wrap

If you try to install the wrapper to achieve autostart, everything seems to be fine, but the wrapper segfaults on subsequent reboots, at least that's the sad situation on Ubuntu 12.04.5. This used to work before.
Still it has to work, so the workaround is to create a /etc/init.d/karaf script with this content:
#!/bin/bash

KARAF_HOME=/home/neusoft/tools/karaf

case "$1" in
  start)
    log_begin_msg "Starting Karaf..."
        $KARAF_HOME/bin/start
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Shutting down Karaf..."
        $KARAF_HOME/bin/stop
    log_end_msg 0
    ;;
  *)
  ;;
esac
To register the file with the system
sudo update-rc.d karaf defaults 98 02

Autostart on FreeBSD

Using FreeBSD, autostarting the service is different:

echo 'karaf_enable="YES"' | sudo tee -a /etc/rc.conf > /dev/null

The rc.conf entry will start the script under /etc/rc.d. And the contents of the /etc/rc.d/karaf file:

#!/bin/sh
. /etc/rc.subr
export KARAF_OPTS="-Dkey=value"
start_cmd="karaf_start"
stop_cmd="karaf_stop"
karaf_start() {
        export JAVA_HOME=/usr/local/openjdk7
        /opt/karaf/bin/start
}
karaf_stop() {
        export JAVA_HOME=/usr/local/openjdk7
        /opt/karaf/bin/stop
}
load_rc_config $name
run_rc_command "$1"

Then you just have to make it executable:

sudo chmod +x /etc/rc.d/karaf

Or even make a symbolic link for the ones expect logs to be at standard places:

sudo ln -s /opt/karaf/data/log /var/log/karaf

Gotchas

Building on OSX Yosemite with Apple's JDK 1.6 succeeds, but logging on shows that we have a crippled container:

# features:addurl http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo.features/1.12.0/org.apache.felix.ipojo.features-1.12.0.xml
# Command not found: features:addurl

Investigating /opt/karaf/data/log/karaf.log shows us the cause of the error:

"Bundle org.apache.karaf.features.command is waiting for dependencies [(objectClass=org.apache.karaf.features.FeaturesService)]"

Installing Oracle JDK 1.7 & setting JAVA_HOME appropriately fixes the problem.

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
...
(rebuild the whole shebang)
...

No comments:

Post a Comment