CentOS6设置Tomcat自动启动

来源:互联网 发布:主奴社交软件 编辑:程序博客网 时间:2024/04/28 06:39

shell文件:

#!/bin/sh#关闭进程killpids(){  pids=($(ps -ef | grep $1 | awk '{print $2}'))  for pid in ${pids[@]}; do    echo "关闭进程: pid ${pid}"    kill -9 ${pid}  done}killpids tomcat#搜索可能的安装目录echo "Directory list:"paths=($(find / -maxdepth 5 -type d -name '*tomcat*'))if [ ${#paths[@]} -lt 1 ];then  echo "Could not find your tomcat directory!"  exitfifor((i=0; i<${#paths[@]}; i++));do  if [[ ! ${paths[i]} =~ "tmp" ]]    then      echo "$i. ${paths[i]}"  fidoneecho -n "Which one is the root directory of tomcat? "#读取根目录while(true)  do    read snif [[ $sn -ge 0 && $sn -lt ${#paths[@]} ]]  then        path=${paths[sn]}        echo $pathbreak  else    echo "$sn is not expected"fi  done#设置环境变量sed -i '/CATALINA_HOME/d' /etc/profileecho "设置环境变量"echo "export CATALINA_HOME=$path" >> /etc/profilesource /etc/profile#开机启动#1.添加 /etc/rc.d/init.d/tomcatrm -rf /etc/rc.d/init.d/tomcattouch /etc/rc.d/init.d/tomcatchmod +x /etc/rc.d/init.d/tomcatecho '#!/bin/bash# chkconfig: 2345 89 2# Description: Tomcat Server basic start/shutdown script# /etc/init.d/tomcat -- startup script for the Tomcat servlet engine' >> /etc/rc.d/init.d/tomcatecho "TOMCAT_HOME=$path/binSTART_TOMCAT=$path/bin/startup.shSTOP_TOMCAT=$path/bin/shutdown.sh" >> /etc/rc.d/init.d/tomcatecho 'start() { echo -n "Starting tomcat: " cd $TOMCAT_HOME ${START_TOMCAT} echo "done."}stop() { echo -n "Shutting down tomcat: " cd $TOMCAT_HOME ${STOP_TOMCAT} echo "done."}case "$1" in start) start ;;stop) stop ;;restart) stop sleep 10 start ;;*) echo "Usage: $0 {start|stop|restart}"esacexit 0' >> /etc/rc.d/init.d/tomcat#2.添加到chkconfigchkconfig --add tomcatchkconfig tomcat onservice tomcat restart 

运行即可,中间要选择 tomcat 目录

0 0