nginx启停脚本

【nginx启停脚本】上下观古今,起伏千万途。这篇文章主要讲述nginx启停脚本相关的知识,希望能为你提供帮助。

[root@manager case]# cat case3.sh #!/bin/bash #******************************************************************** #Author: Oldxu #Date: 2021-09-25 #FileName: case3.sh #Description: The test script #********************************************************************#ngin启停脚本 . /etc/init.d/functionsread -p "你想执行的操作是[ start | stop | restart ]: " action#定义变量 start_nginx() { #首先判断nginx是否正在运行 nginx_status=$(ps aux |grep nginx | grep -v grep | wc -l) if [ ${nginx_status} -eq \'0\' ]; then systemctl start nginx nginx_status=$(ps aux |grep nginx | grep -v grep | wc -l) if [ ${nginx_status} -ne \'0\' ]; then action "nginx成功启动...." /bin/true else action "nginx启动失败...." /bin/false exit fi else action "nginx 已经启动,无需再次启动....." /bin/false exit fi } stop_nginx() { #首先判断nginx是否正在运行 nginx_status=$(ps aux |grep nginx | grep -v grep | wc -l) if [ ${nginx_status} -ne \'0\' ]; then systemctl stop nginx & > /dev/null nginx_status=$(ps aux |grep nginx | grep -v grep | wc -l) if [ ${nginx_status} -eq \'0\' ]; then action "nginx停止成功...." /bin/true else action "nginx停止失败...." /bin/false exit fi else action "nginx已经停止,无需再次停止....." /bin/false exit fi } restart_nginx() { nginx_status=$(ps aux |grep nginx | grep -v grep | wc -l) if [ ${nginx_status} -eq \'0\' ]; then start_nginx & > /dev/null action "nginx重启完毕" /bin/true else stop_nginx & > /dev/null start_nginx & > /dev/null action "nginx重启完毕" /bin/true fi }case ${action} in start) start_nginx ; ; stop) stop_nginx ; ; restart) restart_nginx ; ; *) echo "你输入的内容有误,退出....." exit esac


    推荐阅读