Install Tomcat under Linux and set auto-start

Source: Internet
Author: User

Under the Linux system, when a service is set up, it needs to be mounted under/ETC/RCX.D, and the startup script will be written under/etc/init.d/.

Create a new file under/etc/init.d/Tomcat (need to operate under root)

Vi/etc/init.d/tomcat

Write the following code:

# Tomcat Self-starter script

  1. #!/bin/sh

    # chkconfig:345 99 10

    # Description:auto-starts Tomcat

    #/ETC/INIT.D/TOMCATD

    # Tomcat Auto-start

    # Source function library.

    #. /etc/init.d/functions

    # source Networking configuration.

    #. /etc/sysconfig/network

    Retval=0

    Export JDK_HOME=/USR/JAVA/JDK1.7.0_45 (please fill in the actual JDK directory)

    Export catalina_home=/home/ldatum/usr/apache-tomcat-7.0.10 (please fill in the real Tomcat directory)

    Export catalina_base=/home/ldatum/usr/apache-tomcat-7.0.10 (please fill in the real Tomcat directory)

    Start ()

    {

    If [-f $CATALINA _home/bin/startup.sh];

    Then

    echo $ "Starting Tomcat"

    $CATALINA _home/bin/startup.sh

    Retval=$?

    echo "OK"

    Return $RETVAL

    Fi

    }

    Stop ()

    {

    If [-f $CATALINA _home/bin/shutdown.sh];

    Then

    echo $ "Stopping Tomcat"

    $CATALINA _home/bin/shutdown.sh

    Retval=$?

    Sleep 1

    PS-FWWU Tomcat | grep apache-tomcat|grep-v grep | Grep-v PID | awk ' {print $} ' |xargs kill-9

    echo "OK"

    # [$RETVAL-eq 0] && rm-f/var/lock/...

    Return $RETVAL

    Fi

    }

    Case "$" in

    Start

    Start

    ;;

    Stop

    Stop

    ;;

    Restart

    echo $ "restaring Tomcat"

    $ stop

    Sleep 1

    $ start

    ;;

    *)

    echo $ "Usage: $ {Start|stop|restart}"

    Exit 1

    ;;

    Esac

    Exit $RETVAL

  2. Once added, add executable permissions to it:chmod +x/etc/init.d/tomcat.

    1. The link to the shell file is then connected to the/etc/rc2.d/directory. The numbers in the/etc/rcx.d/directory for Linux represent the different run level, which is the order in which the boot starts, Ubuntu9.10 There are 0-5 six level, can not be casually connected to other directories, it may be in that directory when the program started Tomcat needs some of the library has not been loaded, with the LN command to link tomcat links Past:ln-s/etc/init.d/ Tomcat /etc/rc2.d/s16tomcat. The naming rules in the RCX.D directory are very specific, more different needs may be the beginning of s, may also be K start, after the number represents their boot sequence, detailed look at the respective directory of the Readme file

    2. The next step is to set the script to run automatically when the system starts, and stop automatically when the system shuts down, using the following command:chkconfig--add Tomcat. If chkconfig is not installed, it is installed with programs such as Apt-get or yum , and the general server version of Linux is already in place.

      Finally, use Chkconfig--list to confirm that you added the success

    3. Finally, the reboot system is restarted. After rebooting, you will find that your Tomcat has run successfully.

Install Tomcat under Linux and set auto-start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.