Boot automatically on Tomcat under Linux

Source: Internet
Author: User

There are two ways to boot the Tomcat on Linux, one is simple, one is complex and professional, and we generally recommend the shell script startup method to implement using Shell script. Here are two methods that we'll cover separately.

1.shell Script Startup

As we all know, setting up a start-up service in Linux requires the/ETC/RCX.D to be mounted. In addition, you need to/etc/init.d some startup scripts. In fact, it is very simple to export the required environment variables, such as Java_home,jre_home, Catalina_home, Catalina_base and so on, and then directly call $catalina_home/bin/ Startup.sh will be able to start successfully.


The first step: we create a new file under/ETC/INIT.D Tomcat (need to operate under root privileges)

Vi/etc/init.d/tomcat  

Write down the following code, Tomcat self-launching script:

#!/bin/sh # chkconfig:345 # 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 JAVA_HOME=/USR/JAVA/JDK1.7.0_60 export JRE_HOME=/USR/JAVA/JDK1.7.0_60/JRE Export Catalina_home=/usr/local/tomcat Export Catalina_base=/usr/local/tomcat 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 Root | grep 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

Here is a special reminder to note that this sentence Ps-fwwu root | grep tomcat|grep-v grep | grep-v PID | awk ' {print $} ' |xargs kill-9, anyone familiar with Linux commands should Clear the meaning of this sentence, here is simply the first half of the query root user under the Tomcat process PID, individual changes according to the actual situation.

Step two: After you save the exit, add executable permissions to it


Step Three: Mount

Connect the shell file link 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 needed to some of the library has not been loaded, with the ln command link tomcat links Past: sudo ln-s/etc/init.d/ Tomcat/etc/rc2.d/s16tomcat. The naming rules under the RCX.D directory are very specific, more different needs may be the beginning of s, may also be the beginning of K, after the numbers represent their starting order, detailed look at the Readme file in their respective directories.

Ln-s/etc/init.d/tomcat/etc/rc2.d/s16tomcat  


Fourth step: Set the script to boot from

Set this script to automatically execute when the system starts, and stop automatically when the system shuts down, using the following command:

Chkconfig--add Tomcat  


Fifth Step: Verify

Execute sudo reboot. After rebooting, you will find that Tomcat has run successfully.


Digression: After adding this script we start, stop, restart Tomcat to use the command directly

Service Tomcat start  service Tomcat stop  


Other tomcat settings commands are: Chkconfig--list Tomcat chkconfig Tomcat on, and you can try to find out what the effect is.


2. Modify System Files 1. Modify/etc/rc.d/rc.local
 
Vi/etc/rc.d/rc.local   


2. Add the following two lines of script, remember the two lines, only the second line is not, you must add the first row. At the end of the/etc/rc.d/rc.local file, add:
    Export java_home=/usr/java/jdk1.7.0_60      /usr/local/tomcat/bin/startup.sh start  

Description:/usr/java/jdk1.7.0_60 is the JDK installation directory
/usr/local/tomcat is a tomcat-installed directory
3. Note: Modify the rc.local file to be executable
chmod +x  rc.local  



The first kind of shell script implementation of Tomcat start-up has been practiced, the second kind of useless, just found on the Internet has this information, so record down, easy to learn later. You can also refer to:http://blog.csdn.net/wangyonglin1123/article/details/50996300

Boot automatically on Tomcat under Linux

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.