TOMCAT管理シェルファイル
tomcatmanage.sh
#!/bin/bash
$JDkのインストールディレクトリはパラメータをシェルに渡して、シェル貰ってない場合
#Tomcatのインストールディレクトリの親ディレクトリはjdk1.6.0_14 があるかどうか
#管理サービスのコマンドは一つのシェルに書き込んで、シェルに渡すパラメータは異なるコマンド
#=========================================================================================================
PRG="$0″
# parsing the current command path
while [ -h “$PRG" ] ; do
ls=`ls -ld “$PRG"`
link=`expr “$ls" : '.*-> \(.*\)$’`
if expr “$link" : '/.*’ > /dev/null; then
PRG="$link"
else
PRG=`dirname “$PRG"`/"$link"
fi
done
# get the command path
PRGDIR=`dirname “$PRG"`
# PRGDIR maybe ../apache-tomcat-6.0.20/bin
# get the tomcat home path
tomcat_dir=`cd “$PRGDIR/.." ; pwd`
top_dir=`cd “$tomcat_dir/.."; pwd`
# set the default jdk directory name
jdk_name="jdk1.6.0_14″
# get the default jdk path
jdk_dir="$top_dir/$jdk_name"
# parse the parameter $2,set the jdk path,if $2 is not empty.
if [ -n “$2″ ]; then
jdk_dir="$2"
fi
# confirm that the jdk path is effective and set the JAVA_HOME environment variable
if [ -d “$jdk_dir" ]; then
export JAVA_HOME="$jdk_dir"
export JRE_HOME="$JAVA_HOME/jre"
#echo “JRE_HOME is $JRE_HOME"
else
echo “The JAVA_HOME environment variable is error,this environment variable is needed to run this program.JAVA_HOME=$jdk_dir."
echo “The application will exit."
exit 1
fi
# handle the request:start,stop,restart,version
case “$1″ in
start)
echo -n $"Tomcat server is starting: "
“$PRGDIR"/startup.sh >/dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
echo “Tomcat server has been started."
else
echo “Tomcat server failed to start."
fi
echo
;;
stop)
echo -n $"Tomcat server is stopping: "
“$PRGDIR"/shutdown.sh >/dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
echo “Tomcat server has been stopped."
else
echo “Tomcat server failed to stop."
fi
echo
;;
version)
“$PRGDIR"/version.sh
;;
restart|reload)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart|version}"
echo " start Start server"
echo " stop Stop server"
echo " restart Restart server"
echo " version What version of tomcat are you running?"
exit 1
esac