您的位置:首页 > 运维架构 > Tomcat

tomcat启动脚本

2015-12-13 23:05 537 查看
#!/bin/bash

#chkconfig: 2345 10 90

source /etc/init.d/functions

if [ -f /etc/system/tomcat ];then

   source  /etc/system/tomcat

fi

prog=tomcat

tomcat={ /usr/local/tomcat/bin/catalina.sh start &>/dev/null }

pidfile=${pidfile-/var/run/tomcat.pid}

lockfile=${lockfile-/var/lock/subsys/tomcat.lock}

start() {

   echo -n "Starting tomcat"

   daemon $tomcat $OPTIONS

   RETVAL=$?

   [ $RETVAL -eq 0 ] && touch $pidfile $lockfile

   echo

}

stop() {

   echo -n "Stoping tomcat"

   killproc  java

   RETVAL=$?

   [ $RETVAL -eq 0 ]  && rm -rf $pidfile

   echo

}

reload() {

   echo -n "Reloading tomcat"

   killproc  java -HUP

   echo

}

status() {

   netstat -nltp|grep 8080 &>/dev/null && netstat -ntlp | grep 8009 &>/dev/null

   RETVAL=$?

  if  [ $RETVAL -eq 0 ];then

  echo "tomcat is running"

    else

      echo "tomcat is stopped"

  fi

}

case $1 in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;;

status)

status

;;

*)

echo "Usage service tomcat{start|stop|restart|reload}"

esac

note:在脚本编写完成之后,我们会执行下面的操作

chkconfig --add tomcat

chkconfig tomcat  on

但是在执行上面命令的过程中,有可能会出现下面的错误

service tomcat does not support chkconfig

解决办法为:在脚本的开头加上

#chkconfig: 2345 10 90
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: