每天随机时间重启服务
crontab
# Restart ats in random time of every day to release swap. 0 2 * * * root /bin/sh /opt/soft/vcdn_tools/restart_ats.sh > /dev/null 2>&1
shell
#!/bin/bash # Author : 71standby@gmail.com # Date : 2018-03-02 # Description : Restart ats in random time of every day to release swap. function random_sleep() { randNum=$(($RANDOM%60)) echo "Now to sleep $randNum minutes..." >> "/data/ats/logs/swap_release.log" sleep $randNum"m" } function ats_statistics() { SUM=0 OVERALL=0 for PID in `ps -ef |grep traffic_ |grep -v grep |grep -v $0 |awk '{print $2}'` do # PROGNAME=`ps -p $PID -o comm --no-headers` DIR=/proc/$PID/smaps for SWAP in `grep Swap $DIR 2>/dev/null| awk '{ print $2 }'` do let SUM=$SUM+$SWAP done # echo "PID=$PID - Swap used: $SUM - ($PROGNAME)" let OVERALL=$OVERALL+$SUM SUM=0 done current=`date "+%Y-%m-%d %H:%M:%S"` echo $current >> "/data/ats/logs/swap_release.log" echo "ATS swap used: $OVERALL" >> "/data/ats/logs/swap_release.log" } echo "############## start ##############" >> "/data/ats/logs/swap_release.log" ats_statistics random_sleep systemctl restart ats 2>/dev/null || /etc/init.d/ats restart ats_statistics echo "############## end ##############" >> "/data/ats/logs/swap_release.log"
作者:Standby — 一生热爱名山大川、草原沙漠,还有我们小郭宝贝!
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。