爱乐眼底图像分析

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5766|回复: 0

centos tomcat 自启动

[复制链接]
发表于 2012-8-26 12:01:25 | 显示全部楼层 |阅读模式

首先为Tomcat编辑一段启动脚本,并置于/etc/rc.d/init.d目录下,让Tomcat和httpd一样作为一项系统服务,并随系统自动启动。

[root@sample ~]# vi /etc/rc.d/init.d/tomcat  ← 建立Tomcat启动脚本,如下:

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

export JDK_HOME=/home/graduate/jdk1.6.0_16  ← 以免启动时找不到jdk
export JAVA_HOME=/home/graduate/jdk1.6.0_16 ←  以免启动时找不到jdk

# Source function library.
. /etc/rc.d/init.d/functions

start(){
if [ -z $(/sbin/pidof java) ]; then
echo "Starting tomcat"
/home/graduate/apache-tomcat-6.0.14/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"
/home/graduate/apache-tomcat-6.0.14/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)
/home/graduate/apache-tomcat-6.0.14/bin/catalina.sh version
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0

[root@sample ~]# chmod 755 /etc/rc.d/init.d/tomcat  ← 将启动脚本属性设置为755(使之可执行)

[root@sample ~]# chkconfig --add tomcat  ← 将Tomcat加入到chkconfig中

[root@sample ~]# chkconfig tomcat on   ← 将Tomcat设置为自启动

[root@sample ~]# chkconfig --list tomcat  ← 确认Tomcat服务状态
tomcat 0ff 1ff 2n 3n 4n 5n 6ff  ← 确认2~5为on的状态就OK

[root@sample ~]# /etc/rc.d/init.d/tomcat start  ← 启动Tomcat

Starting tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JAVA_HOME: /usr/local/jdk1.5.0_08

测试Servlet/JSP



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



QQ|Archiver|手机版|小黑屋|爱乐眼底图像分析 ( 京ICP备1201155号 )        

GMT+8, 2024-11-22 01:58 , Processed in 0.043653 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表