sh nginx服务命令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh nginx服务命令相关的知识,希望对你有一定的参考价值。

#!/bin/sh
nginx=/usr/sbin/nginx
config=/etc/nginx/nginx.conf

case $1 in
    start)
        echo "Starting nginx"
        count=`ps -ef | grep 'nginx' | grep -v 'nginxd' | grep -v 'grep'`
        if [ ! -n "$count" ]; then
            $nginx -c $config
            if [ $? -ne 0 ]; then
                echo "Failed to start"
            else
                echo "Started"
            fi
        else
            echo "Nginx is running"
        fi
        ;;
    stop)
        echo "Stop nginx"
        count=`ps -ef | grep 'nginx' | grep -v 'nginxd' | grep -v 'grep'`
        if [ -n "$count" ]; then
            if ($nginx -s quit); then
                echo "Stopped"
            else
                echo "Failed to stop"
            fi
        else
            echo "Nginx is not running"
        fi
        ;;
    force-stop)
        echo "Force stop nginx"
        count=`ps -ef | grep 'nginx' | grep -v 'nginxd' | grep -v 'grep'`
        if [ -n "$count" ]; then
            if ($nginx -s stop); then
                echo "Stopped"
            else
                echo "Failed to stop"
            fi
        else
            echo "Nginx is not running"
        fi
        ;;
    reload)
        echo "Reload the configuration file"
        count=`ps -ef | grep 'nginx' | grep -v 'nginxd' | grep -v 'grep'`
        if [ -n "$count" ]; then
            if ($nginx -s reload); then
                echo "Reload configurion file finished"
            else
                echo "Failed to reload"
            fi
        else
            echo "Nginx is not running"
        fi
        ;;
    restart)
        echo "Restart Nginx"
        sh ${0} stop
        sleep 2
        sh ${0} start
        ;;
    show)
        ps -ef | grep 'nginx' | grep -v 'nginxd' | grep -v 'grep'
        ;;
    *)
        echo -n "Usage: $0 {start|stop|force-stop|reload|restart|show}"
        ;;
esac

以上是关于sh nginx服务命令的主要内容,如果未能解决你的问题,请参考以下文章

centos6.9下设置nginx服务开机自动启动

设置Nginx开机自启动

nginx 设置开机自动启动脚本

sh 以具有nologin shell的其他用户身份运行脚本或命令,例如nginx或www-data

sh 在一个命令中使用自定义补丁,配置和名称后缀为nginx构建Ubuntu或Debian软件包

sh 完美的Web服务器 - Nginx,Ajenti,Ubuntu