forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeployment-lock-ctl
executable file
·53 lines (43 loc) · 1.07 KB
/
deployment-lock-ctl
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
#!/bin/bash
command="$0"
lockdir="deployments/lock"
function usage {
echo "$command <command> [target]
Manages the lock state of staging and prod deployments.
lock target locks a logical target
unlock target unlocks a logical target
status shows the deployment lock state on various hosts"
exit 1
}
if [[ $# -lt 1 || $# -gt 2 ]]; then
usage
fi
function get_status {
if (ssh "zulip@$1.zulip.net" '[ -d "'"$lockdir"'" ]'); then
printf "%-10s %b" "$1" "is currently \e[31mlocked\e[0m\n"
else
printf "%-10s %b" "$1" "is currently \e[32munlocked\e[0m\n"
fi
}
if [[ "$1" == "lock" ]]; then
verb="mkdir"
elif [[ "$1" == "unlock" ]]; then
verb="rmdir"
elif [[ $# == 1 && "$1" == "status" ]]; then
get_status "staging"
get_status "prod0"
exit
else
usage
fi
if [[ "$2" == "staging" ]]; then
ssh [email protected] "$verb $lockdir"
get_status "staging"
exit
elif [[ "$2" == "prod" ]]; then
ssh [email protected] "$verb $lockdir"
get_status "prod0"
exit
else
usage
fi