RSS

Start Binary Tomcat6 On Ubuntu / Centos System Start Up

05 Jul

Give the command in terminal prompt:

Step 1: Command to go into init.d folder

cd /etc/init.d

step 2: Create file tomcat6 and edit using below command

root@mycomputer:/etc/init.d# vi tomcat6
(or)  
root@mycomputer:/etc/init.d# gedit tomcat6

Step 3: Paste the below script and give correct JAVA_HOME and CATALINA_HOME and tomcat bin location

#!/bin/sh
###BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
# Tomcat 6 init-script
CATALINA_HOME=/home/ideas2it24/apache-tomcat-6.0.32
export CATALINA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
case $1 in
 start)
 sh /home/ideas2it24/apache-tomcat-6.0.32/bin/startup.sh
 echo "tomcat6 started successfully"
 ;;
 stop)
 sh /home/ideas2it24/apache-tomcat-6.0.32/bin/shutdown.sh
 echo "tomcat6 stoped successfully"
 ;;
 restart)
 sh /home/ideas2it24/apache-tomcat-6.0.32/bin/shutdown.sh
 sh /home/ideas2it24/apache-tomcat-6.0.32/bin/startup.sh
 echo "tomcat6 restarted successfully"
 ;;
 *)
 sh /home/ideas2it24/apache-tomcat-6.0.32/bin/startup.sh
 echo "tomcat6 started successfully"
 ;;
 esac
exit 0

Step 4: Permission to the script, Give the following command

For Ubuntu:
 root@mycomputer:/etc/init.d# chmod 751 tomcat6
For centOs:
 chmod +x tomcat

Step 5:Now make the script executable Give following command

For Ubuntu:
 root@mycomputer:/etc/init.d# update-rc.d tomcat6 defaults
For CentOs:
 chkconfig --add tomcat

Step6: To Start / Stop / Restarting tomcat6

to start /etc/init.d/tomcat6 start
to stop /etc/init.d/tomcat6 stop
to restart /etc/init.d/tomcat6 restart

Another Script:

Instead of Step3  script we can use below script

# vi /etc/init.d/tomcat6
#!/bin/sh
# Tomcat 6 init-script
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.13
export CATALINA_HOME=/usr/local/apache-tomcat-6.0.20
export PATH=$JAVA_HOME/bin:$PATH
start_tomcat6=/home/ideas2it24/apache-tomcat-6.0.32/bin/startup.sh
stop_tomcat6=/home/ideas2it24/apache-tomcat-6.0.32/bin/shutdown.sh
start() {
 echo "Starting tomcat: "
 su -c ${start_tomcat6} tomcat
 echo "done."
}
stop() {
 echo "Shutting down tomcat: "
 ${stop_tomcat6} tomcat
 echo "done."
}
# See how we were called
case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 restart)
 stop
 sleep 2
 start
 ;;
 *)
 echo "Usage: $0 {start|stop|restart}"
esac
exit 0
 
4 Comments

Posted by on July 5, 2012 in CentOS, General, Tomcat, Ubuntu

 

Tags: , ,

4 responses to “Start Binary Tomcat6 On Ubuntu / Centos System Start Up

  1. Allen

    September 17, 2012 at 1:15 am

    When someone writes an post he/she keeps the plan of a
    user in his/her brain that how a user can be aware of it. So that’s why this piece of writing is great. Thanks!

     
    • Creators

      September 18, 2012 at 10:14 am

      Thanks Allen, do post your valuable suggestions in future

       
  2. Accelerate by Eben Pagan

    May 19, 2013 at 5:25 pm

    I’m really impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you modify it yourself? Anyway keep up the nice quality writing, it’s rare to see a great blog like this one nowadays.

     
  3. James

    November 27, 2015 at 6:05 am

    Dear sir

    I want to schedule auto service restart for the tomcat6 in Ubuntu 14.05 server ,can you help me .

    Thank you

     

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

 
%d bloggers like this: