› Foros › PC › Software libre
su
cd /opt/
wget http://apache.rediris.es//tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz
tar -xzf apache-tomcat-6.0.29.tar.gz
mv apache-tomcat-6.0.29 tomcat6-a
chown -R webmaster:webmaster tomcat6-a (o el usuario que quieras)
#!/bin/bash
#################################################
##### Arranque Tomcat #####
##### Autor: rdcarrera #####
##### Adaptado y revisado por: #####
##### Ruben D. Carrera #####
#################################################
. /lib/lsb/init-functions
####/VARIABLES/OPEN/####
TOMCAT_USER=webmaster
TOMCAT_DIR=/opt/tomcat6-a
TOMCAT_BIN=$TOMCAT_DIR/bin
DESCRIPCION="Tomcat 6 a"
SUDO=/bin/su
####/VARIABLES/CLOSED/####
####/EXPORT/OPEN/####
export CATALINA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=128m -server"
export JAVA_HOME=/usr/lib/jvm/java-6-sun
####/EXPORT/CLOSED/####
####/FUNCTION/OPEN/####
function start() {
log_action_begin_msg "Iniciando $DESCRIPCION"
echo -e "\n"
$SUDO $TOMCAT_USER -c "$TOMCAT_BIN/startup.sh"
echo -e "\n"
echo -e [ '\E[32;40m'"\033[1m$DESCRIPCION Iniciado\033[0m" ]
log_action_end_msg $?
}
function stop() {
log_action_begin_msg "Deteniendo $DESCRIPCION"
echo -e "\n"
$SUDO $TOMCAT_USER -c "$TOMCAT_BIN/shutdown.sh"
echo -e [ '\E[31;40m'"\033[1m$DESCRIPCION Parando\033[0m" ]
echo -e "\n"
log_action_end_msg $?
}
function stop-force() {
log_action_begin_msg "Deteniendo $DESCRIPCION"
echo -e "\n"
for i in `ps aux | grep $TOMCAT_DIR | grep -v grep | awk '{ print $2 }'`; do
kill -9 $i;
done
echo -e [ '\E[31;40m'"\033[1m$DESCRIPCION Matando proceso\033[0m" ]
echo -e "\n"
log_action_end_msg $?
}
function status() {
log_action_begin_msg "Mostrando el status de $DESCRIPCION"
echo -e "\n"
ON=`ps aux | grep $TOMCAT_DIR | grep -v grep | awk '{ print $2 }'`
if [ $ON ]; then
ps aux | grep $TOMCAT_DIR | grep -v grep
echo -e [ '\E[32;40m'"\033[1m$DESCRIPCION Corriendo\033[0m" ]
else
echo -e [ '\E[31;40m'"\033[1m$DESCRIPCION No iniciado\033[0m" ]
fi
echo -e "\n"
log_action_end_msg $?
}
function question(){
CONTROL="yes"
sleep 2;
while [ $CONTROL = "yes" ]; do
clear
status
echo -e "¿Desea continuar? \n"
select DOCONTINUE in Arrancar Esperar Forzar Salir
do
if [ $DOCONTINUE ]; then
case "$DOCONTINUE" in
"Arrancar")
CONTROL="no";
break;
;;
"Esperar")
break;
;;
"Forzar")
stop-force;
break;
;;
"Salir")
exit 2;
;;
esac
else
echo "Opcion no valida"
fi
done
done
}
####/FUNCTION/CLOSED/####
####/MAIN/OPEN/####
case "$1" in
"status")
status;
;;
"start")
start;
;;
"stop")
stop;
;;
"stop-force")
stop-force;
;;
"restart"|"reload")
stop;
question;
start;
;;
"restart-force"|"reload-force")
stop-force;
sleep 5;
start;
;;
*)
echo -e "Error en la ejecución. Ejecución: \n\t$0 [ status | start | *(stop | restart | reload) *-force ]"
;;
esac
exit 0
####/MAIN/CLOSED/####
update-rc.d tomcat6-a defaults 99