定时重启jar,py的shell脚本
#>>>>>>>填写启动脚本名名py.sh <<<<<<<< jar_name="py.py" #获取当前目录 work_path=$(dirname $0) cd ${work_path} #拼接文件路径 path_file=$(pwd)"/monitor.log" #获取时间 time=$(date "+%Y-%m-%d %H:%M:%S") #判断文件是否存在 if [ ! -f "$path_file" ];then #不存在则创建文件 touch $path_file echo "${time} 初始化日志文件" >> $path_file fi apiID=$(ps -ef |grep $jar_name|grep -v 'grep'| awk '{print $2}') # 判断进程是否存在 if test $apiID ;then kill -9 $apiID; echo "${time} [INFO] 进程已关闭" >> $path_file nohup python $jar_name & echo "${time} [INFO] 进程重启成功" >> $path_file else nohup python $jar_name & echo "${time} [INFO] 进程已启动" >> $path_file fi