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

  • 相关阅读:
    git 错误 fatal: Not a valid object name: 'master'.
    SQL: select一组数据,concat同表同列的数据
    Linux curl usage
    Regular Expression
    浅谈Linux Process status,环境锁
    浅谈Manpage
    Java文件读写详解。 附txt乱码问题, html乱码问题
    在ubuntu 18.04下装有线守护wg
    centOS 7 换ssh端口
    如何把DEBIAN变成UBUNTU-DESKTOP最少化安装
  • 原文地址:https://www.cnblogs.com/guoew/p/10391049.html
Copyright © 2011-2022 走看看