#!/bin/bash
JAVA_HOME="/usr/local/jdk1.7/jdk1.7"
TOMCAT_HOME="/usr/local/tomcat/apache_tomat-8"
export JAVA_HOME
usage="{stop|start|restart}"
start_tomcat="$TOMCAT_HOME/bin/startup.sh"
stop_tomcat="$TOMCAT_HOME/bin/shutdown.sh"
# look pid isexists
# THIS IS GET PID
PID=$( netstat -anp | grep 8080 |awk '{print $7}' | awk '{split($0,b,"/");print b[1]}')
# THIS IS REGULAR GET NUMBER
RES=$(echo "$PID" |awk '{if($0 ~ /^[0-9]+$/) print $0;}')
echo " value of tomcat pid------------------------> $PID"
echo "value of pid res---------------------------> $RES"
start(){
echo "starting tomcat..."
if [ -z "$RES" ]
then
${start_tomcat}
echo "start tomcat ok !"
else
echo "start tomcat ok ^^ !"
fi
}
stop(){
echo "stoping tomcat..."
if [ -n "$RES" ]
then
${stop_tomcat}
echo "stoped tomcat ok!"
else
echo "stoped tomcat ok ^^ !"
fi
}
# read arg
echo " please input: $usage "
read ANS
case $ANS in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo " please input :$usage"
exit 1
;;
esac
apache