1、编写脚本nginx_restart.sh
#!/bin/bash
ps -ef | grep nginx | grep -v grep > /data/nginx/nginx_restart.txt
file=$(cat /data/nginx/nginx_restart.txt | grep process | grep -v nginx_restart | awk '{print $2}')
file_num=`cat /data/nginx/nginx_restart.txt | grep process | grep -v nginx_restart| wc -l`
if [ $file_num -ge 1 ]
then
for i in $file
do
`kill -9 $i`
done
DATE1=`date +"%Y-%m-%d/%H:%M:%S"`
echo "nginx in $DATE1 stop!">> /data/nginx/nginx_restart.log
sleep 10
`/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf`
DATE2=`date +"%Y-%m-%d/%H:%M:%S"`
echo "nginx in $DATE2 start!" >> /data/nginx/nginx_restart.log
else
`/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf`
fi
2、添加计划任务
#每周6,3点30分执行一次
crontab -e : 30 3 * * 6 sh /data/nginx/nginx_restart.sh
翻译
搜索
复制
标签:grep,file,重启,nginx,conf,定时,data,restart From: https://www.cnblogs.com/leihongnu/p/17836283.html