您好,登錄后才能下訂單哦!
Nginx服務(wù)啟動(dòng)停止重新加載腳本
已知Nginx管理命令為:
啟動(dòng):/application/nginx/sbin/nginx
停止:/application/nginx/sbin/nginx -s stop
重新加載:/application/nginx/sbin/nginx -s reload
請(qǐng)用case腳本模擬Nginx啟動(dòng)關(guān)閉
/etc/init.d/nginx{start|stop|restart|reload}
并實(shí)現(xiàn)可通過(guò)chkonfig管理
腳本:
#
#nginx 啟動(dòng)腳本
#2018-11-29
#
#!/bin/bash
#調(diào)用系統(tǒng)函數(shù)及自定義變量
[ -f /etc/init.d/functions ]&& . /etc/init.d/functions
Pidfile=/application/nginx/logs/nginx.pid
#共用函數(shù)
publics(){
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "Nginx is $1" /bin/true
else
actio "Nginx is $1" /bin/false
fi
}
#啟動(dòng)函數(shù)start
start(){
if [ -f $Pidfile ];then
echo "Nginx is running"
else
/application/nginx/sbin/nginx
publics Started
fi
return $RETVAL
}
#關(guān)閉函數(shù)stop
stop(){
if [ ! -f $Pidfile ];then
echo "Nginx is not runing"
else
/application/nginx/sbin/nginx -s stop
publics Stopped
fi
return $RETVAL
}
#重新加載函數(shù)reload
reload(){
if [ ! -f $Pidfile ];then
echo "Can't open $Pidfile ,no such file directory"
else
/application/nginx/sbin/nginx -s reload
publics Reload
fi
return $RETVAL
}
#case 語(yǔ)句使用選擇
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
reload)
reload
RETVAL=$?
;;
restart)
stop
sleep 2
start
RETVAL=$?
;;
*)
echo "USAGE:$0 {satrt|stop|restart|reload}"
exit 1
;;
esac
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。