inc_startsim.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. stopsim()
  2. {
  3. echo "checking for pid file: $PIDFILE"
  4. if [ -f $PIDFILE ]
  5. then
  6. running=`ps aux | grep $NAME | grep $(cat $PIDFILE) -c`
  7. if [ $running -eq 0 ]
  8. then
  9. echo Simulation not running
  10. else
  11. echo "Killing Simulation $(cat $PIDFILE)"
  12. kill $(cat $PIDFILE)
  13. echo stoped Simulation
  14. fi
  15. rm $PIDFILE
  16. fi
  17. true
  18. }
  19. stopsim_and_exit()
  20. {
  21. if [ $DATA_DIRECTORY ] && [ -d $DATA_DIRECTORY ];
  22. then
  23. PIDFILE=$DATA_DIRECTORY/$NAME.pid
  24. stopsim
  25. echo "exiting now."
  26. exit 0
  27. fi
  28. }
  29. set_default_data_dir()
  30. {
  31. i="0"
  32. while [ -d $DATA_DIR_BASE$i ]
  33. do
  34. i=$[$i+1]
  35. done
  36. DATA_DIRECTORY=$DATA_DIR_BASE$i
  37. echo "setting data directory to: $DATA_DIRECTORY"
  38. }
  39. create_datadirectory()
  40. {
  41. if [ ! $DATA_DIRECTORY ]
  42. then
  43. set_default_data_dir
  44. fi
  45. if [ ! -d $DATA_DIRECTORY ]
  46. then
  47. echo "create data directory: $DATA_DIRECTORY"
  48. mkdir -p $DATA_DIRECTORY
  49. fi
  50. ERROR=$?
  51. if [ $ERROR -ne "0" ]
  52. then
  53. exit 1
  54. fi
  55. }
  56. USAGE="Usage: `basename $0` [-h] [-d data_dir] args_forwarded_to_simulation"
  57. while [ ! $STOP ]
  58. do
  59. if [ $# -eq 0 ] || [[ "$1" =~ "--" ]]
  60. then
  61. STOP=true
  62. else
  63. echo "para=$1"
  64. case "$1" in
  65. "-d")
  66. DATA_DIRECTORY=$2
  67. echo "directory = $2"
  68. shift
  69. ;;
  70. "-h")
  71. echo $USAGE
  72. exit 0
  73. ;;
  74. "stop")
  75. STOP=true
  76. stopsim_and_exit
  77. ;;
  78. esac
  79. shift
  80. fi
  81. done
  82. create_datadirectory
  83. PIDFILE=$DATA_DIRECTORY/$NAME.pid
  84. stopsim
  85. SIM_PARAMETERS="--DataDirectory $DATA_DIRECTORY $*"
  86. nohup nice -10 ./$NAME $SIM_PARAMETERS >$DATA_DIRECTORY/simoutput.txt 2>$DATA_DIRECTORY/simerror.txt &
  87. echo $! > $PIDFILE
  88. echo started simulation with parameters: $SIM_PARAMETERS