Friday, 21 September 2012

Openldap2.4 performance boosting

According to my experience, the single directive you should add to db section to improve performance is:

olcDbCacheSize

OpenLDAP tuning guide covers that in section: 21.4.2.

To enable a 200000 entries cachesize use this ldif:

The enumeration of the whole directory (150000 entries) took 15 seconds without cachesize and less than 6 seconds with it.

Thursday, 20 September 2012

Instant logger replacement to logback in activemq.5.6.0

In activemq-5.6.0 changing logger to logback is just a matter of seconds:
  • Copy the following jar in ${activemq.base}/lib:
    logback-access-1.0.0.jar
    logback-classic-1.0.0.jar
    
  • Create a logback.xml file in ${activemq.base}/conf, for example:

That's all.

What about the activemq logback logging to a jms system which is activemq?

Tuesday, 4 September 2012

Ppolicy overlay password checking module

How about having openldap-2.4 checking whether the changed password is digit-only or alpha-only and than rejecting it?

It could be done with the non-standard password checking module openldap extension, which requires to create a C file with your rules, compile as a shared object and put in a well-known location.

I wrote a step-by-step recipe with a template C file at:
https://github.com/francescm/ppolicy-check-password

Friday, 25 May 2012

akka, camel and jruby

After reading Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors by Venkat Subramaniam I tried my first akka project in jruby.

To be somehow useful, it had to cope with true messaging (ActiveMQ), so the choice for the glue technology was Apache Camel and Spring.
The hardest part was:
  • getting right the header  (schema and namespace definition) in camel-context.xml. The matter is akka changed namespace at least twice;
  • gathering all dependecies. In fact I didn't use maven or similar so I had to search all jars nearly one by one.
You can have a look at the resulting code at: https://github.com/francescm/akka-camel-jruby

Monday, 21 November 2011

Openldap2.4.26, BerkeleyDB-5.2 and Sasl from scratch

In these days I've deployed a openldap server with openldap-2.4.26, BerkeleyDB.5.2 and cyrus-sasl-2.1.23.

First of all make sure no *-dev packeges are installed for bdb or for sasl.

Start with BerkeleyDB: download from the oracle site, expand and:
cd db-5.2.36/
cd build_unix && ../dist/configure --prefix=/usr/local/BerkeleyDB.5.2/
make
sudo make install

Now it's time for sasl. I got the cyrus-sasl-2.1.23.tar.gz package from: http://cyrusimap.web.cmu.edu/mediawiki/index.php/Cyrus_SASL

Expand it and apply patch: http://repos.archlinuxppc.org/wsvn/filedetails.php?repname=packages&path=%2Fcyrus-sasl-plugins%2Ftrunk%2Fcyrus-sasl-2.1.23-db5-fix.patch.

The patch is actually a patch to two files. To apply a patch a
patch -p1 < patchfile
should work. If there are rejected chunks, move to the dir of the file to be modified and apply only the part of the patch that refers to that file. Write a compile script:
#!/bin/bash

export LDFLAGS="-L/usr/local/BerkeleyDB.5.2/lib"
export LD_LIBRARY_PATH=/usr/local/BerkeleyDB.5.2/lib/

sed -i.bak 's/#elif WITH_DES/#elif defined(WITH_DES)/' \
    plugins/digestmd5.c &&
env CPPFLAGS="-I/usr/local/BerkeleyDB.5.2/include/" \
LDFLAGS="-L/usr/local/BerkeleyDB.5.2/lib/ -R/usr/local/BerkeleyDB.5.2/lib" \
./configure --with-dblib=berkeley --prefix=/usr/local/sasl-2.1.23/
Execute the compile script followed by make and sudo make install. Remember to create the soft link from /usr/local/sasl-2.1.23/lib/sasl2 to /usr/lib/sasl2.
sudo ln -s /usr/local/sasl-2.1.23/lib/sasl2 .
To compile openldap, download and expand the packege, write a compilation script:
#!/bin/bash

