创建tomcat的启动脚本

发布时间:2020-09-27编辑:脚本学堂
创建tomcat启动脚本

1、创建/etc/init.d/tomcatd文件,然后:
 

复制代码 代码如下:
chmod +x /etc/init.d/tomcatd
chkconfig --add tomcatd
chkconfig tomcatd on

2、将下列内容加入tomcatd文件中:
 

复制代码 代码如下:

#!/bin/bash
#
# Startup script for the tomcat
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.
# Source function library.

. /etc/rc.d/init.d/functions
JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat
export JAVA_HOME CATALINA_HOME

start(){
if [ -z $(/sbin/pidof java) ]; then
echo "Starting tomcat"
/usr/local/tomcat/bin/startup.sh
touch /var/lock/subsys/tomcat
else
echo "tomcat allready running"
fi
}

stop(){
if [ ! -z $(/sbin/pidof java) ]; then
echo "Shutting down tomcat"
/usr/local/tomcat/bin/shutdown.sh
until [ -z $(/sbin/pidof java) ]; do :; done
rm -f /var/lock/subsys/tomcat
else
echo "tomcat not running"
fi
}

case "$1" in
start)
start
;;

stop)
stop
;;

restart)
stop
start
;;

status)
/usr/local/tomcat/bin/catalina.sh version
;;

*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0