This post contains the steps that you need to follow to start Tomcat's service automatically when your Linux machine is turned on. This script have been tested on Ubuntu and CentOs
Paso #1: Ingresar al directorio /etc/int.d/ en este directorio se encuentra los scripts de arranque automáticos del sistema.
Step #1: Go to the /etc/int.d/ directory, here are the automatic startup scripts
Paso #2: Crear un fichero, que tendrá los comandos de arranque y detención del servicio de Tomcat
Step #2: Make a file where the start and stop Tomcat's service commands will be placed
Paso #3: Dentro del fichero "tomcat" copiar el script siguiente:
Step #3: Copy and paste the next script into the file "tomcat"
#!/bin/sh
#
# description: Demonio de arranque Tomcat
#
export TOMCAT_HOME=/root/apache/apache-tomcat-6.0.20
start(){
$TOMCAT_HOME/bin/startup.sh
}
stop(){
$TOMCAT_HOME/bin/shutdown.sh
}
case "$1" in
start)
echo "Iniciado / Starting tomcat ..."
start
;;
stop)
echo "Deteniendo / Stopping tomcat ..."
stop
;;
restart)
echo "Reiniciando / Restarting tomcat ..."
stop
start
;;
*)
echo $"Uso / Using : $0 {start|stop}"
exit 1
esac
* El contenido de la variable TOMCAT_HOME es la ruta donde se encuentran los archivos de tomcat tu equipo.
* The variable TOMCAT_HOME should contain the path where are the tomcat's file on your machine
Paso #4: Asignar permiso de ejecución (x) al archivo si es necesario:
Step #4: Add execute access to "tomcat" file whether necessary
Paso #5: Para arrancar/detener/reiniciar respectivamente el servicio manualmente se
utilizan los siguientes comandos:
Step #5: To start/stop/restart manually the service, use the following commands:
$ service tomcat stop
$ service tomcat restart
Paso #6: Agregar los enlaces de arranque y detención mediante el comando chkconfig --add <nombre archivo>
Step #6: Add the links start/stop/restart manually the service, use the following commands:
********
- Para eliminar los enlances se utiliza el comando chkconfig --del <nombre archivo>
- To remove the links, use the command chkconfig --del <filename>
$ sudo chkconfig --del tomcat
Paso #7: Activar el servicio en los distintos niveles de ejecución (runlevels) se utiliza el comando chkconfig <nombre archivo> on (esto activará por defecto los niveles 2345)
Step #7: To activate the service on the several run levels, use the command chkconfig <file name> on ( that will activate the leel 2345 by default) :
$ sudo chkconfig tomcat on
********
- Para desctivar el servicio en los distintos niveles de ejecución (runlevels) se utiliza el comando chkconfig <nombre archivo> off
$ sudo chkconfig tomcat off
- Tambien es posible activar/desactivar la ejecución del script en un nivel especifo con el comando chkconfig --level <numero del nivel> <nombre archivo> on
$ sudo chkconfig --level 23 tomcat on
- Se puede verificar el estado del script con el comando chkconfig --list <nombre archivo>
$ sudo chkconfig --list tomcat
Paso #8: Confirmar que el enlace fue agregado en los niveles especificados se revisa el contenido de archivo /etc/rcX.d/, donde X es el nivel que se quiere revisar.
$ ls -l /etc/rc2.d/
Paso #9: Reiniciar la máquina y comprobar que el servicio inicie por si solo.
$ sudo reboot
Fuente: http://www.youtube.com/watch?v=OdnELC0D5JE&feature=player_embedded#!