Mercurial > hg > cc > azure
comparison master/bin/wrun.sh @ 7:a7637c994964
cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
From kenneth, slight mods in some cases
share.sh:
Distribute files to workers
wrun.sh, invoke.sh:
From last year, slight mods
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Sun, 30 Sep 2018 20:53:43 +0000 |
parents | |
children | 55e953e5c66f |
comparison
equal
deleted
inserted
replaced
6:a3b30e707e83 | 7:a7637c994964 |
---|---|
1 #!/bin/bash | |
2 set -e -o pipefail | |
3 if [ $# -lt 2 ]; then | |
4 cat 1>&2 <<EOF | |
5 Usage: $0 SSname cmd [-x] [-np n] [-f file] [...args] | |
6 Where name is the name of a VM scale set. | |
7 | |
8 Runs cmd on every machine in a scale set, | |
9 passing args and, | |
10 if -f, one line from file per worker | |
11 unless -x, worker id | |
12 by doing as it were | |
13 [ echo line-from-file |] ssh machine "$cmd [id] "$args"" | |
14 EOF | |
15 exit 1 | |
16 fi | |
17 group=cc | |
18 name=$1 | |
19 cmd="$2" | |
20 shift 2 | |
21 if [ "$1" = "-x" ] | |
22 then | |
23 id=-x | |
24 shift | |
25 else | |
26 id= | |
27 fi | |
28 if [ "$1" = "-np" ] | |
29 then | |
30 np=$2 | |
31 shift | |
32 shift | |
33 else | |
34 np=$(az vmss get-instance-view -g $group -n $name | jq '.virtualMachine.statusesSummary | .[0].count') | |
35 fi | |
36 echo "|$name|$cmd|$@|$np|" 1>&2 | |
37 me=$(az vm list-ip-addresses -g cc -n Deb1 | jq -r '.[0].virtualMachine.network.publicIpAddresses|.[0].ipAddress') | |
38 echo me=$me 1>&2 | |
39 if [ "$1" = "-f" ] | |
40 then | |
41 file=$2 | |
42 shift 2 | |
43 tfile=$(mktemp) | |
44 split -n r/$np -u --filter="cat > $tfile\$\$" $file & | |
45 # Wait for fifos to be built | |
46 while [ $np -gt $(ls ${tfile}* | wc -l) ]; do echo -n . 1>&2; sleep 1; done | |
47 echo 1>&2 | |
48 wc -l ${tfile}* 1>&2 | |
49 else | |
50 file=/dev/null | |
51 fi | |
52 echo "|$np|$file|$tfile|" 1>&2 | |
53 paste -d ' ' \ | |
54 <(if [ "$file" = "/dev/null" ] | |
55 then yes /dev/null|head -$np | |
56 else | |
57 echo ${tfile}?* | tr ' ' '\012' # the name of the file of | |
58 # input lines for each worker | |
59 fi | |
60 ) \ | |
61 <(az vmss list-instance-connection-info -g $group -n $name | tr -s ',": ' '\t' | \ | |
62 tail -n +2 | head -$np |cut -f 3-5 | \ | |
63 while read i ip port | |
64 do | |
65 echo $i $port $ip | |
66 done) | \ | |
67 parallel --gnu --colsep ' ' -j $np "$(dirname "$0")"/internal/invoke.sh $id $me "$cmd" {} "$@" || { r=$? ; echo parallel exited with status=$r 1>&2;} | |
68 if [ "${tfile}" ]; then rm ${tfile}*; fi |