RHEL 5.4 Tomcat 6 Startup Script (开机启动)

[edgen@rhel54 ~]$ su - root
口令:
[root@rhel54 rc3.d]# cd /etc/rc.d/init.d/


[root@rhel54 init.d]# vi tomcat
[root@rhel54 init.d]# cat tomcat
#!/bin/bash
# chkconfig: 345 90 10
# description: Tomcat 6 Startup Script
# /etc/rc.d/init.d/tomcat

 

TOMCAT_HOME=/usr/apache-tomcat-6.0.29
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh

 

CATALINA_HOME=$TOMCAT_HOME
export JAVA_HOME=/usr/java/jdk1.6.0_23

 

. /etc/rc.d/init.d/functions

 

#. /etc/sysconfig/network

 

#[ "${NETWORKING}" = "no" ] && exit 0

 

if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
 echo "Tomcat not valiable..."
 exit 1
fi

 

start(){
 echo -n "Starting Tomcat: "
 daemon $TOMCAT_START
 touch /var/lock/subsys/tomcat
 echo "OK"
}

 

stop(){
 echo -n "Shutting down Tomcat: "
 daemon $TOMCAT_STOP
 rm -f /var/lock/subsys/tomcat
 echo "OK"
}

 

restart(){
 stop
 sleep 3
 start
}

 

status(){
 ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
 read LINE < /tmp/tomcat_process_count.txt
 if [ $LINE -gt 0 ]
 then
  echo -n "tomcat( pid "
  ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  echo -n ") is running..."
  echo
 else
  echo "Tomcat is stopped"
 fi
}

 

case "$1" in
 start)
  start
 ;;
 stop)
  stop
 ;;
 reload|restart)
  restart
 ;;
 status)
  status
 ;;
 *)
  echo "Usage: tomcat {start|stop|reload|restart|status}"
  exit 1
esac

 

exit 0

 

[root@rhel54 init.d]# chmod 755 tomcat
[root@rhel54 init.d]# ll | grep tomcat
-rwxr-xr-x 1 root   root      1340 01-13 17:15 tomcat

 

[root@rhel54 init.d]# chkconfig --add tomcat

[root@rhel54 init.d]# chkconfig --list | grep tomcat
tomcat          0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭

 

[root@rhel54 init.d]# service tomcat status
tomcat( pid 24843 24949 ) is running...

 

[root@rhel54 init.d]# ln -s /etc/rc.d/init.d/tomcat /etc/rc3.d/K10tomcat
[root@rhel54 init.d]# ln -s /etc/rc.d/init.d/tomcat /etc/rc4.d/K10tomcat
[root@rhel54 init.d]# ln -s /etc/rc.d/init.d/tomcat /etc/rc5.d/K10tomcat

 

[root@rhel54 init.d]# service tomcat stop

[root@rhel54 init.d]# service tomcat start

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值