nginx的自动化安装和启停脚本

个人原创,转载请注明出处和作者,否则依法追究法律责任

author: headsen chen

date:  2018-03-07  14:39:11

nginx_install.sh

#!/bin/bash
NGINX=nginx-1.9.3.tar.gz
useradd nginx
yum -y install gcc* pcre* zlib zlib-devel openssl*
cd /tmp
if [ -f $NGINX ];then
continue
else
wget http://nginx.org/download/$NGINX
tar fx $NGINX
fi
cd nginx-1.9.3 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre --with-http_ssl_module --with-http_stub_status_module && make && make install

[root@localhost init.d]# cat nginx
#!/bin/bash
start(){
/usr/local/nginx/sbin/nginx
if [ $? -eq 0 ];then
echo -e "The process nginx start                                   [ 33[032mok33[0m ]"
else
echo -e "The process nginx start                                   [ 33[031mfalse33[0m ]"
fi
}
stop(){
kill -9 `ps -ef |grep nginx: |awk '{print $2}'` >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "The process nginx stop                                   [ 33[032mok33[0m ]"
else
echo -e "The process nginx stop                                    [ 33[031mfalse33[0m ]"
fi
}
restart(){
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "The usage of number must be in start|restart|stop"
;;
esac

chmod +x /etc/init.d/nginx

chmod +x ngins_install.sh

原文地址:https://www.cnblogs.com/kaishirenshi/p/8522304.html