-
Notifications
You must be signed in to change notification settings - Fork 8
/
turn-down.sh
executable file
·57 lines (47 loc) · 941 Bytes
/
turn-down.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
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
function usage () {
cat <<HELP_USAGE
Usage: $0 -n <node> -t <timeout> -r
-n Name of the node
-t Time to recovery, if missing never recover
-r If set, recover with restarting
HELP_USAGE
}
node=""
timeout=-100
restart=false
while getopts ":n:t:r" opt; do
case $opt in
t) timeout=$OPTARG;;
r) restart=true;;
n) node=$OPTARG;;
\?) usage;exit 1;;
*) break ;;
esac
done
shift $((OPTIND -1))
if [ "$node" == "" ]; then
echo "-n <node> is missing"
usage
exit 1;
fi
echo "Pause $node..."
docker pause "$node"
secs=$(($timeout))
while [ $secs -gt 0 ]; do
# countdown on the same line
echo -ne "Resume $node in $secs s...\033[0K\r"
sleep 1
: $((secs--))
done
echo ""
if [ $secs == -100 ] ; then
exit 1
fi
if [ "$restart" = true ] ; then
echo "Restarting $node..."
docker restart "$node"
else
echo "Unpausing $node..."
docker unpause "$node"
fi