-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlocal-setup.sh
executable file
·129 lines (112 loc) · 2.97 KB
/
local-setup.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#
# - get the docker-machine name from commandline argument
# - in shell script, $0 is the program being invoked, and $1, $2.. are the actual arguments
#
MACHINE_NAME=$1
#
# - get the ip of target docker-machine
#
IP=$(docker-machine ip ${MACHINE_NAME})
#
# - run a single zookeeper broker
#
echo "start zookeeper"
#
# - get the running status of docker container named zookeeper
# - use > /dev/null to reduce the amount of logs
#
RUNNING=$(docker inspect --format="{{ .State.Running }}" zookeeper 2> /dev/null)
#
# - basic if else structure in shell script
#
if [[ $? -eq 1 ]]; then
#
# - cannot find docker container named zookeeper, create one
# - for docker run command options, see: https://docs.docker.com/engine/reference/run/
#
docker run \
-d \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
--name zookeeper \
confluent/zookeeper
elif [[ ${RUNNING} == "false" ]]; then
#
# - otherwise, container exists but not running, start it
#
docker start zookeeper
fi
sleep 2
#
# - run the kafka broker
#
echo "start kafka"
RUNNING=$(docker inspect --format="{{ .State.Running }}" kafka 2> /dev/null)
if [[ $? -eq 1 ]]; then
#
# - cannot find docker container named kafka, create one
# - for docker run command options, see: https://docs.docker.com/engine/reference/run/
#
# - here we explicitly configured Kafka advertised_host_name and advertised_port configuration
#
docker run \
-d \
-p 9092:9092 \
-e KAFKA_ADVERTISED_HOST_NAME="${IP}" \
-e KAFKA_ADVERTISED_PORT=9092 \
--name kafka \
--link zookeeper:zookeeper \
confluent/kafka
elif [[ ${RUNNING} == "false" ]]; then
#
# - otherwise, container exists but not running, start it
#
docker start kafka
fi
#
# - run the cassandra
#
echo "start cassandra"
RUNNING=$(docker inspect --format="{{ .State.Running }}" cassandra 2> /dev/null)
if [[ $? -eq 1 ]]; then
#
# - cannot find docker container named cassandra, create one
# - for docker run command options, see: https://docs.docker.com/engine/reference/run/
#
docker run \
-d \
-p 7199:7199 \
-p 9042:9042 \
-p 9160:9160 \
-p 7001:7001 \
--name cassandra \
cassandra:3.7
elif [[ ${RUNNING} == "false" ]]; then
#
# - otherwise, container exists but not running, start it
#
docker start cassandra
fi
#
# - run the redis
#
echo "start redis"
RUNNING=$(docker inspect --format="{{ .State.Running }}" redis 2> /dev/null)
if [[ $? -eq 1 ]]; then
#
# - cannot find docker container named redis, create one
# - for docker run command options, see: https://docs.docker.com/engine/reference/run/
#
docker run \
-d \
-p 6379:6379 \
--name redis \
redis:alpine
elif [[ ${RUNNING} == "false" ]]; then
#
# - otherwise, container exists but not running, start it
#
docker start redis
fi