当前位置: 技术问答>linux和unix
诸神,给个脚本吧,开机自动运行tomcat的,谢谢了
来源: 互联网 发布时间:2017-02-12
本文导语: 不懂linux,但需要在上开机运行tomcat 找了几个例子,试了都不成,笨! redhat linux环境是: jdk6 tomcat是7.0.26,是个解压免安装的,位置在/usr/local/apache-tomcat-7.0.26 请高人给个可开机自启动的脚本!谢谢了 ...
不懂linux,但需要在上开机运行tomcat
找了几个例子,试了都不成,笨!
redhat linux环境是:
jdk6
tomcat是7.0.26,是个解压免安装的,位置在/usr/local/apache-tomcat-7.0.26
请高人给个可开机自启动的脚本!谢谢了
找了几个例子,试了都不成,笨!
redhat linux环境是:
jdk6
tomcat是7.0.26,是个解压免安装的,位置在/usr/local/apache-tomcat-7.0.26
请高人给个可开机自启动的脚本!谢谢了
|
首先为Tomcat编辑一段启动脚本,并置于/etc/rc.d/init.d目录下,让Tomcat和httpd一样作为一项系统服务,并随系统自动启动。
vi /etc/rc.d/init.d/tomcat //添加以下脚本
#!/bin/bash## Startup script for the tomcat## chkconfig: 345 80 15# description: Tomcat is a Servlet+JSP Engine.
export JDK_HOME=/usr/java/jdk1.6.0_26
export JAVA_HOME=/usr/java/jdk1.6.0_26
# Source function library.
./etc/rc.d/init.d/functions
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)
stopstart
;;
status)
/usr/local/tomcat/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 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2~5为on的状态就OK
启动/关闭/重启tomcat:service tomcat start/stop/restart
如果安装目录不一样,注意修改下目录
vi /etc/rc.d/init.d/tomcat //添加以下脚本
#!/bin/bash## Startup script for the tomcat## chkconfig: 345 80 15# description: Tomcat is a Servlet+JSP Engine.
export JDK_HOME=/usr/java/jdk1.6.0_26
export JAVA_HOME=/usr/java/jdk1.6.0_26
# Source function library.
./etc/rc.d/init.d/functions
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)
stopstart
;;
status)
/usr/local/tomcat/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 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2~5为on的状态就OK
启动/关闭/重启tomcat:service tomcat start/stop/restart
如果安装目录不一样,注意修改下目录
|
编辑/etc/rc.d/rc.local 增加内容(假设JDK目录是/usr/jdk)
export JAVA_HOME=/usr/jdk
/usr/local/apache-tomcat-7.0.26/tomcat/bin/startup.sh
export JAVA_HOME=/usr/jdk
/usr/local/apache-tomcat-7.0.26/tomcat/bin/startup.sh
|
在用户目录下的.bashrc中添加启动tomcat的命令就行了!
|
chkconfig service on
|
例如:
#whereis java
java: /usr/java/jdk-1_5_0_02
这里是防止tomcat启动时未设置java环境。
/etc/rc.d/rc.local添加一行
/usr/local/apache-tomcat-7.0.26/tomcat/bin/startup.sh
试一下如果启动成功则可以不设java环境。
另外在用户目录下设置.bashrc同样添加
/usr/local/apache-tomcat-7.0.26/tomcat/bin/startup.sh
两者不同处在于前者在系统启动后启动tomcat
后者在用户启动后启动tomcat