#!/bin/bash
#时间变量,用于记录日志
d=date --date today +%Y%m%d_%H:%M:%S
#计算nginx进程数量
n=ps -C nginx --no-heading|wc -l
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived
if [ $n -eq “0” ]; then
/etc/init.d/nginx start
n2=ps -C nginx --no-heading|wc -l
if [
n
2
−
e
q
"
0
"
]
;
t
h
e
n
e
c
h
o
"
n2 -eq "0" ]; then echo "
n2−eq"0"];thenecho"d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
systemctl start nginx
主机的check_ng.sh
最新推荐文章于 2023-06-29 19:09:46 发布