zoukankan      html  css  js  c++  java
  • 解压安装的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

  • 相关阅读:
    uC/OS-II时间(OS_time)块
    uC/OS-II任务(OS_task)块
    uC/OS-II信号(OS_sem)块
    uC/OS-II队列(OS_q)块
    uC/OS-II互斥信号(OS_mutex)块
    uC/OS-II内存(OS_mem)块
    elasticsearch-installation
    rabbitmq的安装
    str_翻转字符串
    str_2.判断两个字符串是否互为旋转词
  • 原文地址:https://www.cnblogs.com/phpdragon/p/4181698.html
Copyright © 2011-2022 走看看