-
Notifications
You must be signed in to change notification settings - Fork 2
/
start_cluster.sh
executable file
·196 lines (161 loc) · 5.62 KB
/
start_cluster.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
# This script relies on docker to starts the RozoFS cluster based on the
# following containers:
# * rozofs-exportd (one by default)
# * rozofs-storaged (four by default)
# * rozofs-rozofsmount (optional)
set -e
if env | grep -q "DOCKER_ROZOFS_DEBUG"; then
set -x
fi
function start_exportd()
{
echo
echo ">>> Bringing up the exportd node:"
echo
name="rozofs-exportd"
docker run -P \
${LINK_ARG[@]} \
--name ${name} \
-d denaitre/rozofs-exportd > /dev/null 2>&1
#--privileged \
exportdIP=$(getIPbyContainerName "rozofs-exportd")
echo "Successfully brought up [rozofs-exportd]"
}
function restart_exportd()
{
# Reload new configuration file
docker exec rozofs-exportd exportd
killall exportd
#docker exec rozofs-exportd kill `cat /var/run/exportd.pid`
docker exec rozofs-exportd exportd
}
function getIPbyContainerName()
{
if local ip=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' $1);
then
echo "${ip}"
return 0
else
#>&2 echo "[X] Impossible to find IP address of $1"
return 1
fi
}
function usage()
{
echo "Usage: $1 options:"
echo " -d|--display - display the storage configuration"
echo " -h|--help - display this help"
echo " -l|--layout <{0,1,2}> - set the RozoFS layout"
echo " -s|--size <size> - set the number of storage nodes"
echo " -v|--volume <volume> - add a cluster in the selected <volume>"
exit 1
}
# fetch exportd IP address
exportdIP=$(getIPbyContainerName "rozofs-exportd")
OPTS=$(getopt -o dhl:s:v: -l display,help,layout:,size:,volume: -n $0 -- "$@")
if [ $? != 0 ]; then
exit 1
fi
eval set -- "$OPTS"
# extract options and their arguments into variables.
while true ; do
case "$1" in
-d|--display)
if [ ! -z ${exportdIP} ]; then
docker exec rozofs-exportd \
rozo volume list --exportd ${exportdIP};
fi
exit 0;;
-h|--help)
usage $0
break;;
-l|--layout)
DOCKER_ROZOFS_LAYOUT=$2;
shift 2;;
-s|--size)
DOCKER_ROZOFS_CLUSTER_SIZE=$2;
shift 2;;
-v|--volume)
DOCKER_ROZOFS_VID=$2;
shift 2;;
--) shift ; break ;;
esac
done
# Fetch or set future environment variables for containers
# * DOCKER_ROZOFS_CLUSTER_SIZE: the number of storage nodes in the cluster
# * DOCKER_ROZOFS_LAYOUT: the layout set
DOCKER_ROZOFS_CLUSTER_SIZE=${DOCKER_ROZOFS_CLUSTER_SIZE:=4}
DOCKER_ROZOFS_LAYOUT=${DOCKER_ROZOFS_LAYOUT:=0}
min_storage=$(( ${DOCKER_ROZOFS_LAYOUT}+1 * 4))
if (( ${DOCKER_ROZOFS_CLUSTER_SIZE} < ${min_storage} )); then
echo -E "At least ${min_storage} storage nodes are required \
for layout ${DOCKER_ROZOFS_LAYOUT}"
exit 1
fi
# Define bash arrays to keep records for future configuration
# * LINK_ARGS: keep name for inter-container link
# * STORAGED_IP_LIST: keep ip address for rozofs-exportd configuration
LINK_ARGS=()
STORAGED_IP_LIST=()
echo
echo ">>> Bringing up cluster storage nodes:"
echo
# Few IDs are defined next:
# * DOCKER_SID: the storaged container ID in docker
# * ROZOFS_SID: the storage ID in a rozofs cluster
# * ROZOFS_CID: the rozofs cluster ID
# if rozofs-storaged containers are defined, fetch the highest SID
declare -i highestDockerSID=0
if res=$(docker ps \
| grep rozofs-storaged.. \
| head -1 \
| sed 's/.*rozofs-storaged\(..\)/\1/g'); then
# 0x are considered as octal, we have to specify base 10:
highestDockerSID=10#${res}
fi
# Start rozofs-storaged containers
for ROZOFS_SID in $(eval echo "{1..${DOCKER_ROZOFS_CLUSTER_SIZE}}"); do
# DOCKER_SID != ROZOFS_SID
DOCKER_SID=$(printf %02g $(( ${ROZOFS_SID} + ${highestDockerSID} )) )
name="rozofs-storaged${DOCKER_SID}"
# CID is kept in order to retrieve containers IP address (or not...)
CID=$(docker run -P \
--name ${name} \
-d denaitre/rozofs-storaged )
# > /dev/null 2>&1)
# This array contains the list of 'link' parameters of each storaged
# container used for booting the exportd container
LINK_ARG+=("--link $name:$name")
STORAGED_IP_LIST+=("$(getIPbyContainerName ${name})")
echo "Successfully brought up [rozofs-storage${DOCKER_SID}]"
done
# If no rozofs-exportd container exists, create it!
if ! docker ps | grep rozofs-exportd >/dev/null; then
start_exportd
fi
echo
echo ">>> Adding rozofs-storaged containers in the cluster configuration"
echo
# stop exportd
#rozo node stop -r exportd -E ${exportdIP}
docker exec rozofs-exportd rozo node stop -r exportd -E localhost
#docker exec rozofs-exportd 'kill $(cat /var/run/exportd.pid)'
#docker exec rozofs-exportd 'kill $( < /var/run/exportd.pid)'
# Configure rozofs-exportd to add storaged containers in the cluster
# we use `rozo agent` to manage it easily
docker exec rozofs-exportd \
rozo volume expand ${STORAGED_IP_LIST[@]} \
--vid ${DOCKER_ROZOFS_VID} \
--layout ${DOCKER_ROZOFS_LAYOUT} \
--exportd localhost
# If a new volume is detected, export it !
if [ -z ${DOCKER_ROZOFS_VID} ]; then
numberExports=$(rozo export list -E $(getIPbyContainerName "rozofs-exportd") | grep "EXPORT " | wc -l)
docker exec rozofs-exportd \
rozo export create $(( ${numberExports} + 1 )) \
--exportd localhost
fi
docker exec rozofs-exportd exportd
echo "Successfully configure the storage volume"
echo