Páginas

segunda-feira, 3 de junho de 2013

Instalando Liferay CE 6.1 no Debian Squeeze

Nesta postagem vamos ver como instalar o Liferay CE 6.1.1 (pacote com Tomcat 7) no Debian Squeeze, com criação de usuário específico e configuração de daemon através de script init.d.

Requisitos

O Liferay é um aplicativo baseado em Java, então, precisamos ter instalado um JDK, eu recomendo o pacote sun-java6-jdk da distribuição non-free do Squeeze, mas se preferir outro fique à vontade.
Precisamos de um descompactador zip, recomendo o unzip disponível na distribuição main do Squeeze.
Todos os comandos abaixo serão executados em modo super usuário, então, caso não tenha realizado login como root, realize a autorização com o comando su

Criando usuário e grupo

Vamos criar usuário e grupo de sistema.
# addgroup --system liferay
# adduser --system --home /usr/share/liferay --no-create-home --ingroup liferay --disabled-password --shell /bin/false liferay

Instalando

Baixando o pacote

# cd ~
# wget http://ufpr.dl.sourceforge.net/project/lportal/Liferay%20Portal/6.1.1%20GA2/liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip

Criando estrutura de pastas e descompactando

# mkdir /usr/share/liferay
# cd /usr/share/liferay/
# unzip /root/liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip

Criando links simbólicos úteis

# ln -s liferay-portal-6.1.1-ce-ga2/ liferay-portal
# cd liferay-portal
# ln -s tomcat-7.0.27/ tomcat

Definindo permissões de pastas

# chown -R liferay:liferay /usr/share/liferay/*
# chmod -R ug=rwx /usr/share/liferay/*

Preparando script daemon

# nano /etc/init.d/liferay
O script abaixo que forneço como exemplo é uma modificação do script para o Tomcat 6 do próprio Debian Squeeze. Existem outras opções disponíveis na internet, se preferir pode utilizar alguma outra mas talvez tenha de mudar um pouco as configurações do usuário criado.
#!/bin/sh
#
# /etc/init.d/liferay -- startup script for the Liferay CE
#
# Written by Miquel van Smoorenburg .
# Modified for Debian GNU/Linux by Ian Murdock .
# Modified for Tomcat by Stefan Gybas .
# Modified for Tomcat6 by Thierry Carrez .
# Additional improvements by Jason Brittain .
# Modified for Liferay by cweiler
#
### BEGIN INIT INFO
# Provides:          liferay
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named cntlm apache2 mysql
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Liferay.
# Description:       Start the Liferay CE.
### END INIT INFO

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=liferay
DESC="Liferay CE"
JVM_TMP=/tmp/liferay-$NAME-tmp

if [ `id -u` -ne 0 ]; then
 echo "You need root privileges to run this script"
 exit 1
fi

# Make sure liferay is started with system locale
if [ -r /etc/default/locale ]; then
 . /etc/default/locale
 export LANG
fi

. /lib/lsb/init-functions

if [ -r /etc/default/rcS ]; then
 . /etc/default/rcS
fi

# Run Liferay as this user ID and group ID
LIFERAY_USER=liferay
LIFERAY_GROUP=liferay

# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"

# Look for the right JVM to use
for jdir in $JDK_DIRS; do
    if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
 JAVA_HOME="$jdir"
    fi
done
export JAVA_HOME

# Directory where the Tomcat 6 binary distribution resides
CATALINA_HOME=/usr/share/liferay/liferay-portal/tomcat

# Directory for per-instance configuration files and webapps
CATALINA_BASE=$CATALINA_HOME

# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
 JAVA_OPTS="-Djava.awt.headless=true -Xmx128M"
fi

# End of variables that can be overwritten in $DEFAULT

if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
 log_failure_msg "$NAME is not installed"
 exit 1
fi

if [ -z "$CATALINA_TMPDIR" ]; then
 CATALINA_TMPDIR="$JVM_TMP"
fi

# Set the JSP compiler if set in the tomcat6.default file
if [ -n "$JSP_COMPILER" ]; then
 JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi

# Define other required variables
LIFERAY_PID="/var/run/$NAME.pid"
LIFERAY_SH="$CATALINA_HOME/bin/catalina.sh"

# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
    JSSE_HOME="${JAVA_HOME}/jre/"
fi

catalina_sh() {
 # Escape any double quotes in the value of JAVA_OPTS
 JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"

 # Define the command to run Tomcat's catalina.sh as a daemon
 # set -a tells sh to export assigned variables to spawned shells.
 TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; \
  CATALINA_HOME=\"$CATALINA_HOME\"; \
  CATALINA_BASE=\"$CATALINA_BASE\"; \
  JAVA_OPTS=\"$JAVA_OPTS\"; \
  CATALINA_PID=\"$LIFERAY_PID\"; \
  CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
  LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
  cd \"$CATALINA_BASE\"; \
  \"$LIFERAY_SH\" $@"

 # Run the catalina.sh script as a daemon
 set +e
 touch "$LIFERAY_PID" "$CATALINA_BASE"/logs/catalina.out
 chown $LIFERAY_USER "$LIFERAY_PID" "$CATALINA_BASE"/logs/catalina.out

 start-stop-daemon --start -b -u "$LIFERAY_USER" -g "$LIFERAY_GROUP" \
  -c "$LIFERAY_USER" -d "$CATALINA_TMPDIR" -p "$LIFERAY_PID" \
  -x /bin/bash -- -c "$TOMCAT_SH"
 status="$?"
 set +a -e
 return $status
}

