Automatic Starting Tomcat on ubuntu

07 Oct

Tomcat requires JAVA_HOME variable.  The best way to do this is to set it in your .bashrc file.

The better method is editing your .bashrc file and adding the following line there,  You will have to logout of the shell for the change to take effect.

vi ~/.bashrc

Add the following line:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

At this point you can start tomcat by just executing the script in the tomcat/bin folder.

Automatic Starting

To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.

sudo vi /etc/init.d/tomcat

Now paste the following content:

    # Tomcat auto-start
    # description: Auto-starts tomcat
    # processname: tomcat
    # pidfile: /var/run/

    export JAVA_HOME=/usr/lib/jvm/java-6-sun

    case $1 in
            sh /usr/local/tomcat/bin/
            sh /usr/local/tomcat/bin/
            sh /usr/local/tomcat/bin/
            sh /usr/local/tomcat/bin/
    exit 0

You’ll need to make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat

sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tomcat should now be fully installed.

Restart the system and tomcat start automatically.


Posted by on October 7, 2011 in CentOS, Installations, Ubuntu


Tags: , , , ,

13 responses to “Automatic Starting Tomcat on ubuntu

  1. Jvm Host

    December 2, 2011 at 3:50 pm

    I would advise to use ‘sh /usr/local/tomcat/bin/ -force’ or even
    ‘killall -9 java’ as regular is not always working and can block the tomcat

  2. Tim-Hinnerk Heuer (@geekdenz)

    July 12, 2012 at 6:06 am

    Nice choice of theme and thanks for the great POST! 😉

  3. Team

    March 2, 2013 at 11:53 am

    It worked for me good job

  4. Andun Sameera

    June 8, 2013 at 8:45 am

    +1 Great…

  5. Tim Pizey (@timPizey)

    September 13, 2013 at 2:50 pm

    Thanks, though I used

    update-rc.d tomcat defaults

  6. Tom

    November 27, 2013 at 3:32 pm

    U saved my day 😉 great explanations, which finally helped me to get it up and running … I was so close …

  7. Sönmez ÇELİK

    March 27, 2014 at 2:48 pm

    Thank you. Finally I did it.

  8. shantanu

    August 17, 2015 at 6:12 am

    nice post…thank you so much. In my case it is working like a champ. However how to stop tomcat on linux shutdown. I am using Ubuntu

  9. James

    November 27, 2015 at 6:06 am

    Dear sir

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

    Thank you

  10. deligeli

    February 28, 2016 at 4:40 pm

    I tried it, but tomcat doesn’t start. any ideas?

  11. Neha

    March 18, 2016 at 3:53 pm

    Very good article. Just made my job easy, thanks for sharing.

  12. Gulab Singhj

    February 21, 2017 at 5:18 am

    hi i try this but not working any suggestion ?


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: