-
Notifications
You must be signed in to change notification settings - Fork 0
/
nimby-check.sh
44 lines (38 loc) · 1.29 KB
/
nimby-check.sh
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
#!/bin/bash
TRACTOR_ENGINE_URL="animtractor"
# the script needs credentials for a user with wrangler permissions so that it can eject tasks
TRACTOR_WRANGLER_UN="wrangler"
TRACTOR_WRANGLER_PW=""
force_state=2
# Check if force argument given
if [[ "$#" -ne 0 ]]; then
if [[ "$1" == "on" ]]; then
force_state=0
elif [[ "$1" == "off" ]]; then
force_state=1
fi
fi
# Log in to animtractor
if [[ -z "$TRACTOR_WRANGLER_PW"]]; then # if password is empty
login=$(curl -s "${TRACTOR_ENGINE_URL}/Tractor/monitor?q=login&user=${TRACTOR_WRANGLER_UN}")
else
login=$(curl -s "${TRACTOR_ENGINE_URL}/Tractor/monitor?q=login&user=${TRACTOR_WRANGLER_UN}&c=${TRACTOR_WRANGLER_PW}")
fi
info=$(curl -s "127.0.0.1:9005/blade/status")
host=$(echo "$login" | jq -r .host)
hnm=$(echo "$info" | jq -r .hnm)
tsid=$(echo "$login" | jq -r .tsid)
## Check if NIMBY should be enabled
if [[ "$force_state" -ne 1 ]] \
&& [[ $(w -sh | wc -l) -ne 0 ]] \
|| [[ "$force_state" -eq 0 ]]; then
# Turn NIMBY on and eject existing tasks
echo "Turning NIMBY on"
curl -s "127.0.0.1:9005/blade/ctrl?nimby=1"
sleep 1
echo "Eject any running tasks"
curl -s "animtractor/Tractor/queue?q=ejectall&blade=${hnm}/${host}&tsid=${tsid}"
else
echo "Turning NIMBY off"
curl -s "127.0.0.1:9005/blade/ctrl?nimby=0"
fi