Linux重启进程脚本

Linux重启进程脚本

#!/bin/bash
script_dir="/home/dev/supplier/script"
logDir="/home/dev/supplier/logs"
cd $script_dir
for file in `ls *.sh`
do
    echo ${file%.sh}
    if  [[ $file =~ "rollback" ]] || [[ $file =~ "restart_all" ]] || [[ $file =~ "clean" ]] ;then
        echo "skip $file"
    else
                process=`ps aux|grep "service=${file%.sh}"|grep -v grep|awk '{print$2}'`
                if [ ! $process ]; then
                 echo "No Porcess To Kill!"
                else
                 echo "kill -9 $process"      
                 kill -9 $process
                 sleep 10
                fi
                echo "Restart $script_dir/$file"
                nohup $script_dir/$file > $logDir/${file%.sh}.out 2>&1 &
                echo "Restart $file Done."
        fi
done

 

1.排除掉指定脚本

2.通过启动路径中的关键字查找进程编号

3.停止进程

4.通过nohup启动

留下回复