zoukankan      html  css  js  c++  java
  • nginx启动脚本

    如下为nginx启动脚本,如有不妥之处,欢迎指出。

    #!/bin/bash

    #chkconfig: 2345 80 90
    #description:auto_run

    source /etc/profile
    [ -f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1

    ng_path=/usr/local/lnmp/nginx
    [ -f ${ng_path}/sbin/nginx ] || exit 1
    [ -f ${ng_path}/conf/nginx.conf ] || exit 1

    debug=0

    function tof(){
        if [ ${status} -ne 0 ] ; then
            debug=1
        fi
    }

    case $1 in
        start) 
        $ng_path/sbin/nginx 2>/dev/null
        status=$?
        tof
        ;;
        stop)
        $ng_path/sbin/nginx -s stop 2>/dev/null
        status=$?
        tof
        ;;
        restart)
        $ng_path/sbin/nginx -s stop 2>/dev/null &&
        $ng_path/sbin/nginx 2>/dev/null
        status=$?
        tof
        ;;
        reload)
        $ng_path/sbin/nginx -s reload 2>/dev/null
        status=$?
        tof
        ;;
        status)
        sta=`netstat -anp | awk '/^tcp.*:80>/{print $NF}'|grep nginx `
        if [ "$sta" == "" ];then

            echo 'nginx is not running.'
        else 
            echo  "$sta"| awk -F '/' '{if($2 == "nginx"){print "SUCCESS! ",$2," running (",$1,")"}else {print "nginx is not running."}}'
        fi
        debug=2
        ;;
        check)
        $ng_path/sbin/nginx -t
        debug=2
        ;;
        *)
        echo 'USAGE: $0 <start|stop|restart|reload|status|check>'
        debug=3
        ;;

    esac
    if [ $debug -eq 0 ] ;then
        action "$0 $1" /bin/true
    elif [ $debug -eq 1 ];then
        action "$0 $1" /bin/false
    fi

    上述脚本中在查询状态时容易获取不到相应信息,需要根据实际情况作出相应修改

    下面附加在rhel7.X/centos7.X nginx的启动脚本                              ---20170813追加

     
    [Unit]
    Description=nginx service
    After=network.target

    [Service]
    Type=forking
    ExecStart=/usr/local/nginx-1.10.2/sbin/nginx -c /etc/nginx/nginx.conf
    ExecReload=/usr/local/nginx-1.10.2/sbin/nginx -s reload
    ExecStop=/usr/local/nginx-1.10.2/sbin/nginx -s stop
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

  • 相关阅读:
    内联函数和宏
    python面向对象高级:@property
    python面向对象高级:__slots__
    Python哈希表的例子:dict、set
    python数据结构之哈希表
    python数据结构之队列
    python数据结构之堆栈
    python数据结构之链表
    分治法及其python实现例子
    查找算法:二分法查找及其python实现案例
  • 原文地址:https://www.cnblogs.com/guoew/p/10391049.html
Copyright © 2011-2022 走看看