2014-01-21 21:53:37 +01:00
|
|
|
#!/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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
if [[ $# -lt 1 || $# -gt 2 ]]; then
|
2014-01-21 21:53:37 +01:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
function get_status {
|
2015-09-26 03:47:30 +02:00
|
|
|
if (ssh "zulip@$1.zulip.net" '[ -d "'"$lockdir"'" ]'); then
|
2014-01-21 21:53:37 +01:00
|
|
|
printf "%-10s %b" "$1" "is currently \e[31mlocked\e[0m\n"
|
|
|
|
else
|
|
|
|
printf "%-10s %b" "$1" "is currently \e[32munlocked\e[0m\n"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
if [[ "$1" == "lock" ]]; then
|
2014-01-21 21:53:37 +01:00
|
|
|
verb="mkdir"
|
2015-09-26 03:47:30 +02:00
|
|
|
elif [[ "$1" == "unlock" ]]; then
|
2014-01-21 21:53:37 +01:00
|
|
|
verb="rmdir"
|
2015-09-26 03:47:30 +02:00
|
|
|
elif [[ $# == 1 && "$1" == "status" ]]; then
|
2014-01-21 21:53:37 +01:00
|
|
|
get_status "staging"
|
|
|
|
get_status "prod0"
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
if [[ "$2" == "staging" ]]; then
|
2014-01-21 21:53:37 +01:00
|
|
|
ssh zulip@staging.zulip.net "$verb $lockdir"
|
|
|
|
get_status "staging"
|
|
|
|
exit
|
2015-09-26 03:47:30 +02:00
|
|
|
elif [[ "$2" == "prod" ]]; then
|
2014-01-21 21:53:37 +01:00
|
|
|
ssh zulip@prod0.zulip.net "$verb $lockdir"
|
|
|
|
get_status "prod0"
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|