linux下设置tomcat自启动

 

1:创建一个tomcat.sh文件,内容如下:

 

#!/bin/sh

#

# tomcat: Start/Stop/Restart tomcat

#

# chkconfig: 2345 80 20

# description: Tomcat is a Java Servlet Container

#

#

# match these values to your environment:

export CATALINA_BASE=/home/tomcat/tomcat6

export CATALINA_HOME=/home/tomcat/tomcat6

export CATALINA_TMPDIR=/home/tomcat/tomcat6/temp

export JRE_HOME=/usr/java/jdk1.5.0_06

 

 

 

# Source function library.

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

 

TOMCAT=/home/tomcat/tomcat6

 

start {

echo -n $"Starting Tomcat: "

$TOMCAT/bin/catalina.sh start

}

 

stop {

echo -n $"Stopping Tomcat: "

$TOMCAT/bin/catalina.sh stop

 

}

 

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

status)

;;

status)

;;

restart)

stop

start

;;

*)

echo $"Usage: $0 {start|stop|restart}"

;;

esac

exit $RETVAL

 

 

 

2种设置自启动模式

<推荐第1>

1: root账号登录,将tomcat.sh文件拷贝到/root/, 在该目录下输入:

Chmod 777 tomcat  tomcat赋最高权限

Vi  /etc/inittab

在文件内容末尾增加如下项,设置自启动tomcat进程。

self:2345:once:/root/tomcat.sh

 

 

 

2: tomcat文件拷贝到/etc/init.d/下,在该目录下输入:

Chmod 777 tomcat  tomcat赋最高权限

chkconfig --add tomcat  tomcat加入服务

chkconfig --level 345 tomcat on 设置级别

chkconfig --list tomcat 查看tomcat是否加入

 

启动tomcat service tomcat start

停止tomcat:  service tomcat stop 

 

你可能感兴趣的:(java,tomcat,linux,servlet,function,service)