zoukankan      html  css  js  c++  java
  • tomcat启动脚本

      1 #!/bin/bash  
      2 #  
      3 # chkconfig: - 95 15   
      4 # description: Tomcat start/stop/status script  
      5 
      6 #Location of JAVA_HOME (bin files)  
      7 export JAVA_HOME=/usr/local/jdk1.7
      8 
      9 #Add Java binary files to PATH  
     10 export PATH=$JAVA_HOME/bin:$PATH
     11 
     12 #CATALINA_HOME is the location of the configuration files of this instance of Tomcat  
     13 CATALINA_HOME=/usr/tomcats/tomcat8081
     14 
     15 #TOMCAT_USER is the default user of tomcat  
     16 TOMCAT_USER=root
     17 
     18 #TOMCAT_USAGE is the message if this script is called without any options  
     19 TOMCAT_USAGE="Usage: $0 {e[00;32mstarte[00m|e[00;31mstope[00m|e[00;32mstatuse[00m|e[00;31mrestarte[00m}"
     20 
     21 #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop  
     22 SHUTDOWN_WAIT=20
     23 
     24 tomcat_pid() {
     25         echo `ps -ef | grep $CATALINA_HOME | grep -v grep | tr -s " "|cut -d" " -f2`
     26 }
     27 
     28 start() {
     29   pid=$(tomcat_pid)
     30   if [ -n "$pid" ];then
     31     echo -e "e[00;31mTomcat is already running (pid: $pid)e[00m"  
     32   else
     33     echo -e "e[00;32mStarting tomcate[00m"  
     34     if [ `user_exists $TOMCAT_USER` = "1" ];then
     35       su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
     36     else
     37       $CATALINA_HOME/bin/startup.sh
     38     fi
     39     status
     40   fi
     41   return 0
     42 }
     43 
     44 status(){
     45   pid=$(tomcat_pid)
     46   if [ -n "$pid" ];then
     47     echo -e "e[00;32mTomcat is running with pid: $pide[00m"  
     48   else
     49     echo -e "e[00;31mTomcat is not runninge[00m"  
     50   fi
     51 }
     52 
     53 stop() {
     54   pid=$(tomcat_pid)
     55   if [ -n "$pid" ];then
     56     echo -e "e[00;31mStoping Tomcate[00m"  
     57         $CATALINA_HOME/bin/shutdown.sh
     58 
     59     let kwait=$SHUTDOWN_WAIT
     60     count=0;
     61     until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]  
     62     do
     63       echo -n -e "e[00;31mwaiting for processes to exite[00m
    ";
     64       sleep 1
     65       let count=$count+1;
     66     done
     67 
     68     if [ $count -gt $kwait ];then
     69       echo -n -e "
    e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT secondse[00m"  
     70       kill -9 $pid
     71     fi
     72   else
     73     echo -e "e[00;31mTomcat is not runninge[00m"  
     74   fi
     75 
     76   return 0
     77 }
     78 
     79 user_exists(){
     80   if id -u $1 >/dev/null 2>&1; then
     81     echo "1"  
     82   else
     83     echo "0"  
     84   fi
     85 }
     86 
     87 case $1 in
     88         start)
     89           start
     90         ;;
     91 
     92         stop)
     93           stop
     94         ;;
     95 
     96         restart)
     97           stop
     98           start
     99         ;;
    100 
    101         status)
    102       status
    103         ;;
    104 
    105         *)
    106       echo -e $TOMCAT_USAGE  
    107         ;;
    108 esac
    109 exit 0

    说明:红色字体是需要根据自己的tomcat以及jdk的路径进行手动配置的,运行tomcat的用户也需要自己配置,配置的账号系统中要存在。

  • 相关阅读:
    eclipse中文乱码
    学习进度(7)
    校园管家(Android开发团队项目)NABCD
    NABCD(团队项目)
    android studio连接真机大概问题
    01梦断代码阅读笔记
    学习进度(6)
    android studio学习(一)
    地铁出行系统1.0
    学习进度(4)
  • 原文地址:https://www.cnblogs.com/fansik/p/5783760.html
Copyright © 2011-2022 走看看