nginx 服务启动管理脚本 留存备用

360影视 2024-12-27 17:31 3

摘要:#!/BIN/bashumask 077BIN_PATH=$(cd "$(dirname "$0")"; pwd)cd $BIN_PATHsource ~/.bash_profilesource ./common.shLUAJIT_DIR=$INSTALL_D

#!/BIN/bash

umask 077

BIN_PATH=$(cd "$(dirname "$0")"; pwd)

cd $BIN_PATH

source ~/.bash_profile

source ./common.sh

LUAJIT_DIR=$INSTALL_DIR/nginx/nginx/luajit

export LUAJIT_LIB=$LUAJIT_DIR/lib

export LUAJIT_INC=$LUAJIT_DIR/include/luajit-2.1

export LD_LIBRARY_PATH=$LUAJIT_DIR/lib:$LD_LIBRARY_PATH

start {

$INSTALL_DIR/nginx/nginx/sbin/nginx -c $INSTALL_DIR/nginx/nginx/conf/nginx.conf -p $INSTALL_DIR/nginx/nginx

if [[ -d "$INSTALL_DIR/keepalived" && -f $INSTALL_DIR/nginx/nginx/keepalived/keepalived_nginx.conf && -f $INSTALL_DIR/nginx/nginx/keepalived/.rootdir ]]; then

sudo $INSTALL_DIR/keepalived/sbin/keepalived \

-f $INSTALL_DIR/nginx/nginx/keepalived/keepalived_nginx.conf -d -D -S 0 --pid=$INSTALL_DIR/nginx/nginx/keepalived/keepalived_nginx.pid \

--vrrp_pid=$INSTALL_DIR/nginx/nginx/keepalived/vrrp_nginx.pid \

--checkers_pid=$INSTALL_DIR/nginx/nginx/keepalived/checkers_nginx.pid

sleep 2

fi

chmod 640 $INSTALL_DIR/nginx/nginx/logs/*

}

stop {

if [[ -n "$(ps aux | grep "$INSTALL_DIR/nginx/nginx/sbin" | grep -v grep)" ]]; then

$INSTALL_DIR/nginx/nginx/sbin/nginx -s stop -p $INSTALL_DIR/nginx/nginx

fi

if [[ -n "$(ps aux | grep keepalived_nginx | grep -v grep)" ]]; then

sudo pkill -f keepalived_nginx

fi

}

reload {

$INSTALL_DIR/nginx/nginx/sbin/nginx -s reload -p $INSTALL_DIR/nginx/nginx

else

echo "nginx not running!"

exit 3

fi

}

status {

pid=`ps -ef | grep "$INSTALL_DIR/nginx/nginx/sbin/nginx" | grep -v 'grep' | awk '{print $2}'`

if [[ ! -z "$pid" ]]; then

hosts=(`grep 'listen' $INSTALL_DIR/nginx/nginx/conf/nginx.conf | awk '{print $2}' | awk -F ";" '{print $1}'`)

for host in ${hosts[@]}; do

ip="127.0.0.1"

port=${host#*:}

if [[ $str =~ ":" ]]; then

ip=${host%:*}

fi

check_service --service-name platform-nginx --shell="

echo "nginx service available!"

if [[ -f $INSTALL_DIR/nginx/nginx/keepalived/keepalived_nginx.conf ]]; then

if [[ -z "$(ps aux | grep keepalived_nginx | grep -v grep | wc -l)" ]]; then

echo "nginx keepalived service unavailable!"

exit 1

else

echo "nginx keepalived service available!"

exit 0

fi

fi

else

echo "nginx not running!"

exit 3

fi

}

case $1 in

start)

start

;;

stop)

stop

;;

restart)

stop

sleep 5

start

;;

reload)

reload

;;

status)

status

;;

esac

来源:小夏科技论

相关推荐