restart.sh 563 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. app_dir=`pwd`
  3. app_name='devops-agent.jar'
  4. pid=`ps aux | grep ${app_name} | grep -v 'grep' | tr -s ' '| cut -d ' ' -f 2`
  5. echo "process id: "${pid}
  6. if [[ -z ${pid} ]];
  7. then
  8. echo "process killed"
  9. else
  10. kill -15 ${pid}
  11. fi
  12. echo "sleep 10s and wait process killed"
  13. sleep 10
  14. pid=`ps aux | grep ${app_name} | grep -v 'grep' | tr -s ' '| cut -d ' ' -f 2`
  15. if [[ -z ${pid} ]];
  16. then
  17. echo "${app_name} has killed, restart now"
  18. nohup java -jar ${app_dir}"/"${app_name} ${app_dir}/agent.json > console.log 2>&1 &
  19. else
  20. echo "process ${pid} not killed"
  21. fi