Wednesday, November 24, 2010

Install Apache Geronimo (as service) on Ubuntu Linux

Apache Geronimo is an Open Source J2EE server. And it can be installed rather easily on Ubuntu Linux (10.04).

- First step is to install sun java.
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk


- Second step is to download and extract (install) Geronimo:
Download from :
http://geronimo.apache.org/apache-geronimo-v22-release.html
I downloaded the latest stable release with tomcat:
geronimo-tomcat6-javaee5-2.2-bin.tar.gz

Then md5sum it (to gain problem-solving time):
md5sum geronimo-tomcat6-javaee5-2.2-bin.tar.gz
and crosscheck it with the md5 sum on the site.

Extract the archive:
tar -xvzf geronimo-tomcat6-javaee5-2.2-bin.tar.gz

Rename the extracted directory to something smaller:
mv geronimo-tomcat6-javaee5-2.2 geronimo.2.2
From now on when we will refer to the full path of the geronimo.2.2 directory as ${GERONIMO_HOME}.

Open .bashrc file:
gedit /home/${user}/.bashrc

Add JAVA_HOME, JRE_HOME and JAVA_OPTS at the end of .bashrc:
export JAVA_HOME=/usr/lib/jvm/java-6-sun   
export JRE_HOME=/usr/lib/jvm/java-6-sun/jre
export JAVA_OPTS="-Xmx256m -XX:MaxPermSize=128m"
Run .bashrc (just this once):
. .bashrc
Or close the terminal and open a new one.

- Last step is to start the server:
cd ${GERONIMO_HOME}/bin
./geronimo start

And the server is up and running!
You can browse the Administration console at
http://localhost:8080/
Click the link "Administration -> console" on the left.
Provide the default credentials :
system/manager
And geronimo is at your disposal!

To maximize security, it is time to change the default admin username and password. You need to stop geronimo:
cd ${GERONIMO_HOME}/bin
./geronimo.sh stop --user system --password manager
Open user/passwords file
gedit ${GERONIMO_HOME}/var/security/users.properties
and add a new line with the new administrator user and his password like this:
g_admin=g_admin_pass
Next time you start the server the password will be automatically encrypted.
Open permission/groups file:
gedit ${GERONIMO_HOME}/var/security/groups.properties
Assign administration and monitoring privileges only to the new user. Change the two uncommented lines like this:
admin=g_admin
monitor=g_adminLastly you should change the file permissions on these files:
chmod -R 600 ${GERONIMO_HOME}/var/security

To create a service in order to automate startup open/create the following file:
sudo gedit /etc/init.d/geronimo2
Add the following code. You only need to set correctly for your system the variables GERONIMO_HOME, GERONIMO_OWNER, GERONIMO_ADMIN and GERONIMO_PASS inside the script.

#!/bin/bash
# chkconfig: 234 20 80
# description: Geronimo Server start/stop script
# processname: geronimo2

JAVA_HOME=/usr/lib/jvm/java-6-sun
JRE_HOME=/usr/lib/jvm/java-6-sun/jre
JAVA_OPTS="-Xmx256m -XX:MaxPermSize=128m"

GERONIMO_HOME=/home/gfuser/geronimo.2.2
GERONIMO_OWNER=gfuser
GERONIMO_ADMIN=g_admin
GERONIMO_PASS=g_asmin_pass

export JAVA_HOME JRE_HOME JAVA_OPTS GERONIMO_HOME GERONIMO_OWNER GERONIMO_ADMIN GERONIMO_PASS

start() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo "Geronimo is already UP!"
  else 
    echo -n "Starting geronimo: "
    cd $GERONIMO_HOME/bin
    su $GERONIMO_OWNER -c "$GERONIMO_HOME/bin/geronimo.sh start"
    sleep 20
    echo "done."
  fi
}

stop() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo -n "Gracefully stoping geronimo: "
    su $GERONIMO_OWNER -c "$GERONIMO_HOME/bin/geronimo.sh stop --user $GERONIMO_ADMIN --password $GERONIMO_PASS"
    sleep 10
    echo "done."
  else
    echo "Geronimo is already DOWN!"
  fi
}

force_stop() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo -n "Forcefully stoping geronimo: "
    su $GERONIMO_OWNER -c "$GERONIMO_HOME/bin/geronimo.sh stop --force --user $GERONIMO_ADMIN --password $GERONIMO_PASS"
    echo "done."
  else
    echo "Geronimo is already DOWN!"
  fi
}

status() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo "Geronimo is UP!"
  else
    echo "Geronimo is DOWN!"
  fi
}

case "$1" in
  start)
    start
;;
  stop)
    stop
;;
  status)
    status
;;
  force_stop)
    force_stop
;;
  restart)
    stop
    sleep 2
    start
;;
  *)
  echo "Usage: $0 {start|stop|force_stop|restart|status}"
esac

exit 0

Now you need to change the file permissions:
sudo chmod 755 /etc/init.d/geronimo2

Next create the upstart conf file:
sudo gedit /etc/init/geronimo2.conf
and add the following code

# geronimo2

start on runlevel [2345]
stop on runlevel [16]

respawn

pre-start exec /etc/init.d/geronimo2 start
post-stop exec /etc/init.d/geronimo2 stop


Reload upstart configuration:
sudo initctl reload-configuration
Start geronimo service :
sudo initctl start geronimo2

And the geronimo service is securely installed and will be started on every boot.

0 σχόλια:

Post a Comment