export LDFLAGS="-L/usr/local/BerkeleyDB.5.2/lib"
export LD_LIBRARY_PATH=/usr/local/BerkeleyDB.5.2/lib/

env CPPFLAGS="-I/usr/local/BerkeleyDB.5.2/include/ \
 -I/usr/local/sasl-2.1.23/include/" \
LDFLAGS="-L/usr/local/BerkeleyDB.5.2/lib/ -L/usr/local/sasl-2.1.23/lib/" \
./configure --enable-crypt --enable-hdb=yes --enable-ppolicy \
--with-cyrus-sasl --with-tls=openssl --enable-overlays \
--enable-valsort --localstatedir=/var/lib/ --prefix=/usr/local/openldap-2.4.26

Then run the command, make depend, make and sudo make install.

Thursday, 22 September 2011

jruby processor with activemq-5.5.0

Activemq is already in bundle with camel. The camel config file is in $ACTIVEMQ_HOME/conf/camel.xml.

But you need something more to use a jruby processor with activemq:
- add lang namespace to camel.xml;
- add a aopalliance.jar and jruby.jar to classpath (and more, if you need logback);
- write and register jruby bean.

Add namespace to camel.xml: just replace header with:
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="
                           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                           http://www.springframework.org/schema/lang
                           http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
                           http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

Add a aopalliance.jar to classpath: download springsource-2.5 with all dependencies. Unzip it and get aopalliance.jar from the lib/aopalliance directory.

Activemq $CLASSPATH is defined as $ACTIVEMQ_HOME/conf, so create a ruby folder in conf and add a jruby bean named ruby_processor.rb:
java_import "org.apache.camel.Exchange"
java_import "org.apache.camel.Processor"
java_import "org.slf4j.Logger"
java_import "org.slf4j.LoggerFactory"
java_import "ch.qos.logback.classic.LoggerContext"

java_package "com.test.camel"

class RubyProcessor
  include Processor

  def initialize
    @logger = LoggerFactory.getLogger("com.test.camel.#{File.basename(__FILE__, ".rb")}");
  end  

  java_signature "void process(Exchange exchange)"
  def process(exchange)
    test = exchange.in.headers['test']
    @logger.info("RubyProcessor: header test is: #{test}")
    exchange.in.set_header("Issuer", "rubyProcessor")
  end
end
Please note this bean does very few: just dump the value of a header to a log file, then sets a new header. It is just e proof-of-concept bean.

In camel.xml add a test route like:
<from uri="activemq:example.A"/>
     <bean ref="rubyProcessor" />
            <to uri="activemq:example.B" />

 <lang:jruby id="rubyProcessor"
              script-interfaces="org.apache.camel.Processor"
              script-source="classpath:ruby/ruby_processor.rb">
  </lang:jruby>

The ticky part.


To have logback work first you need to include in lib folder logback-classic and logback-core then I had to upgrade slf4j to 1.6.2 which means copying a couple of jars both in lib and in lib/optional.

The logback.xml can be created in conf, logfile from logback are written in $ACTIVEMQ_HOME.

Than I noticed the ruby scripting fails to work in the routes. I had to replace the <ruby> tags with <simple>.

Wednesday, 14 September 2011

Send a mail with ruby1.8, ruby1.9 and jruby

I lost the best part of this morning to send a mail with ruby with the constrain it should work with ruby1.8, ruby1.9 and jruby.

This is my best effort:
#!/usr/bin/env ruby
#ENCODING: UTF-8

require 'rubygems'
require 'net/smtp'
require 'mail'

TO = 'you@test.com'
FROM = 'me@test.com'

mail = Mail.new do
  from    FROM
  to      TO
  subject 'This is a test email'
  body    "Test\n\nNow is the time #{Time.now}\n"
end

Net::SMTP.start('localhost') do |smtp|
  smtp.send_message(mail.to_s, TO, FROM)
end

I hope it could save someone's time!