Friday, June 14, 2013

Compiling Apache Commons Daemon for Linux and *BSD

I am manually installing the latest version of Tomcat on my Debian Linux server without using its package management system (dpkg). I downloaded Tomcat 7.0.41 from the Tomcat 7.0 download page. Then I unpacked the Tomcat tarball (apache-tomcat-7.0.41.tar.gz) into the /usr/local directory because it seems like a proper place for manually installed software.

/usr/local
tar xzf ~/apache-tomcat-7.0.41.tar.gz

Tomcat requires JDK or JRE to run, so make sure it is installed already. Since we need JDK to compile Apache Commons Daemon, we should install JDK. Later, we can remove JDK and install JRE. Tomcat will work fine with JRE, but some sophisticated Web applications, such as OpenCMS, requires JDK instead of JRE. On Debian, we can use apt-get to install JDK.

apt-get install openjdk-7-jdk

On OpenBSD, we can use pkg_add to install JDK.

pkg_add -i -v jdk

Once we have both Java and Tomcat installed on the system, we need to find a way to start Tomcat automatically on every boot. It is recommended to use Apache Commons Deamon for this purpose. Tomcat is distributed with the source code for the Daemon. In the bin directory of Tomcat, we find a tarball called commons-daemon-native.tar.gz. Let's compile Apache Commons Daemon. This will produce an executable file jsvc for Linux and *BSD which can be used to start any program or Java application in daemon mode. First, unpack the Commons Daemon tarball into your HOME or a temporary location.

tar xzf commons-daemon-native.tar.gz

Then, define an environment variable JAVA_HOME to point to the JDK directory. The configure script in the source uses this variable to find JDK.

export JAVA_HOME=/usr/local/jdk-1.6.0

I think libcap-dev should be installed along with gcc and make.

apt-get install gcc make libcap-dev

Go to the unix subfolder and run the configure script. This assumes that gcc and GNU make are already on your system.

cd commons-daemon-1.0.15-native-src/unix
./configure

Then, run make.

make

This will produce jsvc. Copy it to the bin directory of Tomcat.

cp jsvc /usr/local/apache-tomcat-7.0.41/bin

Starting Tomcat with jsvc needs a bit of tweaking. First, learn about its command parameters.

jsvc --help

Run jsvc to start Tomcat as daemon as shown below. Then, use lynx or Firefox to check Tomcat at http://127.0.0.1:8080/. If that works, we can turn it into a script. On Debian Linux and OpenBSD, I would put into /etc/rc.local something like this:

export JAVA_HOME=/usr/local/jdk-1.6.0
/usr/local/tomcat-7.0.41/bin/jsvc -classpath /usr/local/tomcat-7.0.41/bin/bootstrap.jar:/usr/local/tomcat-7.0.41/bin/tomcat-juli.jar -outfile /tmp/catalina.out -errfile /tmp/catalina.err -Dcatalina.home=/usr/local/tomcat-7.0.41 -Dcatalina.base=/home/tomcat7 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/home/tomcat7/conf/logging.properties -pidfile /tmp/tomcat7.pid -user tomcat7 org.apache.catalina.startup.Bootstrap

You may notice that my settings are peculiar in a way. Basically, I create a user "tomcat7" and use its HOME directory as CATALINA_BASE. The jsvc command is run with -user parameter so it will start Tomcat as the specified user (tomcat7). To stop Tomcat, run jsvc like this:

JAVA_HOME=/usr/local/jdk-1.6.0 /usr/local/tomcat-7.0.41/bin/jsvc -classpath /usr/local/tomcat-7.0.41/bin/bootstrap.jar:/usr/local/tomcat-7.0.41/bin/tomcat-juli.jar -stop -pidfile /tmp/tomcat7.pid org.apache.catalina.shutdown

Also Read

Tuesday, June 11, 2013

Getting Liferay Enterprise Portal to work on Linux and *BSD

