码迷,mamicode.com
首页 > 其他好文 > 详细

模拟启动Nginx的脚本[if条件语句练习]

时间:2017-10-28 19:52:44      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:$0   root   enabled   etc   条件语句   模拟   span   pcr   module   

说明: 已在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条件语句练习]

标签:$0   root   enabled   etc   条件语句   模拟   span   pcr   module   

原文地址:http://www.cnblogs.com/rainjin/p/7747774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!