模拟启动Nginx的脚本[if条件语句练习]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模拟启动Nginx的脚本[if条件语句练习]相关的知识,希望对你有一定的参考价值。
说明: 已在CentOS 7.2 上编译安装nginx 1.13.6 -- 练手!!!
[[email protected] scripts]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.13.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.13.6 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0f
[[email protected] scripts]# cat nginx.sh
#!/bin/bash
#simulate the Nginx‘s running process;
. /etc/init.d/functions
CMD=$1
if [ "$CMD" = "start" ]
then
if [ `ps -ef | grep -c [n]ginx | wc -l` -gt 1 ]
then
echo "nginx already running."
exit 1
fi
/application/nginx/sbin/nginx &>/dev/null
if [ $? -eq 0 ]
then
action "start nginx" /bin/true
else
action "start nginx" /bin/false
fi
elif [ "$CMD" = "stop" ]
then
killall nginx &>/dev/null
if [ $? -eq 0 ]
then
action "stop nginx" /bin/true
else
action "stop nginx" /bin/false
exit 2
fi
elif [ "$CMD" = "restart" ]
then
killall nginx &>/dev/null
/application/nginx/sbin/nginx &>/dev/null
if [ $? -eq 0 ]
then
action "restart nginx" /bin/true
else
action "restart nginx" /bin/false
fi
else
echo "Usage: sh $0 {start|stop|restart}"
fi
以上是关于模拟启动Nginx的脚本[if条件语句练习]的主要内容,如果未能解决你的问题,请参考以下文章