Liferay is currently the top-ranking Java-based CMS (content management system). It is primarily geared toward business enterprises, and has many useful features for team collaboration. However, it can be used in many situations, including a media contents portal. Liferay community editions are packaged in many bundled forms, including a Tomcat bundle, a Geronimo bundle and such. Let's download a Tomcat bundle "liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip". We are going to take only the Liferay bits from the package and deploy Liferay onto our existing Tomcat installation.

  1. Install JRE and Tomcat if you haven't. On Debian, it is done as follows:

    apt-get install openjdk-7-jre tomcat7
  2. Set JAVA_OPTS variable in the setenv.sh script. This file is located in /usr/local/tomcat/bin directory in OpenBSD. If setenv.sh doesn't exist there, create it. However, JAVA_OPTS variable should be specified in /etc/default/tomcat7 in Debian. The following is the suggested value of JAVA_OPTS:

    JAVA_OPTS="-Dfile.encoding=UTF8 -Djava.awt.headless=true -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC"
  3. Copy every file from liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/lib/ext to the local Tomcat folder.

    cp liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/lib/ext/* /var/lib/tomcat7/lib
  4. Copy all the directories from liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps to the local Tomcat folder.

    mv liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/* /var/lib/tomcat7/webapps
  5. Create a text file webapps/ROOT/META-INF/context.xml and write the following in it.

    <Context crossContext="true">
    </Context>
  6. From liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/conf, copy these files to the local Tomcat folder.

    • catalina.policy
    • catalina.properties
  7. Find every line containing "<Connector" in server.xml and append URIEncoding="UTF-8".

  8. Unpack the Liferay package. Copy files from liferay-portal-6.1.1-ce-ga2/data/hsql to some directory.

    mkdir /var/lib/tomcat7/work/Liferay
    cp liferay-portal-6.1.1-ce-ga2/data/hsql/* /var/lib/tomcat7/work/Liferay
  9. Restart Tomcat.

Wednesday, June 5, 2013

Set up Yanel on Debian Linux Tomcat

After building Yanel from source, follow the steps below to deploy and configure Yanel for Tomcat on Debian Linux.

  1. Adjust the value of JAVA_OPTS= environment variable in /etc/default/tomcat7 to ensure smooth operation of Yanel.

    JAVA_OPTS="-Djava.awt.headless=true -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Xms128m -Xmx256m -XX:MaxPermSize=128m -XX:+UseConcMarkSweepGC"
  2. Copy or move the directory build/webapps/yanel to /var/lib/tomcat7/webapps directory. If you want to make it the default application, rename it to ROOT.

    mv /usr/src/wyona-yanel-1.0.0-src/build/webapps/yanel /var/lib/tomcat7/webapps/ROOT
  3. Copy or move the directory src/realms to /var/lib/tomcat7 directory. You can put it anywhere you like. Just remember to edit realms.xml accordingly.

  4. Enter Tomcat webapps directory. Then, go to Yanel WEB-INF/classes directory and edit some files to configure Yanel. Some of the files that you may edit include:

    • log4j.properties
    • realms.xml
  5. Restart Tomcat.

    /etc/init.d/tomcat7 restart

Set up Lenya on Debian Linux

Apache Lenya is an open-source content management system based on Java and XML technology. I compiled Lenya following this post. It was tricky to take only the Web application part out of the source tree after compilation. In the end, I figured it out after going through the source directories.

Simply copy or move the directory apache-lenya-2.0.4-src/build/lenya to Tomcat's webapps directory. You can rename it to ROOT if you want to make it the default Web application. Remember to stop Tomcat first.

/etc/init.d/tomcat7 stop
rm -rf /var/lib/tomcat7/webapps/ROOT
mv apache-lenya-2.0.4-src/build/lenya /var/lib/tomcat7/webapps/ROOT

There are some more things that need to be done. First, adjust the value of JAVA_OPTS in /etc/default/tomcat7. I got the -Dorg.xml.sax.parser= part from the lenya.sh script in Lenya source.

JAVA_OPTS="-Djava.awt.headless=true -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Xms32m -Xmx256m -XX:MaxPermSize=128m -XX:+UseConcMarkSweepGC"

Then, copy files from webapps/ROOT/WEB-INF/lib/endorsed to /var/lib/tomcat7/lib.

cp /var/lib/tomcat7/webapps/ROOT/WEB-INF/lib/endorsed/* /var/lib/tomcat7/lib

Restart Tomcat.

/etc/init.d/tomcat7 restart

Use Lenya at http://127.0.0.1:8080.

Tuesday, June 4, 2013

Compile Tomcat Native Library on Debian Linux

To compile Tomcat native library, I installed some additional packages.

apt-get install gcc libapr1-dev libssl-dev make openjdk-7-jdk

I set JAVA_HOME environment variable.

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386

I downloaded the tarball from apache.cs.utah.edu. It was located in /apache.org/tomcat/tomcat-connectors/native/ directory. I unpacked the tarball and compiled it as follows.

cd /usr/src
tar xzvf tomcat-native-1.1.27-src.tar.gz
cd tomcat-native-1.1.27-src/jni/native
./configure --with-apr=/usr/bin/apr-1-config
make
make install

Then, I copied the library like this.

cd .libs
mv libtcnative-1.so* /usr/lib

Then, I ran ldconfig.

ldconfig

I uncommented the following line in /etc/tomcat7/server.xml.

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

I restarted Tomcat.

/etc/init.d/tomcat7 restart

I hope Tomcat native library will boost Tomcat performance.

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews