1. 程式人生 > >nginx啟動腳本編寫

nginx啟動腳本編寫

nginx自動腳本

思路:

1、判斷nginx進程是否存在ps -ef|grep nginx |egrep -v "grep|nginxd.sh"

2、case 啟動|關閉|重啟|重新加載


缺陷:nginx分兩個不同的進程,分別是master管理進程和運行進程,如果某個進程出現問題的話這個腳本就無效,需要對pid進行流程控制。此腳本沒有涉及kill nginx的ID

[[email protected] ~]# cat nginxd.sh

#!/bin/bash

##

#nginx服務啟動腳本

. /etc/init.d/functions

nginx_dir=/mnt/tengine/tengine-2.1.2/sbin/

[ $# -ne 1 ] && {

echo "USAGE:$0 start|stop|restart|reload"

exit 9

}

testnginx(){

ps -ef|grep nginx |egrep -v "grep|nginxd.sh" &>/dev/null

result=$?

if [ $result -eq 0 ];then

return 1

else

return 0

fi

}


casefun(){

sum1=$1

case "$sum1" in

"start")

testnginx

[ $? -eq 1 ] && {

action "startnginx" /bin/false

exit 4

}

testnginx

[ $? -eq 0 ] && {

$nginx_dir/nginx

testnginx

[ $? -eq 1 ] && {

action "startnginx" /bin/true

}

}

;;

"stop")

testnginx

[ $? -eq 0 ] && {

acton "stopnginx" /bin/false

exit 6

}

testnginx

[ $? -eq 1 ] && {

$nginx_dir/nginx -s stop

testnginx

[ $? -eq 0 ] && {

action "stopnginx" /bin/true

}

}

;;

"restart")

testnginx

[ $? -eq 0 ] && {

action "stopnginx" /bin/false

}

testnginx

[ $? -eq 1 ] && {

$nginx_dir/nginx -s stop

testnginx

[ $? -eq 0 ] && {

action "restartnginx" /bin/true

}

}

$nginx_dir/nginx

testnginx

[ $? -eq 1 ] && {

action "startnginx" /bin/true

} || {

action "startnginx" /bin/false

}

;;

"reload")

testnginx

[ $? -eq 0 ] && {

action "reloadnginx" /bin/false

exit 7

}

[ $? -eq 1 ] && {

$nginx_dir/nginx -s reload

}

;;

*)

echo "USAGE:$0 start|stop|restart|reload"

exit 6

esac

}


casefun $*


本文出自 “常想一二” 博客,請務必保留此出處http://250919938.blog.51cto.com/962010/1947993

nginx啟動腳本編寫