tomcat服务脚本

tomcat作为常用的web容器,使用非常广泛

此处略过tomcat的安装过程和配置过程。

#!/usr/bin/env bash
#tomcat启动脚本
#by mark
tomcat_dir=/usr/local/tomcat8/bin               #tomcat的bin目录
log=/usr/local/tomcat8/logs
#cd $tomcat_dir


##函数的定义
configtest() {                  #文件语法校验           
                sh $tomcat_dir/configtest.sh  &> /dev/null
                if [ $? -eq 0 ] ; then
                   echo -e "\033[32;49;1m tomcat: the configuration file /usr/local/tomcat8/conf/server.xml syntax is ok....\033[39;49;0m"
                   echo -e "\033[32;49;1m tomcat: configuration file /usr/local/tomcat8/conf/server.xml test is successful....\033[39;49;0m"
                else
                   echo "\033[41;37m Syntax is Error \033[0m" && tail -f $log/catalina.out
                fi

}
##configtest

#power start

pwstart() {
                sh $tomcat_dir/startup.sh &> /dev/null
                if [ $? -eq 0 ] ; then
                   echo -e "\033[32;49;1m Tomcat: Tomcat is running now .....\033[39;49;0m"
                fi
}

start() {                       #启动tomcat
                sh $tomcat_dir/startup.sh &> /dev/null
                if [ $? -eq 0 ] ; then
                   echo -e "\033[32;49;1m Tomcat: Tomcat is running now.....\033[39;49;0m"
                   sleep 3 && clear && sleep 7
                   tail -f $log/catalina.out
                fi

}

stop() {                        #停止tomcat
               pid=`netstat -lnpt |grep java |grep :8080 |awk -F: {'print $7'} |awk  '{print $3}' |awk -F/ '{print $1}'`
                kill -9 $pid
#               sh $tomcat_dir/shutdown.sh &> /dev/null
                if [ $? -eq 0 ] ; then
                   echo -e "\033[33;49;1m Tomcat: Tomcat is stopped....\033[39;49;0m"
                   #tail -f $log/catalina.out
                fi


}
case $1 in
      pwstart)
                pwstart
            ;;
        start)
                 start
            ;;
         stop)
                 stop
            ;;
      restart)
                 $0 stop
                 sleep 3
                 $0 start
            ;;
   configtest)
                 configtest
            ;;

            *)
                 echo "Usage: start|pwstart|stop|restart|configtest"
esac

#echo $0
#sleep 3                 
#echo `clear`
#sleep 1
#sleep 1
#sleep 1
#sleep 1
#sleep 1

#\033[32;49;1m Tomcat server restart succeed!\033[39;49;0m

#sh shutdown.sh                                 #停止tomcat
#sh start.sh                                    #启动tomcat


你可能感兴趣的:(tomcat,服务脚本)