1
0

uav_proc_watcher.sh 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh
  2. source /etc/profile
  3. process_flag=$1
  4. working_directory=$2
  5. start_command=$3
  6. now=$(date "+%Y-%m-%d %H:%M:%S")
  7. # max log file count
  8. log_file_max=30
  9. # interval of run
  10. step=15
  11. if [[ "$4" -ge 5 && "$4" -le 60 ]]; then
  12. step=$4
  13. fi
  14. for(( i = 0; i < 60; i=(i+step) )); do
  15. # judge process running
  16. count=`ps -fC java | grep $process_flag | wc -l`
  17. if [ $count -eq 0 ]; then
  18. # log
  19. echo "$now $process_flag restart by $start_command">>$working_directory/$(date "+%Y-%m-%d")_restart.out
  20. # start
  21. cd $working_directory
  22. nohup $start_command 1>/dev/null 2>&1 &
  23. # clear log file
  24. if [ $(find $working_directory -name "*_restart.out" | wc -l) -gt $log_file_max ]; then
  25. rm -rf $(ls $working_directory/*_restart.out|head -n1)
  26. fi
  27. fi
  28. #
  29. if [ $step -ge 60 ];then
  30. exit 0
  31. else
  32. sleep $step
  33. fi
  34. done