因公司业务需要,写了个定时重启功能:
重启脚本:restart.sh
#!/bin/bash if [ -f ~/.bash_profile ]; then . ~/.bash_profile fi c1=${0} c2=`dirname $c1` cd "$c2" for i in `ls -t etsv5-*.jar` do #echo $i break done echo "kill ${i}" pid=`ps aux | grep -i $i |grep java | grep -v grep | awk '{print $2}'` if [ -z "$pid" ] ; then echo "No process running." exit -1; fi echo "The process(${pid}) is running..." kill ${pid} echo "Send shutdown request to process(${pid}) OK" sleep 3s echo start $i nohup java -jar $i &
然后定时crontab 计划任务:
命令:
service crond start 启动服务
service crond stop关闭服务
service crond restart重启服务
service crond reload重新载入配置
service crond status查看crontab服务状态
配置crontab:
crontab -e 编辑
crontab -l 任务列表
crontab -r 清除所有任务
新增任务:
0 03 * * * /u06/etsuser/etsv6.0.0/app/etsv5-db-cacher/21-001/restart.sh原文链接:https://www.f2er.com/centos/381825.html