Vamos a crear un script completo que permite subir, bajar y reiniciar un JBoss sobre Kubuntu 10.10.
Las opciones de branches, trunk es para subir (si esta arriba lo baja y publica un aplicativo) desde la copia de trabajo del subversion.
Creamos el archivo que contendrá el script: sudo vi /etc/init.d/jboss
Copia este contenido:
#! /bin/sh
#
# $Id: jboss_init_redhat.sh 71252 2008-03-25 17:52:00Z dbhole $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
# Init script modified for Ubuntu Server 8.04 by
# Chiral Software, Inc.
#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/RUTA/JBOSS/jboss-5.1.0.GA"}
#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
#JBOSS_USER=${JBOSS_USER:-"jboss"}
JBOSS_USER=${JBOSS_USER:-"RUNASIS"}
#make sure java is in your path
#this must be set even if java is in a well-known place like /usr/bin
#JAVAPTH=${JAVAPTH:-"/RUTA/java/jdk1.6.0_22"}
#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"default"}
#if JBOSS_HOST specified, use -b to bind jboss services to that address
# JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
#JBOSS_BIND_ADDR=${JBOSS_HOST:-"-b IP_DEL_EQUIPO"}
#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
#define la ruta de la ubicación del branches donde esta el codigo fuente
BRANCHES=${BRANCHES:-"/RUTA/2_Fuentes/branches/VERSION"}
#define la ruta de la ubicación del trunk donde esta el codigo fuente
TRUNK=${TRUNK:-"/RUTA/2_Fuentes/trunk"}
if [ "$JBOSS_USER" = "RUNASIS" ]; then
SUBIT=""
else
SUBIT="su - $JBOSS_USER -c "
fi
if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
# ensure the file exists
touch $JBOSS_CONSOLE
if [ ! -z "$SUBIT" ]; then
chown $JBOSS_USER $JBOSS_CONSOLE
fi
fi
if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
echo "WARNING: ignoring it and using /dev/null"
JBOSS_CONSOLE="/dev/null"
fi
#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"$JBOSS_HOME/server/$JBOSS_CONF/log/console.log"}
JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
#if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
# export PATH=$PATH:$JAVAPTH
#fi
if [ ! -d "$JBOSS_HOME" ]; then
echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
exit 1
fi
procrunning () {
procid=0
for procid in `pidof -x $JBOSS_HOME/bin/run.sh`; do
ps -fp $procid | grep "${JBOSSSH% *}" > /dev/null && pid=$procid
done
}
stop () {
pid=0
procrunning
if [ $pid = '0' ]; then
/bin/echo -n -e "\nNo JBossas is currently running\n"
exit 1
fi
RETVAL=1
# If process is still running
# First, try to kill it nicely
for id in `ps --ppid $pid | awk '{print $1}' | grep -v "^PID$"`; do
if [ -z "$SUBIT" ]; then
kill -15 $id
else
$SUBIT "kill -15 $id"
fi
done
sleep=0
while [ $sleep -lt 120 -a $RETVAL -eq 1 ]; do
/bin/echo -n -e "\nwaiting for JBoss processes to stop\n";
sleep 10
sleep=`expr $sleep + 10`
pid=0
procrunning
if [ $pid = '0' ]; then
RETVAL=0
fi
done
count=0
pid=0
procrunning
if [ $RETVAL != 0 ] ; then
/bin/echo -e "\nTimeout: Shutdown command was sent, but process is still running with PID $pid\n"
exit 1
fi
echo
exit 0
}
case "$1" in
start)
echo "Iniciando el JBoss"
eval touch $JBOSS_HOME/server/$JBOSS_CONF/log/server.log
cd $JBOSS_HOME/bin
if [ -z "$SUBIT" ]; then
# eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
eval $JBOSS_CMD_START 2>&1 &
else
# $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
$SUBIT "$JBOSS_CMD_START 2>&1 &"
fi
eval tail -f $JBOSS_HOME/server/$JBOSS_CONF/log/server.log
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
trunk)
$0 stop
echo "Eliminando archivos existentes"
rm $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.jar
rm $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.war
rm $JBOSS_HOME/server/$JBOSS_CONF/lib/librerias_propias*.jar
echo "Publicando nuevos archivos"
cp $TRUNK/RUTA/target/empaquetado.jar $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.jar
cp $TRUNK/RUTA/target/empaquetado.war $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.war
$0 start
;;
branches)
$0 stop
echo "Eliminando archivos existentes"
echo "Publicando nuevos archivos"
$0 start
;;
*)
echo "usage: $0 (start|stop|restart|branches|trunk|help)"
esac
Terminando de pegar el contenido del script, lo guarda dando ESC :wq
Ya tenemos el script, ahora es solo darle permisos de ejecución: sudo chmod 755 jboss
Y listo, ya lo podemos ejecutar: service jboss trunk
Con esto debería subir el JBoss realizando la publicación de nuestro aplicativo que esta en el trunk del repositorio.
Sus opiniones las pueden dejar en los comentarios
Las opciones de branches, trunk es para subir (si esta arriba lo baja y publica un aplicativo) desde la copia de trabajo del subversion.
Creamos el archivo que contendrá el script: sudo vi /etc/init.d/jboss
Copia este contenido:
#! /bin/sh
#
# $Id: jboss_init_redhat.sh 71252 2008-03-25 17:52:00Z dbhole $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
# Init script modified for Ubuntu Server 8.04 by
# Chiral Software, Inc.
#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/RUTA/JBOSS/jboss-5.1.0.GA"}
#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
#JBOSS_USER=${JBOSS_USER:-"jboss"}
JBOSS_USER=${JBOSS_USER:-"RUNASIS"}
#make sure java is in your path
#this must be set even if java is in a well-known place like /usr/bin
#JAVAPTH=${JAVAPTH:-"/RUTA/java/jdk1.6.0_22"}
#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"default"}
#if JBOSS_HOST specified, use -b to bind jboss services to that address
# JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
#JBOSS_BIND_ADDR=${JBOSS_HOST:-"-b IP_DEL_EQUIPO"}
#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
#define la ruta de la ubicación del branches donde esta el codigo fuente
BRANCHES=${BRANCHES:-"/RUTA/2_Fuentes/branches/VERSION"}
#define la ruta de la ubicación del trunk donde esta el codigo fuente
TRUNK=${TRUNK:-"/RUTA/2_Fuentes/trunk"}
if [ "$JBOSS_USER" = "RUNASIS" ]; then
SUBIT=""
else
SUBIT="su - $JBOSS_USER -c "
fi
if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
# ensure the file exists
touch $JBOSS_CONSOLE
if [ ! -z "$SUBIT" ]; then
chown $JBOSS_USER $JBOSS_CONSOLE
fi
fi
if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
echo "WARNING: ignoring it and using /dev/null"
JBOSS_CONSOLE="/dev/null"
fi
#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"$JBOSS_HOME/server/$JBOSS_CONF/log/console.log"}
JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
#if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
# export PATH=$PATH:$JAVAPTH
#fi
if [ ! -d "$JBOSS_HOME" ]; then
echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
exit 1
fi
procrunning () {
procid=0
for procid in `pidof -x $JBOSS_HOME/bin/run.sh`; do
ps -fp $procid | grep "${JBOSSSH% *}" > /dev/null && pid=$procid
done
}
stop () {
pid=0
procrunning
if [ $pid = '0' ]; then
/bin/echo -n -e "\nNo JBossas is currently running\n"
exit 1
fi
RETVAL=1
# If process is still running
# First, try to kill it nicely
for id in `ps --ppid $pid | awk '{print $1}' | grep -v "^PID$"`; do
if [ -z "$SUBIT" ]; then
kill -15 $id
else
$SUBIT "kill -15 $id"
fi
done
sleep=0
while [ $sleep -lt 120 -a $RETVAL -eq 1 ]; do
/bin/echo -n -e "\nwaiting for JBoss processes to stop\n";
sleep 10
sleep=`expr $sleep + 10`
pid=0
procrunning
if [ $pid = '0' ]; then
RETVAL=0
fi
done
count=0
pid=0
procrunning
if [ $RETVAL != 0 ] ; then
/bin/echo -e "\nTimeout: Shutdown command was sent, but process is still running with PID $pid\n"
exit 1
fi
echo
exit 0
}
case "$1" in
start)
echo "Iniciando el JBoss"
eval touch $JBOSS_HOME/server/$JBOSS_CONF/log/server.log
cd $JBOSS_HOME/bin
if [ -z "$SUBIT" ]; then
# eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
eval $JBOSS_CMD_START 2>&1 &
else
# $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
$SUBIT "$JBOSS_CMD_START 2>&1 &"
fi
eval tail -f $JBOSS_HOME/server/$JBOSS_CONF/log/server.log
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
trunk)
$0 stop
echo "Eliminando archivos existentes"
rm $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.jar
rm $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.war
rm $JBOSS_HOME/server/$JBOSS_CONF/lib/librerias_propias*.jar
echo "Publicando nuevos archivos"
cp $TRUNK/RUTA/target/empaquetado.jar $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.jar
cp $TRUNK/RUTA/target/empaquetado.war $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.war
$0 start
;;
branches)
$0 stop
echo "Eliminando archivos existentes"
rm $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.jar
rm $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.war
rm $JBOSS_HOME/server/$JBOSS_CONF/lib/librerias_propias*.jar
echo "Publicando nuevos archivos"
cp $BRANCHES/RUTA/target/empaquetado.jar $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.jar
cp $BRANCHES/RUTA/target/empaquetado.war $JBOSS_HOME/server/$JBOSS_CONF/deploy/empaquetado.war
;;
*)
echo "usage: $0 (start|stop|restart|branches|trunk|help)"
esac
Terminando de pegar el contenido del script, lo guarda dando ESC :wq
Ya tenemos el script, ahora es solo darle permisos de ejecución: sudo chmod 755 jboss
Y listo, ya lo podemos ejecutar: service jboss trunk
Con esto debería subir el JBoss realizando la publicación de nuestro aplicativo que esta en el trunk del repositorio.
Sus opiniones las pueden dejar en los comentarios
Comentarios
Publicar un comentario