zoukankan      html  css  js  c++  java
  • Shell脚本

    OS:CentOS/Redhat 系列

    并在 Centos 6.7 和 Centos 7.2 上测试正常

    #!/bin/bash
    #
    # auth: daxin
    # time: 2018/07/10
    #
    # nginx    start nginx web server
    # 
    # chkconfig: - 10 90
    # description: Start, stops and reload nginx web server
    #
    # config: /usr/local/nginx/conf/nginx.conf
    # config: /usr/local/nginx/conf/vhosts
    #
    ### BEGIN INIT INFO
    # Provides: nginx
    # Required-Start:
    # Required-Stop:
    # Default-Start: 3
    # Default-Stop: 
    # Short-Description: start and stop nginx web server
    # Description: Start, stop and reload nginx web server
    ### END INIT INFO
    
    # Source function library
    . /etc/init.d/functions
    
    NGINX_DIR="/usr/local/nginx"
    NGINX="${NGINX_DIR}/sbin/nginx"
    NGINX_CONF="${NGINX_DIR}/conf/nginx.conf"
    PROG=$(basename $NGINX)
    LOCK_FILE="${NGINX_DIR}/${PROG}.lock"
    
    # check Command exists
    if [ ! -x ${NGINX} ]; then
        echo -n $"${NGINX} does not exists."; warning; echo
        exit 5
    fi
    
    function start() {
        [ -f $NGINX_CONF ] || exit 6 
        $NGINX -c $NGINX_CONF 
        retval=$?
        if [ $retval -eq 0 ]; then
            touch $LOCK_FILE
            action "Starting $PROG" /bin/true
        else
            action "Starting $PROG" /bin/false
        fi
        return $retval
    }
    
    function stop() {
        pkill $PROG
        retval=$?
        if [ $retval -eq 0 ]; then
            rm -f $LOCK_FILE
            action "Stop $PROG" /bin/true
        else
            action "Stop $PROG" /bin/false   
        fi
        return $retval
    }
    
    function restart() {
        configtest_q || return 6
        stop
        start
    }
    
    function reload() {
        configtest_q || return 6
        nginx_main_process=$(ps aux | grep $NGINX | grep -v grep | awk '{print $2}')
        kill -HUP $nginx_main_process
        retval=$?
        if [ $retval -eq 0 ]; then
            action "Reload $PROG" /bin/true
        else
            action "Reload $PROG" /bin/false
        fi
        return $retval
    }
    
    function configtest_q() {
        $NGINX -t -c $NGINX_CONF
    }
    
    function status() {
        nginx_main_process=$(ps aux | grep $NGINX | grep -v grep | awk '{print $2}')
        if [ -z $nginx_main_process ]; then
            action "$PROG is not running" /bin/false
        else
            action "$PROG is runing" /bin/true
        fi
    }
    
    
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        reload)
            reload
            ;;
        restart)
            restart
            ;;
        configtest)
            configtest_q
            ;;
        status)
            status
            ;;
        *)
            echo $"Usage: $0 {start|stop|reload|configtest|status|restart}"
            exit 2
    esac
      
    

      

  • 相关阅读:
    mysql高级之编程优化
    高性能产品必由之路
    linux下安装xhprof
    linux下安装apc
    linux下安装vld
    python装饰器通俗易懂的解释!
    python函数基础 与文件操作
    python基础入门一(语法基础)
    iOS Keychain,SSKeychain,使用 理解 原理
    起头
  • 原文地址:https://www.cnblogs.com/dachenzi/p/9290132.html
Copyright © 2011-2022 走看看