-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathredis.sh
executable file
·100 lines (81 loc) · 2.34 KB
/
redis.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
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
#!/bin/bash
provider=$1
cat << EOF > answers.conf
[general]
namespace = default
provider = $provider
[redismaster-app]
image = jasonbrooks/redis
hostport = 6379
[redisslave-app]
image = jasonbrooks/redis
master_hostport = 6379
hostport = 6379
EOF
ret=0
echo "Running projectatomic/redis-centos7-atomicapp"
atomicapp run --destination=./ projectatomic/redis-centos7-atomicapp
res=$?
if [ $res -gt $ret ]; then
ret=$res
fi
if [ $ret -eq 0 ]; then
if [ "$provider" = "docker" ]; then
total=0
docker ps | egrep "redis-master" | egrep -q " Up "
while [ $? -ne 0 -a $total -lt 120 ]; do
sleep 2
total=$((total+2))
docker ps | egrep "redis-master" | egrep -q " Up "
done
sleep 2
echo "Checking docker containers"
docker ps
docker ps | egrep "redis-master" | egrep -q " Up "
res=$?
if [ $res -gt $ret ]; then
ret=$res
fi
host="0.0.0.0"
port=`docker ps | egrep "redis-master" | sed -e "s/.*0.0.0.0://" -e "s/->.*//"`
elif [ "$provider" = "kubernetes" ]; then
total=0
while [ `kubectl get pods | egrep -c "^redis-(master|slave)-.*1/1\s+Running\s+"` -ne 3 -a $total -lt 120 ]; do
sleep 2
total=$((total+2))
done
echo "Checking kubernetes pod"
kubectl get pods
echo "Checking kubernetes services"
kubectl get services
count=`kubectl get pods | egrep -c "^redis-(master|slave)-.*1/1\s+Running\s+"`
if [ $count -ne 3 -a 1 -gt $ret ]; then
ret=$res
fi
host=`kubectl get services | egrep "^redis-master" | awk '{print $(NF-1)}'`
port=`kubectl get services | egrep "^redis-master" | awk '{print $NF}' | sed -e 's%/TCP%%'`
fi
times=0
redis-cli -h $host -p $port ping
while [ $? -ne 0 -a $times -lt 3 ]; do
times=$((times+1))
redis-cli -h $host -p $port ping
done
echo "Checking connectivity to master"
redis-cli -h $host -p $port get key
res=$?
if [ $res -gt $ret ]; then
ret=$res
fi
fi
echo "Stopping projectatomic/redis-centos7-atomicapp"
atomicapp stop ./
res=$?
if [ $res -gt $ret ]; then
ret=$res
fi
if [ "$provider" = "docker" ]; then
docker stop redis-master redis-slave
docker rm redis-master redis-slave
fi
exit $ret