1. 程式人生 > >模擬啟動Nginx的腳本[if條件語句練習]

模擬啟動Nginx的腳本[if條件語句練習]

zlib ons spa 條件語句 exit stub b- function fun

說明: 已在CentOS 7.2 上編譯安裝nginx 1.13.6 -- 練手!!!

[root@rainjin 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

[root@rainjin 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條件語句練習]