首页 > 代码库 > linux tomcat service
linux tomcat service
LINUX创建tomcat的开机启动
创建tomcat启动脚本
放入 /etc/init.d/ (/etc/rc.d/init.d)目录,如:tomcat(没有类型)
设置执行权限 chmod 755 tomcat
加入开机启动 chkconfig --add tomcat
查看开机启动项 chkconfig --list
删除开机启动 chkconfig --del tomat
设置启动级别 chkconfig --level 2345 tomcat
注意事项:
tomcat 启动脚本
1.1 JAVA_HOME CATLINA_HOME可以不用指定,使用默认也可以;
1.2 也可以重新指定 特定地址,并export JAVA_HOME
加入服务时chkconfig --add tomcat
2.1 -bash: ./tomcat: /bin/bash^M: bad interpreter: 没有那个文件或目录
2.2 原因:windows与unix的编码格式不同
2.3 解决方法: 1.vi(vim) filename 2.:set ff? 3.:set ff=unix 并保存
tomcat脚本:
#!/bin/bash
# chkconfig: 2345 10 90
# description: Starts and Stops the Tomcat daemon.
TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-7.0.39-wf-82
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh
# necessary environment variables export
#CATALINA_HOME=$TOMCAT_HOME
#export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64
# source function library.
. /etc/rc.d/init.d/functions
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then echo "Tomcat not valilable..."
exit
fi
start(){
echo -n "Starting Tomcat: "
daemon $TOMCAT_START
echo
touch /var/lock/subsys/tomcat
}
stop(){
echo -n "Shutting down Tomcat: "
daemon $TOMCAT_STOP
rm -f /var/lock/subsys/tomcat.pid echo
}
restart(){
stop
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 ;;
restart)
stop
sleep 3
start ;;
status)
status ;;
*)
echo "Usage: tomcatd {start|stop|restart|status}"
exit 1
esac
exit 0
linux tomcat service