case "$1" in
  start)
 if [ -z "$JAVA_HOME" ]; then
  log_failure_msg "no JDK found - please set JAVA_HOME"
  exit 1
 fi

 if [ ! -d "$CATALINA_BASE/conf" ]; then
  log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
  exit 1
 fi

 log_daemon_msg "Starting $DESC" "$NAME"
 if start-stop-daemon --test --start --pidfile "$LIFERAY_PID" \
  --user $LIFERAY_USER --exec "$JAVA_HOME/bin/java" \
  >/dev/null; then

  # Remove / recreate JVM_TMP directory
  rm -rf "$JVM_TMP"
  mkdir -p "$JVM_TMP" || {
   log_failure_msg "could not create JVM temporary directory"
   exit 1
  }
  chown $LIFERAY_USER "$JVM_TMP"

  catalina_sh start
  sleep 5
         if start-stop-daemon --test --start --pidfile "$LIFERAY_PID" \
   --user $LIFERAY_USER --exec "$JAVA_HOME/bin/java" \
   >/dev/null; then
   if [ -f "$LIFERAY_PID" ]; then
    rm -f "$LIFERAY_PID"
   fi
   log_end_msg 1
  else
   log_end_msg 0
  fi
 else
         log_progress_msg "(already running)"
  log_end_msg 0
 fi
 ;;
  stop)
 log_daemon_msg "Stopping $DESC" "$NAME"

 set +e
 if [ -f "$LIFERAY_PID" ]; then
  start-stop-daemon --stop --pidfile "$LIFERAY_PID" \
   --user "$LIFERAY_USER" \
   --retry=TERM/20/KILL/5 >/dev/null
  if [ $? -eq 1 ]; then
   log_progress_msg "$DESC is not running but pid file exists, cleaning up"
  elif [ $? -eq 3 ]; then
   PID="`cat $LIFERAY_PID`"
   log_failure_msg "Failed to stop $NAME (pid $PID)"
   exit 1
  fi
  rm -f "$LIFERAY_PID"
  rm -rf "$JVM_TMP"
 else
  log_progress_msg "(not running)"
 fi
 log_end_msg 0
 set -e
 ;;
   status)
 set +e
 start-stop-daemon --test --start --pidfile "$LIFERAY_PID" \
  --user $LIFERAY_USER --exec "$JAVA_HOME/bin/java" \
  >/dev/null 2>&1
 if [ "$?" = "0" ]; then

  if [ -f "$LIFERAY_PID" ]; then
      log_success_msg "$DESC is not running, but pid file exists."
   exit 1
  else
      log_success_msg "$DESC is not running."
   exit 3
  fi
 else
  log_success_msg "$DESC is running with pid `cat $LIFERAY_PID`"
 fi
 set -e
        ;;
  restart|force-reload)
 if [ -f "$LIFERAY_PID" ]; then
  $0 stop
  sleep 1
 fi
 $0 start
 ;;
  try-restart)
        if start-stop-daemon --test --start --pidfile "$LIFERAY_PID" \
  --user $LIFERAY_USER --exec "$JAVA_HOME/bin/java" \
  >/dev/null; then
  $0 start
 fi
        ;;
  *)
 log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
 exit 1
 ;;
esac

exit 0

Ajustes finais

Como estamos no Brasil, vamos configurar corretamente o Liferay CE.
# nano /usr/share/liferay/liferay-portal/tomcat-7.0.27/bin/setenv.sh
Remova a definição de user.timezone do arquivo aberto no comando acima.
# nano /usr/share/liferay/liferay-portal/tomcat/webapps/ROOT/WEB-INF/classes/system-ext.properties
Adicione as seguintes linhas no arquivo aberto pelo último comando
user.country=BR
user.language=pt
user.timezone=America/Sao_Paulo
# Caso utilize proxy, descomente e configure as linhas abaixo
#http.proxyHost=127.0.0.1
#http.proxyPort=3128

Concluindo

Configure o script na inicialização do sistema.
# chmod +x /etc/init.d/liferay
# update-rc.d liferay defaults
# tail -f /usr/share/liferay/liferay-portal/tomcat/log/catalina.out
O Liferay deve iniciar automaticamente, mas, às vezes, pode demorar um pouco.

Considerações

Esta postagem tem como objetivo apenas abordar a instalação do Liferay CE no Debian, sem entrar nas configurações do Liferay em si. Lembre que para um ambiente de produção é necessário remover a aplicação de exemplo que vem junto com o pacote e configurar um banco de dados adequado.

Nenhum comentário:

Postar um comentário

Olá! Antes de postar seu comentário, por favor, observe que comentários técnicos, elogios e sugestões são antecipadamente agradecidos, esclarecimentos sobre os conceitos envolvidos na postagem serão respondidos da melhor forma possível, mas pedidos de ajuda técnica ou suporte individual deverão ser feitos através do formulário de contato. Grato!