tomcat启动脚本-by Liemer_Lius

Shell Liemer_Lius 1111℃ 0评论

tomcat是常用的java项目容器,管理的时候没有统一的脚本,使得很多操作都需要手动去键入命令。于是乎,我自己编写了一个功能比较简单实用的启动脚本,脚本可以加入服务,可以启动,关闭,重启,查看状态,并且当启动的时候,可以用-log选项来动态查看catalina.out日志。

#!/bin/bash
# chkconfig: 23 33 22
# discription: To management tomcat start or stop or configtest...

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

TOMCAT_HOME=/usr/local/tomcat

RETVAL(){
ps aux |grep tomcat |grep -v grep |grep -v 'bash' &> /dev/null
DEBUG=$?
}

START (){
  RETVAL
  if [ $DEBUG -eq 0 ]; then
    echo -e "\033[31mTomcat is already running. Exit!\033[0m"
  else
    ${TOMCAT_HOME}/bin/startup.sh &>/dev/null
    if [ $? -eq 0 ]; then
      echo -n "Start Tomcat: "
      echo -e "\t[\033[35m OK \033[0m]"
    else
      echo -n "Starting Tomcat: "
      echo -e "\t[\031[35m Faild \033[0m]"
    fi
  fi
}

STOP (){
  RETVAL
  if [ $DEBUG -ne 0 ]; then
    echo "Tomcat is not running."
  else
    ${TOMCAT_HOME}/bin/shutdown.sh &> /dev/null
    if [ $? -eq 0 ]; then
      echo -e "Stop tomcat:\t[\033[35m OK \033[0m]"
    else
      echo -e "Stop tomcat:\t[\031[35m Faild \033[0m]"
    fi
  fi
}

HELP(){
  echo "service tomcat start [-log]|stop|restart|status|help"
}
STATUS(){
  RETVAL
  if [ $DEBUG -eq 0 ]; then
    echo "Tomcat is running!"
  else
    echo "Tomcat has stoped!"
  fi
}

if [ $# -lt 1 ]; then
  HELP
  exit 6
fi

case $1 in
start)
  START ;;
stop)
  STOP ;;
restart)
  STOP
  sleep 1
  START ;;
help)
  HELP
  exit 0 ;;
status)
  STATUS ;;
*)
  HELP
  exit 5 ;;
esac

if [ "$1"x == "startx" ]; then
  if [ "$2"x == "-logx" ]; then
    tail -f /usr/local/tomcat/logs/catalina.out
  fi
fi

脚本通过chkconfig –add tomcat加入到service以后,一些参数使用上出现错误,与脚本本身的运行有出入,待后续研究补充。

 

 

 

转载请注明:liutianfeng.com » tomcat启动脚本-by Liemer_Lius

喜欢 (0)

发表回复