tomcat开机启动 for centos

来源:互联网 发布:优化脱硫指标 编辑:程序博客网 时间:2024/05/16 07:52

要让tomcat在开机时自启动,需要在/etc/init.d目录下增加相应的脚本内容及步骤如下所示:

vi /etc/init.d/tomcat             //并输入如下内容:

# tomcat自启动脚本#!/bin/sh# chkconfig: 345 99 10# description: Auto-starts tomcat# /etc/init.d/tomcatd# Tomcat auto-start# Source function library.#. /etc/init.d/functions# source networking configuration.#. /etc/sysconfig/networkRETVAL=0# 请填写真实的JDK目录export JDK_HOME=/usr/java/jdk1.7.0_45 # 请填写真实的tomcat目录export CATALINA_HOME=/home/ldatum/usr/apache-tomcat-7.0.10# 请填写真实的tomcat目录export CATALINA_BASE=/home/ldatum/usr/apache-tomcat-7.0.10start(){    if [ -f $CATALINA_HOME/bin/startup.sh ];      then        echo $"Starting Tomcat"        $CATALINA_HOME/bin/startup.sh        RETVAL=$?        echo " OK"        return $RETVAL    fi}stop(){    if [ -f $CATALINA_HOME/bin/shutdown.sh ];      then        echo $"Stopping Tomcat"        $CATALINA_HOME/bin/shutdown.sh        RETVAL=$?        sleep 1        ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9        echo " OK"        # [ $RETVAL -eq 0 ] && rm -f /var/lock/...        return $RETVAL    fi}case "$1" in start)     start     ;; stop)     stop     ;; restart)     echo $"Restaring Tomcat"     $0 stop     sleep 1     $0 start     ;; *)     echo $"Usage: $0 {start|stop|restart}"     exit 1     ;;esacexit $RETVAL
保存退出。

之后,给其增加可执行权限:chmod +x /etc/init.d/tomcat

增加到自启动列表有相关配置:

[rafael@centos6 init.d]$ chkconfig --add tomcat

[rafael@centos6 init.d]$ chkconfig --level 2345 tomcat on



0 0
原创粉丝点击