Tomcat self-boot script in CentOS

Source: Internet
Author: User
Tags centos tomcat

Previously built for the company's Tomcat environment (CentOS installation configuration JDK1.7 and TOMCAT7), developers say that every time you start Tomcat is inconvenient, every time to go under the/usr/local/apache-tomcat-7.0.26/bin to execute, It's a waste of time and simplicity. Well, there's a requirement to improve, so here's a look at the Self starter script I'm looking for.
System: CentOS 5.x
Environment: apache-tomcat-7.0.26 JDK-7U3

Script content:

The code is as follows Copy Code

#!/bin/bash
# chkconfig:2345 10 90
# Description:start and Stop the Tomcat daemon.

Tomcat_home=/usr/local/tomcat
tomcat_start= $TOMCAT _home/bin/startup.sh
tomcat_stop= $TOMCAT _home/bin/shutdown.sh

# Necessary Environment Variables export
Catalina_home= $TOMCAT _home
Export java_home=/usr/java/jdk1.7.0_03

# source function library.
. /etc/rc.d/init.d/functions

# source Networking configuration.
. /etc/sysconfig/network

# Check that networking are up.
[' ${networking} ' = ' no '] && exit 0

# Check for Tomcat script
if [!-F $TOMCAT _home/bin/catalina.sh]
Then echo "Tomcat not valilable ..."
Exit
Fi

Start () {
Echo-n "Starting Tomcat:"
Daemon $TOMCAT _start
Echo
Touch/var/lock/subsys/tomcat
}

Stop () {
Echo-n $ "Shutting down Tomcat:"
Daemon $TOMCAT _stop
Rm-f/var/lock/subsys/tomcat.pid Echo

}

Restart () {
Stop
Start
}

Status () {
    ps ax--width=1000 | grep [o]rg.apache.catalina.startup.bootstrap start] | awk ' {PRI NTF $ ""} ' | WC | awk ' {print $} ' >/tmp/tomcat_process_count.txt
    read Line </tmp/tomcat_process_count.txt
    If [$line-gt 0]; then
        echo-n Tomcat (PID
        PS Ax--width=1000 | grep "Org.apache.catalina.startup.Bootstrap Start" | awk ' {printf $ '} '
        echo-n ') is running ... "
   &nbs p;    Echo
    else
        echo "Tomcat is Stopped "
    fi
}

Case "$" in
Start
start;;
Stop
stop;;
Restart)
Stop
Sleep 3
start;;
Status
status;;
*)
echo "USAGE:TOMCATD {start|stop|restart|status}"
Exit 1
Esac
Exit 0

After saving, go to/usr/local/and execute:

The code is as follows Copy Code

Ln-s Apache-tomcat-7.0.26/tomcat

That matches the path in my script:/usr/local/tomcat
And then you confirm the JDK path, and mine is/usr/java/jdk1.7.0_03.

Then give permission to do it from start:

The code is as follows Copy Code
chmod +x/etc/init.d/tomcat
Chkconfig--add Tomcat
Chkconfig Tomcat on

Finally verify if the script can start and stop Tomcat

The code is as follows Copy Code
Service Tomcat Stop
Service Tomcat Start

If you don't have a problem, check to see if the JDK and Tomcat paths are correct if you have a problem.

Related Article

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.