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

  • 相关阅读:
    COM编程概述
    计算机系统
    计算机启动过程
    资源共享型智能指针实现方式
    [6] 智能指针boost::weak_ptr
    [5] 智能指针boost::shared_ptr
    [4] 智能指针boost::scoped_ptr
    函数后面加throw关键字
    [3] 智能指针std::auto_ptr
    (原创)开发使用Android studio所遇到的一些问题总结
  • 原文地址:https://www.cnblogs.com/guoew/p/10391049.html
Copyright © 2011-2022 走看看