Changeset 138 for trunk/IPs/systemC/processor/Morpheo/Script/distexe.sh
- Timestamp:
- May 12, 2010, 7:34:01 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/IPs/systemC/processor/Morpheo/Script/distexe.sh
r128 r138 5 5 #----------------------------------------------------------- 6 6 7 declare VERSION="1.0" 8 declare -i SLEEP=3 9 10 # Need : test, echo, cd, dirname, basename, ssh, ps aux 7 #-----[ global variable ]----------------------------------- 8 declare VERSION="1.3" 9 declare -i SLEEP=2; 10 declare -i TRAP=0; 11 12 # Need : test, echo, cd, dirname, basename, ssh, ps aux, ls, wc, sed 13 # lock.sh, unlock.sh, date.sh, nb_cpu.sh, distexe_execute_n.sh, distexe_execute.sh 11 14 12 15 #-----[ distexe_usage ]------------------------------------- … … 23 26 echo " A line can content many shell command."; 24 27 echo " Don't forgot the final end of line (else the last command is not executed)"; 25 echo " example : "; 28 echo " * For each command, a directory (in work directory) is created : Task_X (X is the number of line in command file)."; 29 echo " The command is execute in this directory. (Warning, set your environment ! but we source .bashrc)."; 30 echo " Three file is generate :"; 31 echo " - \"distexe.info\" content information as host, pid ..."; 32 echo " - \"distexe.output\" is the output (standard and error) of the execution"; 33 echo " - \"distexe.command\" is the command launch."; 34 # echo " * A command empty (no command on a line of file) is a synchronisation with all process" 35 echo " * The environment variable DISTEXE_HOSTS list hosts to execute command"; 36 echo " After each host, a number is to the number of process. It's optionnal, the default value is the number of processor."; 37 echo " * All hosts must have network file systems (per example nfs or samba)"; 38 echo " Work directory must be in this network file systems !"; 39 echo ""; 40 echo "Example : "; 41 echo " # Create command file"; 26 42 echo ' echo "export PATH=${PATH}:${HOME}/my_appli/bin; my_appli 13" > command_file.txt'; 27 43 echo ' echo "export PATH=${PATH}:${HOME}/my_appli/bin; my_appli 21" >> command_file.txt'; 28 44 echo ' echo "export PATH=${PATH}:${HOME}/my_appli/bin; my_appli 7" >> command_file.txt'; 29 echo ' echo "" >> command_file.txt'; 30 echo " * For each command, a directory (in work directory) is created : Task_X (X is the number of line in command file)."; 31 echo " The command is execute in this directory. (Warning, set your environment !)."; 32 echo " Two file is generate : \"distexe.output\" is the output (standard and error) of the execution, and \"distexe.command\" is the command lunch."; 33 # echo " * A command empty (no command on a line of file) is a synchronisation with all process" 34 echo " * The environment variable DISTEXE_HOSTS list hosts to execute command"; 35 echo " After each host, a number is to the number of process. It's optionnal, the default value is the number of processor."; 36 echo " example :"; 45 echo ' echo "" >> command_file.txt'; 46 echo " # Set hosts list variable"; 37 47 echo ' export DISTEXE_HOSTS="localhost/1 nod/4 gdi/2"'; 38 echo " * All hosts must have network file systems (per example nfs or samba)";39 echo " Work directory must be in this network file systems !";40 echo ""; 48 echo " # Execute distexe"; 49 echo " ${0} command_file.txt;"; 50 41 51 exit; 42 }43 44 #-----[ my_date ]-------------------------------------------45 function my_date ()46 {47 date +"%F %T";48 52 } 49 53 … … 81 85 function header () 82 86 { 83 echo "distexe ${VERSION}"; 87 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> =========================================="; 88 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> distexe ${VERSION}"; 89 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> =========================================="; 90 } 91 92 #-----[ distexe_wait_end ]---------------------------------- 93 function distexe_wait_end() 94 { 95 while true; do 96 97 nb_file=$(ls -1 ${PREFIX_FILE_HOST}* 2>/dev/null| wc -l); 98 99 if test ${nb_file} -eq 0; then 100 break; 101 fi; 102 103 # wait (to not have 100% cpu) 104 sleep ${SLEEP}; 105 done; 106 107 rm -f ${FILE_CPT}; 108 }; 109 110 #-----[ distexe_no_trap ]----------------------------------- 111 function distexe_no_trap() 112 { 113 TRAP=1; 114 } 115 116 #-----[ distexe_trap ]-------------------------------------- 117 function distexe_trap() 118 { 119 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> Trap signal detected"; 120 # echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> !!!!!!!!!!!!!!!! Trap signal detected !!!!!!!!!!!!!!!!"; 121 122 local -a files_host=($(ls ${PREFIX_FILE_HOST}* 2>/dev/null)); 123 local -i nb_files_host=${#files_host[*]}; 124 125 if test ${nb_files_host} -ne 0; then 126 for file_host in ${files_host[*]}; do 127 128 local host=$(basename ${file_host} |sed s/$(basename ${PREFIX_FILE_HOST})//); 129 130 # ssh can not set yet pid in file_host 131 local -i nb_word=0; 132 while test ${nb_word} -eq 0; do 133 nb_word=$(echo ${file_host} |wc -m); 134 done; 135 136 ${MORPHEO_SCRIPT}/lock.sh ${LOCK_HOST}; 137 138 if test -f ${file_host}; then 139 local cmd="kill -s SIGINT $(cat ${file_host})"; 140 ssh ${host} ${cmd}; 141 fi; 142 143 ${MORPHEO_SCRIPT}/unlock.sh ${LOCK_HOST}; 144 done; 145 fi; 146 147 # echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> >>>>>>>>>>>>>>>> Trap signal detected >>>>>>>>>>>>>>>>"; 148 149 distexe_wait_end; 150 151 # echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> ################ Trap signal detected ################"; 152 153 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> an error occure"; 154 exit 1; 84 155 } 85 156 … … 87 158 function distexe () 88 159 { 160 trap distexe_no_trap INT TERM; 161 89 162 distexe_test_usage ${*}; 90 163 … … 104 177 fi; 105 178 106 local FILE_CPT="${PATH_EXE}/control-"$(basename ${FILE_CMD}); 107 179 local FILE_CPT="${PATH_EXE}/distexe-control-"$(basename ${FILE_CMD}); 180 local LOCK_HOST="${PATH_EXE}/distexe-host-lock"; 181 local PREFIX_FILE_HOST="${PATH_EXE}/distexe-host-"; 182 local PREFIX_FILE_PROCESS="${PATH_EXE}/distexe-process-"; 183 local hosts="${DISTEXE_HOSTS}"; 184 108 185 header; 109 186 110 echo " * {"$(my_date)"} <${HOSTNAME}> file : ${FILE_CMD}"; 111 echo " * {"$(my_date)"} <${HOSTNAME}> path : ${PATH_EXE}"; 112 echo " * {"$(my_date)"} <${HOSTNAME}> sleep : ${SLEEP}"; 113 114 local hosts="${DISTEXE_HOSTS}"; 115 local -a commands; 116 local -i cpt=0; 187 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> file : ${FILE_CMD}"; 188 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> path : ${PATH_EXE}"; 189 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> sleep : ${SLEEP}"; 190 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> hosts : ${hosts}"; 117 191 118 192 for line in ${hosts}; do … … 120 194 local -i nb_process=$(echo ${line} | cut -d/ -f2); 121 195 122 echo " * {"$(my_date)"} <${HOSTNAME}> station : ${host} (${nb_process}) ... ";123 124 196 # lunch service 125 local cmd="export MORPHEO_SCRIPT=${MORPHEO_SCRIPT};${MORPHEO_SCRIPT}/execute_n.sh ${PATH_EXE} ${FILE_CMD} ${FILE_CPT} ${nb_process};"; 126 ssh ${host} ${cmd} & 127 128 commands[${cpt}]="${cmd}"; 129 cpt=$((${cpt}+1)); 197 local FILE_HOST=${PREFIX_FILE_HOST}'${HOSTNAME}'; 198 199 local valid=$(ssh ${host} "if test -f ${FILE_HOST}; then echo \"ko\"; else touch ${FILE_HOST}; echo \"ok\"; fi"); 200 201 if test ${valid} = "ok"; then 202 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> station : ${host} (${nb_process} process(es))"; 203 204 local cmd="export MORPHEO_SCRIPT=${MORPHEO_SCRIPT};. ${MORPHEO_SCRIPT}/distexe_execute_n.sh ${PATH_EXE} ${FILE_CMD} ${FILE_CPT} ${FILE_HOST} ${LOCK_HOST} ${PREFIX_FILE_PROCESS} ${SLEEP} ${nb_process};"; 205 206 ssh ${host} ${cmd} & 207 else 208 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> station \"${host}\" is already used"; 209 fi; 130 210 done; 131 211 132 echo " * {"$(my_date)"} <${HOSTNAME}> all hosts working"; 133 134 cpt=0; 135 while test ${cpt} -lt ${#commands[*]}; do 136 local -i res=1 137 138 while true; do 139 res=$(ps aux | grep -c "${commands[${cpt}]}"); 140 141 if test ${res} -eq 0; then 142 break; 143 fi; 144 145 # wait (to not have 100% cpu) 146 sleep ${SLEEP}; 147 done 148 149 cpt=$((${cpt}+1)); 150 done; 151 152 echo " * {"$(my_date)"} <${HOSTNAME}> all hosts is done"; 153 rm ${FILE_CPT}; 212 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> all hosts working"; 213 214 trap distexe_trap INT TERM; 215 216 if test ${TRAP} -eq 1; then 217 distexe_trap; 218 fi; 219 220 # Wait end ok all Task 221 distexe_wait_end; 222 223 echo " * {"$(${MORPHEO_SCRIPT}/date.sh)"} <${HOSTNAME}> all hosts is done"; 154 224 } 155 225
Note: See TracChangeset
for help on using the changeset viewer.