Setup Tomcat as Startup Service On REDHAT

SETUP TOMCAT AS SERVICE ON REDHAT

Supaya APACHE Tomcat bisa di jalankan sebagai service diperlukan user tomcat, untuk membuat user login sebagai root di Konlsole terminal:

$ su -
$ adduser -s /sbin/nologin tomcat
$ passwd tomcat

kemudian download Tomcat dari http://tomcat.apache.org/
dan Download Java Jdk di http://java.sun.com

Ekstrak file tomcat ke folder /opt dengan nama tomcat, dan ekstrak file JDK ke folder /opt dengan nama java, dari list folder /opt hasilnya sebagai berikut :

$ ls -la /opt

drwxr-xr-x 9 tomcat root 4096 2007-12-19 12:50 java
drwxr-xr-x 11 tomcat root 4096 2008-01-07 13:21 tomcat

Kemudian ubah kepemilikan folder tomcat dan java di dalam folder opt mejadi milik tomcat user

$ chown -R tomcat /opt/tomcat
$ chown -R tomcat /opt/java

kemudian tambahkan script berikut ke folder /etc/init.d/

$ vi /etc/init.d/tomcat

++++++++++++++++++++++++++++++++++++++++++

#!/bin/sh
# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ “${NETWORKING}” = “no” ] && exit 0

tomcat=/opt/tomcat
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/opt/java

start(){
echo -n $”Starting Tomcat service: “
#daemon -c
$startup
RETVAL=$?
echo
}

stop(){
action $”Stopping Tomcat service: ” $shutdown
RETVAL=$?
echo
}

restart(){
stop
start
}

status(){
numproc=`ps -ef | grep catalina | grep -v “grep catalina” | wc -l`
if [ $numproc -gt 0 ]; then
echo “Tomcat is running…”
else
echo “Tomcat is stopped…”
fi
}

# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
status)
status tomcat
;;
restart)
restart
;;
*)
echo $”Usage: $0 {start|stop|status|restart}”
exit 1
esac

exit 0
+++++++++++++++++++++++++++++++++

kemudaian tambahkan tomcat kedalam service

$ chkconfig –add tomcat
$ chkconfig tomcat on

untuk tes ketikan :

$ /et/init.d/tomcat start

kemudian cobalah test apache tomcatnya dengan mencek di browser anda dengan alamat :

http://localhost:8080

About these ads

One thought on “Setup Tomcat as Startup Service On REDHAT

  1. Thank you Valimot for your blog post. It was very usefull for me, clear for understanding and ease for implementation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s