-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathgat-cli
executable file
·335 lines (298 loc) · 7.51 KB
/
gat-cli
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
# shellcheck disable=SC2207,SC2155
search_dir() {
q="$(find -name $1 -type d 2>/dev/null| wc -l)"
if (( q > 0 )); then
echo 1
else
echo 0
fi
}
dir_exists() {
if [[ -d "$1" ]]; then
echo 1
else
echo 0
fi
}
path_exists() {
if [[ -f "$1" ]]; then
echo 1
else
echo 0
fi
}
# Grep through user's files in their home directory for some string.
str_exists() {
location="${2:-*}"
q="$(grep "$1" -Ri $location 2>/dev/null| wc -l)"
if (( q > 0 )); then
echo 1
else
echo 0
fi
}
service_state() {
q=$(timeout 3 systemctl status "$1" 2>/dev/null | grep Active | awk '{print $2}')
if [[ "$q" == "" ]]; then
echo 0
else
echo 1
fi
}
db_exists() {
q=$(timeout 3 sudo -u postgres psql -l 2>/dev/null| grep "$1" | wc -l)
if (( q > 0 )); then
echo 1
else
echo 0
fi
}
curl_responds() {
q=$(timeout 3 curl --silent -k "$1" 2>/dev/null| wc -c)
if (( q > 0 )); then
echo 1
else
echo 0
fi
}
cmd_exists() {
if ! command -v "$1" &> /dev/null; then
echo 0
else
echo 1
fi
}
prettify() {
cat | sed 's/1/✔ /g;s/0/✘ /g;s/2/✅/g'
}
unified-progress() {
x=$(cat)
# Are there any zeros
if [[ "$x" == *"0"* ]]; then
# If there are any ones
if [[ "$x" == *"1"* ]]; then
# Mixed
echo 2
else
# Otherwise it's only zeros
echo 0
fi
else
echo 1
fi
}
_status-singularity() {
local -a r=()
r[0]=$(cmd_exists singularity)
echo "${r[@]}"
}
_status-ephemeris() {
local -a r=()
r[0]=$(dir_exists ~/ephemeris_venv)
echo "${r[@]}"
}
_status-datalibs() {
local -a r=()
r[0]=$(dir_exists /libraries/)
echo "${r[@]}"
}
_status-cluster() {
local -a r=()
r[0]=$(service_state munge)
r[1]=$(service_state slurmd)
r[2]=$(service_state slurmctld)
r[3]=$(str_exists slurm-drmaa1)
r[4]=$(str_exists DRMAA_LIBRARY_PATH)
echo "${r[@]}"
}
_status-mapping() {
local -a r=()
r[0]=$(str_exists cpus-per-task=2)
r[1]=$(str_exists dynamic_admin_only)
r[2]=$(str_exists 'upper_bound')
r[3]=$(str_exists '<resources>')
echo "${r[@]}"
}
_status-metrics() {
local -a r=()
r[0]=$(str_exists job_metrics_conf.xml.j2)
echo "${r[@]}"
}
_status-storage() {
local -a r=()
r[0]=$(str_exists object_store_config_file)
r[1]=$(str_exists atosatto.minio)
r[2]=$(str_exists dropbox)
echo "${r[@]}"
}
_status-gxadmin() {
local -a r=()
r[0]=$(str_exists usegalaxy_eu.gxadmin)
r[1]=$(cmd_exists gxadmin)
echo "${r[@]}"
}
_status-monitoring() {
local -a r=()
r[0]=$(service_state influxdb)
r[1]=$(service_state grafana-server)
r[2]=$(service_state telegraf)
echo "${r[@]}"
}
_status-gxit() {
local -a r=()
r[0]=$(service_state galaxy-gie-proxy)
echo "${r[@]}"
}
_status-tiaas() {
local -a r=()
r[0]=$(service_state tiaas)
echo "${r[@]}"
}
gat_status() { # [Admin] Get an overview of ALL tutorials not just one.
# day 1
local ansible=$(_status-ansible | unified-progress)
local galaxy=$(_status-galaxy | unified-progress)
# day 2
local singularity=$(_status-singularity | unified-progress)
local ephemeris=$(_status-ephemeris | unified-progress)
local cvmfs=$(_status-cvmfs | unified-progress)
local datalibs=$(_status-datalibs | unified-progress)
# day 3
local cluster=$(_status-cluster | unified-progress)
local mapping=$(_status-mapping | unified-progress)
local metrics=$(_status-metrics | unified-progress)
# day 4
local pulsar=$(_status-pulsar | unified-progress)
local storage=$(_status-storage | unified-progress)
local gxadmin=$(_status-gxadmin | unified-progress)
local monitoring=$(_status-monitoring | unified-progress)
# day 5
local gxit=$(_status-gxit)
local tiaas=$(_status-tiaas)
echo -n "$(hostname -f | cut -d. -f1-2) "
echo "M $ansible$galaxy T $singularity$ephemeris$cvmfs$datalibs W $cluster$mapping$metrics R $pulsar$storage$gxadmin$monitoring F $gxit$tiaas" | prettify
}
gat_status-raw() {
# day 1
local ansible=$(_status-ansible)
local galaxy=$(_status-galaxy)
# day 2
local singularity=$(_status-singularity)
local ephemeris=$(_status-ephemeris)
local cvmfs=$(_status-cvmfs)
local datalibs=$(_status-datalibs)
# day 3
local cluster=$(_status-cluster)
local mapping=$(_status-mapping)
local metrics=$(_status-metrics)
# day 4
local pulsar=$(_status-pulsar)
local storage=$(_status-storage)
local gxadmin=$(_status-gxadmin)
local monitoring=$(_status-monitoring)
# day 5
local gxit=$(_status-gxit)
local tiaas=$(_status-tiaas)
echo -n "$(hostname -f | cut -d. -f1-2) "
echo "M|$ansible|$galaxy T|$singularity|$ephemeris|$cvmfs|$datalibs W|$cluster|$mapping|$metrics R|$pulsar|$storage|$gxadmin|$monitoring F|$gxit|$tiaas"
}
gat_status-sum() {
# day 1
local ansible=$(_status-ansible)
local galaxy=$(_status-galaxy)
# day 2
local singularity=$(_status-singularity)
local ephemeris=$(_status-ephemeris)
local cvmfs=$(_status-cvmfs)
local datalibs=$(_status-datalibs)
# day 3
local cluster=$(_status-cluster)
local mapping=$(_status-mapping)
local metrics=$(_status-metrics)
# day 4
local pulsar=$(_status-pulsar)
local storage=$(_status-storage)
local gxadmin=$(_status-gxadmin)
local monitoring=$(_status-monitoring)
# day 5
local gxit=$(_status-gxit)
local tiaas=$(_status-tiaas)
echo -n "$(hostname -f | cut -d. -f1-2) "
echo "$ansible $galaxy $singularity $ephemeris $cvmfs $datalibs $cluster $mapping $metrics $pulsar $storage $gxadmin $monitoring $gxit $tiaas" | sed 's/ / + /g' | bc
}
_status-ansible() {
local -a r=()
r[0]=$(str_exists 'Copy a file to the' .)
if [[ "${r[0]}" == "0" ]]; then
# Maybe they typo'd it? Test the output file.
r[0]=$(path_exists /tmp/test.txt)
fi
r[1]=$(str_exists '^server_name:')
r[2]=$(search_dir geerlingguy.memcached)
r[3]=$(search_dir secret_group_vars)
echo "${r[@]}"
}
gat_status-ansible() { # [Admin] Check status of ansible training
local -a r=($(_status-ansible | prettify))
echo "$(hostname) basic ${r[0]} template ${r[1]} roles ${r[2]} secrets ${r[3]}"
}
_status-galaxy() {
local -a r=()
r[0]=$(service_state postgresql)
r[1]=$(db_exists galaxy)
# So this check works, then later reverts. Just disable it. It's more confusing than useful.
#r[2]=$(curl_responds http://localhost:8080/api/version)
r[2]=$(service_state galaxy)
r[3]=$(service_state nginx)
r[4]=$(curl_responds https://localhost:443/api/version)
echo "${r[@]}"
}
gat_status-galaxy() { # [Admin] Check status of ansible-galaxy training
local -a r=($(_status-galaxy | prettify))
echo "$(hostname) postgres ${r[0]} ${r[1]} SysD-gxy ${r[3]} SysD-nginx ${r[4]} galaxy(ssl) ${r[5]}"
}
_status-cvmfs() {
local -a r=()
r[0]=$(search_dir galaxyproject.cvmfs)
r[1]=$(dir_exists /cvmfs/)
r[2]=$(str_exists /cvmfs/data.galaxyproject.org/managed/location/tool_data_table_conf.xml)
echo "${r[@]}"
}
gat_status-cvmfs() { # [Admin] Check status of cvmfs training
local -a r=($(_status-cvmfs | prettify))
echo "$(hostname) reqs ${r[0]} /cvmfs/ ${r[1]} gxconf ${r[2]}"
}
_status-pulsar() {
local -a r=()
r[0]=$(search_dir galaxyproject.pulsar)
r[1]=$(str_exists private_token) # group var
r[2]=$(str_exists libcurl4-openssl-dev)
r[3]=$(str_exists PulsarRESTJobRunner)
echo "${r[@]}"
}
gat_status-pulsar() { # [Admin] Check status of pulsar training
local -a r=($(_status-pulsar | prettify))
echo "$(hostname) reqs ${r[0]} groupvars ${r[1]} playbook ${r[2]} jobconf ${r[3]}"
}
usage() {
echo "Galaxy Admin Training (gat) tool:"
echo
grep '^gat_.*()\s*{\s*# ' $0 | sed "s/gat_/ gat /g;s/().*#/\t/;"
echo
exit 1;
}
cmd="$1"; shift;
if [[ "$cmd" == "" ]]; then
usage
else
# Check that FN exists
LC_ALL=C type "gat_$cmd" 2> /dev/null | grep -q 'function'
ec=$?
# If missing, exit with help
if (( ec != 0 )); then
echo "Unknown command!"
usage
fi
gat_$cmd $@
fi