-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvsim
executable file
·173 lines (153 loc) · 4.25 KB
/
dvsim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
set -e
set -u
usage () {
echo "Usage:"
echo " $0 [build | clean | clone | copy | kill | pull | run]"
echo " copy:"
echo " all - copies all files of the form <node>_config.txt to respective nodes"
echo " [file] [node] - copies \$file to \$ node"
}
# Map of node names to ports
declare -A newmap
newmap[a]=34362
newmap[b]=34363
newmap[c]=34364
newmap[d]=34365
newmap[e]=34366
newmap[f]=34367
# All nodes
all_nodes="a b c d e f"
cmd=""
# Only for copying
copy_to_node=""
file_to_copy=""
copy_all=false
# Only for running
nodes_to_run=()
remote=geni
giturl="https://github.com/get9/dvsim.git"
project_dir=dvsim
if [[ $# == 0 ]]; then
usage
exit
fi
# Parse command line args
while [[ $# > 0 ]]; do
key="$1"
case $key in
clean|clone|build|kill|logcat|pull|run)
cmd="$key"
shift
while [[ $# > 0 ]]; do
nodes_to_run+=("$1")
shift
done
;;
copy)
echo "$@"
if [[ $# != 2 && $# != 3 ]]; then
echo "Usage:"
echo " $0 copy [all|<file> <nodename>]"
exit
fi
cmd="copy"
shift
if [[ "$1" == "all" ]]; then
copy_all=true
shift
else
file_to_copy="$1"
shift
copy_to_node="$1"
shift
fi
;;
*)
usage
exit
;;
esac
done
# If no nodes were passed for some commands, then default to all of them
if [[ ${#nodes_to_run[@]} == 0 ]]; then
nodes_to_run=${all_nodes}
fi
# Do things
case $cmd in
# Get source from $githuburl
clone)
echo "cloning on each node"
for node in ${nodes_to_run}; do
echo "${node}"
ssh $remote -p ${newmap[${node}]} "git clone ${giturl}"
done
;;
clean)
echo "cleaning on each node"
for node in ${nodes_to_run}; do
echo "${node}"
ssh $remote -p ${newmap[${node}]} "cd ${project_dir}; make clean"
done
;;
pull)
echo "updating each node"
for node in ${nodes_to_run}; do
echo "${node}"
ssh $remote -p ${newmap[${node}]} "cd ${project_dir}; git pull"
done
;;
kill)
echo "killing each node"
for node in ${nodes_to_run}; do
echo "${node}"
ssh $remote -p ${newmap[${node}]} "kill \$(pgrep mycode)" &
done
;;
# Build via make on all nodes
build)
echo "building on each node"
for node in ${nodes_to_run}; do
echo "${node}"
ssh $remote -p ${newmap[${node}]} "cd ${project_dir}; make debug"
done
;;
# Concatenate logs from each node to file on localhost
logcat)
echo "copying and concatenating logs from nodes to current host"
all_logs=$(pwd)/full_log.txt
for node in ${nodes_to_run}; do
echo "${node}"
n=${newmap[${node}]}
rsync -e "ssh -p ${n}" $remote:~/${project_dir}/log.txt ${node}_log.txt
printf '=%.s' {1..100} >> ${all_logs}
echo "" >> ${all_logs}
echo "${node} LOG" >> ${all_logs}
cat ${node}_log.txt >> ${all_logs}
echo "" >> ${all_logs}
done
;;
# Copy either all config files of the form ${node}_config.txt or copy specific file to given node
copy)
if [[ ${copy_all} == true ]]; then
for node in ${nodes_to_run}; do
echo "${node}_config.txt --> $node"
rsync -e "ssh -p ${newmap[${node}]}" "${node}_config.txt" $remote:~
done
else
n=${newmap[${copy_to_node}]}
rsync -e "ssh -p ${n}" ${file_to_copy} $remote:~/${copy_to_node}_config.txt
fi
;;
# Run on given nodes with existing config on server
run)
for n in ${nodes_to_run[@]}; do
ssh $remote -p ${newmap[${n}]} "ulimit -c unlimited; cd ${project_dir}; build/mycode ~/${n}_config.txt > log.txt 2>&1" &
done
;;
# Not a good command
*)
echo "Unrecognized command: ${cmd}"
exit
;;
esac