Tomcat's shell script---show the process number

Source: Internet
Author: User

#!/bin/bash

#

# Chkconfig:-95 15

# description:tomcat Start/stop/status Script

#Location of Java_home (bin files)

Export java_home=/usr/local/jdk1.7.0_75

#Add Java binary files to PATH

Export path= $JAVA _home/bin: $PATH

#CATALINA_HOME is the location of the instance of Tomcat

Catalina_home=/opt/tomcat

#TOMCAT_USER is the default USER of TOMCAT

Tomcat_user=www

#TOMCAT_USAGE is the message if this script was called without any options

Tomcat_usage= "USAGE: $ {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

#SHUTDOWN_WAIT is WAIT time in seconds for Java proccess to stop

Shutdown_wait=20

Tomcat_pid () {

Echo ' Ps-ef | grep $CATALINA _home | Grep-v grep | Tr-s "" |cut-d ""-f2 "

}

Start () {

pid=$ (Tomcat_pid)

If [-N "$pid"];then

Echo-e "\e[00;31mtomcat is already running (PID: $pid) \e[00m"

Else

Echo-e "\e[00;32mstarting tomcat\e[00m"

If [' user_exists $TOMCAT _user ' = "1"];then

Su $TOMCAT _user-c $CATALINA _home/bin/startup.sh

Else

$CATALINA _home/bin/startup.sh

Fi

Status

Fi

return 0

}

Status () {

pid=$ (Tomcat_pid)

If [-N "$pid"];then

Echo-e "\e[00;32mtomcat is running with PID: $pid \e[00m"

Else

Echo-e "\e[00;31mtomcat is not running\e[00m"

Fi

}

Stop () {

pid=$ (Tomcat_pid)

If [-N "$pid"];then

Echo-e "\e[00;31mstoping tomcat\e[00m"

$CATALINA _home/bin/shutdown.sh

Let kwait= $SHUTDOWN _wait

count=0;

Until [' Ps-p $pid | grep-c $pid ' = ' 0 '] | | [$count-gt $kwait]

Do

Echo-n-E "\e[00;31mwaiting for Processes to exit\e[00m\n";

Sleep 1

Let count= $count +1;

Done

If [$count-gt $kwait];then

Echo-n-E "\n\e[00;31mkilling processes which didn ' t stop after $SHUTDOWN _wait seconds\e[00m"

Kill-9 $pid

Fi

Else

Echo-e "\e[00;31mtomcat is not running\e[00m"

Fi

return 0

}

User_exists () {

If id-u $ >/dev/null 2>&1; Then

echo "1"

Else

echo "0"

Fi

}

Case $ in

Start

Start

;;

Stop

Stop

;;

Restart

Stop

Start

;;

Status

Status

;;

*)

ECHO-E $TOMCAT _usage

;;

Esac

Exit 0


This article is from the "System website Operations" blog, please be sure to keep this source http://cgc888.blog.51cto.com/3989433/1742507

Tomcat's shell script---show the process number

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.