annotate master/bin/wrun.sh @ 9:55e953e5c66f

wrun.sh, invoke.sh: add control of use of nohup, with -i(mmediately) and -w(ait) respectively wrun.sh: add support for fixed file input via -ff, handle -ff - in obvious way wbash.sh: use -ff - and -i to execute shell commands on all workers
author Henry S. Thompson <ht@markup.co.uk>
date Tue, 02 Oct 2018 10:52:45 +0000
parents a7637c994964
children 2fbefb8d1a9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
1 #!/bin/bash
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
2 set -e -o pipefail
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
3 if [ $# -lt 2 ]; then
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
4 cat 1>&2 <<EOF
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
5 Usage: $0 SSname cmd [-x] [-np n] [-f[f] file] [-i] [...args]
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
6 Where name is the name of a VM scale set.
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
8 Runs cmd on every machine in a scale set,
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
9 passing args and,
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
10 if -f, lines from file split per worker
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
11 if -ff, complete file sent to all workers
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
12 unless -x, worker id
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
13 by doing as it were
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
14 [ echo line(s)-from-file |] ssh machine "$cmd [id] "$args""
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
15 if -i, don\'t use nohup on the workers so returns immediately
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
16 [default is to use nohup unless neither -f or -ff]
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
17 EOF
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
18 exit 1
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
19 fi
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
20 group=cc
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
21 name=$1
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
22 cmd="$2"
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
23 shift 2
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
24 if [ "$1" = "-x" ]
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
25 then
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
26 id=-x
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
27 shift
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
28 else
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
29 id=
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
30 fi
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
31 if [ "$1" = "-np" ]
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
32 then
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
33 np=$2
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
34 shift
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
35 shift
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
36 else
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
37 np=$(az vmss get-instance-view -g $group -n $name | jq '.virtualMachine.statusesSummary | .[0].count')
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
38 fi
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
39 echo "|$name|$cmd|$@|$np|" 1>&2
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
40 me=$(az vm list-ip-addresses -g cc -n Deb1 | jq -r '.[0].virtualMachine.network.publicIpAddresses|.[0].ipAddress')
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
41 echo me=$me 1>&2
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
42 wait='-w'
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
43 if [ "$1" = "-f" ]
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
44 then
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
45 file=$2
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
46 shift 2
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
47 tfile=$(mktemp)
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
48 split -n r/$np -u --filter="cat > $tfile\$\$" $file &
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
49 # Wait for files to be built
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
50 while [ $np -gt $(ls ${tfile}* | wc -l) ]; do echo -n . 1>&2; sleep 1; done
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
51 echo 1>&2
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
52 wc -l ${tfile}* 1>&2
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
53 elif [ "$1" = "-ff" ]
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
54 then
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
55 file=$2
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
56 shift 2
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
57 if [ "$file" = "-" ]
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
58 then
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
59 file=$(mktemp)
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
60 cat > $file
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
61 fi
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
62 else
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
63 file=/dev/null
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
64 wait=''
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
65 fi
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
66 if [ "$1" = "-i" ]
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
67 then
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
68 shift
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
69 wait=''
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
70 fi
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
71 echo "|$np|$file|$tfile|$wait|" 1>&2
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
72 paste -d ' ' \
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
73 <(if [ -z "$tfile" ]
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
74 then yes $file|head -$np
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
75 else
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
76 echo ${tfile}?* | tr ' ' '\012' # the name of the file of
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
77 # input lines for each worker
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
78 fi
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
79 ) \
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
80 <(az vmss list-instance-connection-info -g $group -n $name | tr -s ',": ' '\t' | \
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
81 tail -n +2 | head -$np |cut -f 3-5 | \
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
82 while read i ip port
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
83 do
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
84 echo $i $port $ip
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
85 done) | \
9
55e953e5c66f wrun.sh, invoke.sh:
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
86 parallel --gnu --colsep ' ' -j $np "$(dirname "$0")"/internal/invoke.sh $wait $id $me "$cmd" {} "$@" || { r=$? ; echo parallel exited with status=$r 1>&2;}
7
a7637c994964 cull_network.py, parse_load_balance.py, vmss_setup.sh x 2, vmss_create.sh:
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
87 if [ "${tfile}" ]; then rm ${tfile}*; fi