• 解压安装的tomcat, 使用chkconfig命令让tomcat 随机启动,tomcat 变为系统服务


    使用解压安装的tomcat包,命令行输入 service tomcat start 会报 tomcat: unrecognized service 错误提示,意思是说系统没有找到该服务。

    好了,我们现在要解决的问题就是这个报错提示,让我们的解压安装版tomcat也可以支持yum安装方式的service tomcat start命令。

    在/xxx/tomcat/bin/目录下新建一个tomcatd 文件,编辑内容如下:

    #!/bin/bash 
    # 
    # tomcatd This shell script takes care of starting and stopping 
    # standalone tomcat 
    # chkconfig: 345 91 10 
    # description: tomcat service 
    # processname: tomcatd 
    # config file:
    # Source function library. 
    . /etc/rc.d/init.d/functions
    # Source networking configuration. 
    . /etc/sysconfig/network
    # Check that networking is up. 
    if [ "${NETWORKING}" = "no" ]; then
        echo "Network is stoped! Please open the network!";
        exit 0
    fi 
    
    #执行用户
    executor=tomcat
    prog=tomcatd
    export JAVA_HOME=/usr/local/jdk7/
    export CATALINA_HOME=/usr/local/tomcat/
    
    PATH=$PATH:$JAVA_HOME/bin
    
    STARTUP="$CATALINA_HOME/bin/catalina.sh start" 
    SHUTDOWN="$CATALINA_HOME/bin/catalina.sh stop"
    
    if [ ! -f $CATALINA_HOME/bin/startup.sh ]; then 
        echo "CATALINA_HOME for tomcatd not available" 
        exit 0
    fi
    
    
    start() {
        # Start daemons.
        echo -e $"Startting tomcat service: " 
        su - $executor -c "$STARTUP" 
        status
        RETVAL=$? 
        return $RETVAL 
    }
    
    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 "tomcatd ( pid "
            ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
            echo ") is running..."
        else
            echo "Tomcat is stopped"
        fi
    }
    
    stop() { 
        # Stop daemons. 
        echo -e $"Stoping tomcat service:" 
        su - $executor -c "$SHUTDOWN" 
        RETVAL=$? 
        return $RETVAL 
    }
    
    # See how we were called. 
    case "$1" in 
    start) 
        start 
        ;; 
    stop) 
        stop 
        ;; 
    restart|reload)    
        stop 
        sleep 10
        start 
        RETVAL=$? 
        ;; 
    status) 
        status
        RETVAL=$? 
        ;; 
    *) 
        echo $"Usage: $0 {start|stop|restart|status}" 
        exit 1 
    esac
    exit $RETVAL
    # chmod a+x /usr/local/tomcat/bin/tomcat  //配置可执行权限
    # ln -s /usr/local/tomcat/bin/tomcatd /etc/init.d/tomcatd  //新建软链接
    # chkconfig --level 235 tomcatd on //设置为随机启动
    # service tomcatd status  //查看启动状态

    好了,现在就可以使用可爱的 service 命令了,该死的 /xxx/tomcat/bin/startup.sh (/xxx/tomcat/bin/catalina.sh start) 命令丢一边去吧!

    PS:

    http://blog.csdn.net/cnfixit/article/details/7030666

    http://www.jb51.net/article/34332.htm

    http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html

  • 相关阅读:
    Spring 学习7 -事务
    Spring学习 6- Spring MVC (Spring MVC原理及配置详解)
    看秒杀系统的时候看到的关于并发队列的介绍,摘抄如下
    Spring 学习 3- AOP
    Spring学习-1 框架总览
    Spring 学习 5- task 定时任务
    JAVA锁机制-可重入锁,可中断锁,公平锁,读写锁,自旋锁,
    指定链接的样式的顺序
    css方法实现div固定浏览器底端
    文件中批量搜索字符串
  • 原文地址:https://www.cnblogs.com/phpdragon/p/4181698.html
Copyright © 2020-2023  润新知