Skip to content
Home » Automatic Starting Tomcat on ubuntu

Automatic Starting Tomcat on ubuntu

  1. Create a new file to write the code to run on computer start-up:
    Open a new file using the following command from terminal:
    sudo vi /etc/init.d/tomcat
    or
    sudo gedit /etc/init.d/tomcat
  2. Copy the below code in the new tomcat file opened:
    # Tomcat auto-start
    # description: Auto-starts tomcat
    # processname: tomcat
    # pidfile: /var/run/tomcat.pid
    export JAVA_HOME=/usr/lib/jvm/java-6-sun
    case $1 in
    start)
    sh /usr/local/tomcat/bin/startup.sh
    ;;
    stop)
    sh /usr/local/tomcat/bin/shutdown.sh
    ;;
    restart)
    sh /usr/local/tomcat/bin/shutdown.sh
    sh /usr/local/tomcat/bin/startup.sh
    ;;
    esac
    exit 0NOTE: change the path mentioned in above code, if the file path is different on your system.
  3. Make the script executable by running the chmod command:
    sudo chmod 755 /etc/init.d/tomcat
  4. Link this script to the startup folders with a symbolic link:
    sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
    sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
  5. Restart the system and tomcat start automatically:
    Open any browser and type localhost:8080/ to see the tomcat home page.

Leave a Reply

Your email address will not be published. Required fields are marked *

0 Shares
Tweet
Pin
Share
Share
Share