forked from ceph/ceph-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.sh
executable file
·405 lines (338 loc) · 11 KB
/
demo.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/bash
set -e
unset "DAEMON_OPTS[${#DAEMON_OPTS[@]}-1]" # remove the last element of the array
OSD_ID=0
: "${OSD_PATH:=/var/lib/ceph/osd/${CLUSTER}-$OSD_ID}"
# the following ceph version can start with a numerical value where the new ones need a proper name
if [[ "$CEPH_VERSION" == "luminous" ]]; then
MDS_NAME=0
else
MDS_NAME=demo
fi
MDS_PATH="/var/lib/ceph/mds/${CLUSTER}-$MDS_NAME"
RGW_PATH="/var/lib/ceph/radosgw/${CLUSTER}-rgw.${RGW_NAME}"
# shellcheck disable=SC2153
MGR_PATH="/var/lib/ceph/mgr/${CLUSTER}-$MGR_NAME"
RESTAPI_IP=$MON_IP
MGR_IP=$MON_IP
: "${DEMO_DAEMONS:=all}"
: "${RGW_ENABLE_USAGE_LOG:=true}"
: "${RGW_USAGE_MAX_USER_SHARDS:=1}"
: "${RGW_USAGE_MAX_SHARDS:=32}"
: "${RGW_USAGE_LOG_FLUSH_THRESHOLD:=1}"
: "${RGW_USAGE_LOG_TICK_INTERVAL:=1}"
: "${EXPOSED_IP:=127.0.0.1}"
: "${SREE_PORT:=5000}"
# rgw options
: "${RGW_CIVETWEB_IP:=0.0.0.0}"
: "${RGW_CIVETWEB_PORT:=8080}"
: "${RGW_FRONTEND_IP:=$RGW_CIVETWEB_IP}"
: "${RGW_FRONTEND_PORT:=$RGW_CIVETWEB_PORT}"
: "${RGW_FRONTEND_TYPE:="civetweb"}"
: "${RBD_POOL:="rbd"}"
RGW_CIVETWEB_OPTIONS="$RGW_CIVETWEB_OPTIONS port=$RGW_CIVETWEB_IP:$RGW_CIVETWEB_PORT"
RGW_BEAST_OPTIONS="$RGW_BEAST_OPTIONS endpoint=$RGW_FRONTEND_IP:$RGW_FRONTEND_PORT"
if [[ "$RGW_FRONTEND_TYPE" == "civetweb" ]]; then
RGW_FRONTED_OPTIONS="$RGW_CIVETWEB_OPTIONS"
elif [[ "$RGW_FRONTEND_TYPE" == "beast" ]]; then
RGW_FRONTED_OPTIONS="$RGW_BEAST_OPTIONS"
else
log "ERROR: unsupported rgw backend type $RGW_FRONTEND_TYPE"
exit 1
fi
: "${RGW_FRONTEND:="$RGW_FRONTEND_TYPE $RGW_FRONTED_OPTIONS"}"
if [[ "$RGW_FRONTEND_TYPE" == "beast" ]]; then
if [[ "$CEPH_VERSION" == "luminous" ]]; then
RGW_FRONTEND_TYPE=beast
log "ERROR: unsupported rgw backend type $RGW_FRONTEND_TYPE for your Ceph release $CEPH_VERSION, use at least the Mimic version."
exit 1
fi
fi
#######
# MON #
#######
function bootstrap_mon {
# shellcheck disable=SC1091
source start_mon.sh
start_mon
chown --verbose ceph. /etc/ceph/*
}
#######
# OSD #
#######
function parse_size {
# Taken from https://stackoverflow.com/questions/17615881/simplest-method-to-convert-file-size-with-suffix-to-bytes
local SUFFIXES=('' K M G T P E Z Y)
local MULTIPLIER=1
shopt -s nocasematch
for SUFFIX in "${SUFFIXES[@]}"; do
local REGEX="^([0-9]+)(${SUFFIX}i?B?)?\$"
if [[ $1 =~ $REGEX ]]; then
echo $((BASH_REMATCH[1] * MULTIPLIER))
return 0
fi
((MULTIPLIER *= 1024))
done
echo "$0: invalid size \`$1'" >&2
return 1
}
function bootstrap_osd {
if [[ -n "$OSD_DEVICE" ]]; then
if [[ -b "$OSD_DEVICE" ]]; then
if [ -n "$BLUESTORE_BLOCK_SIZE" ]; then
size=$(parse_size "$BLUESTORE_BLOCK_SIZE")
if ! grep -qE "bluestore_block_size = $size" /etc/ceph/"${CLUSTER}".conf; then
echo "bluestore_block_size = $size" >> /etc/ceph/"${CLUSTER}".conf
fi
fi
else
log "Invalid $OSD_DEVICE, only block device is supported"
exit 1
fi
fi
if [ ! -e "$OSD_PATH"/keyring ]; then
if ! grep -qE "osd data = $OSD_PATH" /etc/ceph/"${CLUSTER}".conf; then
echo "osd data = $OSD_PATH" >> /etc/ceph/"${CLUSTER}".conf
echo "osd objectstore = bluestore" >> /etc/ceph/"${CLUSTER}".conf
fi
# bootstrap OSD
mkdir -p "$OSD_PATH"
chown --verbose -R ceph. "$OSD_PATH"
# if $OSD_DEVICE exists we deploy with ceph-volume
if [[ -n "$OSD_DEVICE" ]]; then
ceph-volume lvm prepare --data "$OSD_DEVICE"
else
# we go for a 'manual' bootstrap
ceph "${CLI_OPTS[@]}" auth get-or-create osd."$OSD_ID" mon 'allow profile osd' osd 'allow *' mgr 'allow profile osd' -o "$OSD_PATH"/keyring
ceph-osd --conf /etc/ceph/"${CLUSTER}".conf --osd-data "$OSD_PATH" --mkfs -i "$OSD_ID"
fi
fi
# activate OSD
if [[ -n "$OSD_DEVICE" ]]; then
OSD_FSID="$(ceph-volume lvm list --format json | python -c "import sys, json; print(json.load(sys.stdin)[\"$OSD_ID\"][0][\"tags\"][\"ceph.osd_fsid\"])")"
ceph-volume lvm activate --no-systemd --bluestore "${OSD_ID}" "${OSD_FSID}"
fi
# start OSD
chown --verbose -R ceph. "$OSD_PATH"
ceph-osd "${DAEMON_OPTS[@]}" -i "$OSD_ID"
ceph "${CLI_OPTS[@]}" osd pool create "$RBD_POOL" 8
}
#######
# MDS #
#######
function bootstrap_mds {
if [ ! -e "$MDS_PATH"/keyring ]; then
# create ceph filesystem
ceph "${CLI_OPTS[@]}" osd pool create cephfs_data 8
ceph "${CLI_OPTS[@]}" osd pool create cephfs_metadata 8
ceph "${CLI_OPTS[@]}" fs new cephfs cephfs_metadata cephfs_data
# bootstrap MDS
mkdir -p "$MDS_PATH"
ceph "${CLI_OPTS[@]}" auth get-or-create mds."$MDS_NAME" mds 'allow' osd 'allow *' mon 'allow profile mds' -o "$MDS_PATH"/keyring
chown --verbose -R ceph. "$MDS_PATH"
fi
# start MDS
ceph-mds "${DAEMON_OPTS[@]}" -i "$MDS_NAME"
}
#######
# RGW #
#######
function bootstrap_rgw {
if [ ! -e "$RGW_PATH"/keyring ]; then
# bootstrap RGW
mkdir -p "$RGW_PATH" /var/log/ceph
ceph "${CLI_OPTS[@]}" auth get-or-create client.rgw."${RGW_NAME}" osd 'allow rwx' mon 'allow rw' -o "$RGW_KEYRING"
chown --verbose -R ceph. "$RGW_PATH"
#configure rgw dns name
cat <<ENDHERE >>/etc/ceph/"${CLUSTER}".conf
[client.rgw.${RGW_NAME}]
rgw dns name = ${RGW_NAME}
rgw enable usage log = ${RGW_ENABLE_USAGE_LOG}
rgw usage log tick interval = ${RGW_USAGE_LOG_TICK_INTERVAL}
rgw usage log flush threshold = ${RGW_USAGE_LOG_FLUSH_THRESHOLD}
rgw usage max shards = ${RGW_USAGE_MAX_SHARDS}
rgw usage max user shards = ${RGW_USAGE_MAX_USER_SHARDS}
log file = /var/log/ceph/client.rgw.${RGW_NAME}.log
rgw frontends = ${RGW_FRONTEND}
ENDHERE
fi
# start RGW
radosgw "${DAEMON_OPTS[@]}" -n client.rgw."${RGW_NAME}" -k "$RGW_KEYRING"
}
function bootstrap_demo_user {
if [ -f /ceph-demo-user ]; then
log "Demo user already exists with credentials:"
cat /ceph-demo-user
else
log "Setting up a demo user..."
if [ -n "$CEPH_DEMO_UID" ] && [ -n "$CEPH_DEMO_ACCESS_KEY" ] && [ -n "$CEPH_DEMO_SECRET_KEY" ]; then
radosgw-admin "${CLI_OPTS[@]}" user create --uid="$CEPH_DEMO_UID" --display-name="Ceph demo user" --access-key="$CEPH_DEMO_ACCESS_KEY" --secret-key="$CEPH_DEMO_SECRET_KEY"
else
radosgw-admin "${CLI_OPTS[@]}" user create --uid="$CEPH_DEMO_UID" --display-name="Ceph demo user" > "${CEPH_DEMO_UID}_user_details"
CEPH_DEMO_ACCESS_KEY=$(grep -Po '(?<="access_key": ")[^"]*' "${CEPH_DEMO_UID}_user_details")
CEPH_DEMO_SECRET_KEY=$(grep -Po '(?<="secret_key": ")[^"]*' "${CEPH_DEMO_UID}_user_details")
fi
sed -i s/AWS_ACCESS_KEY_PLACEHOLDER/"$CEPH_DEMO_ACCESS_KEY"/ /root/.s3cfg
sed -i s/AWS_SECRET_KEY_PLACEHOLDER/"$CEPH_DEMO_SECRET_KEY"/ /root/.s3cfg
echo "Access key: $CEPH_DEMO_ACCESS_KEY" > /ceph-demo-user
echo "Secret key: $CEPH_DEMO_SECRET_KEY" >> /ceph-demo-user
radosgw-admin "${CLI_OPTS[@]}" caps add --caps="buckets=*;users=*;usage=*;metadata=*" --uid="$CEPH_DEMO_UID"
# Use rgw port
sed -i "s/host_base = localhost/host_base = ${RGW_NAME}:${RGW_CIVETWEB_PORT}/" /root/.s3cfg
sed -i "s/host_bucket = localhost/host_bucket = ${RGW_NAME}:${RGW_CIVETWEB_PORT}/" /root/.s3cfg
if [ -n "$CEPH_DEMO_BUCKET" ]; then
log "Creating bucket..."
# waiting for rgw to be ready, 5 seconds is usually enough
sleep 5
s3cmd mb s3://"$CEPH_DEMO_BUCKET"
fi
fi
}
################
# IMPORT IN S3 #
################
function import_in_s3 {
if [[ -d "$DATA_TO_SYNC" ]]; then
log "Syncing $DATA_TO_SYNC in S3!"
s3cmd mb s3://"$DATA_TO_SYNC_BUCKET"
s3cmd sync "$DATA_TO_SYNC" s3://"$DATA_TO_SYNC_BUCKET"
else
log "$DATA_TO_SYNC is not a directory, nothing to do!"
fi
}
#######
# NFS #
#######
function bootstrap_nfs {
# Init RPC
rpcbind || return 0
rpc.statd -L || return 0
rpc.idmapd || return 0
# start ganesha
ganesha.nfsd "${GANESHA_OPTIONS[@]}" "${GANESHA_EPOCH}"
}
#######
# API #
#######
function bootstrap_rest_api {
if ! grep -E "\\[client.restapi\\]" /etc/ceph/"${CLUSTER}".conf; then
cat <<ENDHERE >>/etc/ceph/"${CLUSTER}".conf
[client.restapi]
public addr = ${RESTAPI_IP}:${RESTAPI_PORT}
restapi base url = ${RESTAPI_BASE_URL}
restapi log level = ${RESTAPI_LOG_LEVEL}
log file = ${RESTAPI_LOG_FILE}
ENDHERE
fi
# start ceph-rest-api
ceph-rest-api "${CLI_OPTS[@]}" -c /etc/ceph/"${CLUSTER}".conf -n client.admin &
}
##############
# RBD MIRROR #
##############
function bootstrap_rbd_mirror {
# start rbd-mirror
rbd-mirror "${DAEMON_OPTS[@]}"
}
#######
# MGR #
#######
function bootstrap_mgr {
mkdir -p "$MGR_PATH"
ceph "${CLI_OPTS[@]}" auth get-or-create mgr."$MGR_NAME" mon 'allow *' -o "$MGR_PATH"/keyring
chown --verbose -R ceph. "$MGR_PATH"
# start ceph-mgr
ceph-mgr "${DAEMON_OPTS[@]}" -i "$MGR_NAME"
}
########
# SREE #
########
function bootstrap_sree {
if [ ! -d sree ]; then
mkdir sree
tar xzvf sree.tar.gz -C sree --strip-components 1
ACCESS_KEY=$(awk '/Access key/ {print $3}' /ceph-demo-user)
SECRET_KEY=$(awk '/Secret key/ {print $3}' /ceph-demo-user)
pushd sree
sed -i "s|ENDPOINT|http://${EXPOSED_IP}:${RGW_CIVETWEB_PORT}|" static/js/base.js
sed -i "s/ACCESS_KEY/$ACCESS_KEY/" static/js/base.js
sed -i "s/SECRET_KEY/$SECRET_KEY/" static/js/base.js
mv sree.cfg.sample sree.cfg
sed -i "s/RGW_CIVETWEB_PORT_VALUE/$RGW_CIVETWEB_PORT/" sree.cfg
sed -i "s/SREE_PORT_VALUE/$SREE_PORT/" sree.cfg
popd
fi
# start Sree
pushd sree
python app.py &
popd
}
###################
# BUILD BOOTSTRAP #
###################
function build_bootstrap {
# NOTE(leseb): always bootstrap a mon and mgr no matter what
# this is will prevent someone writing daemons in the wrong order
# once both mon and mgr are up we don't care about the order
bootstrap_mon
bootstrap_mgr
if [[ "$DEMO_DAEMONS" == "all" ]]; then
daemons_list="osd mds rgw nfs rbd_mirror rest_api"
else
# change commas to space
comma_to_space=${DEMO_DAEMONS//,/ }
# transform to an array
IFS=" " read -r -a array <<< "$comma_to_space"
# sort and remove potential duplicate
daemons_list=$(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
fi
for daemon in $daemons_list; do
case "$daemon" in
mon)
# the mon is already present so we skip this
continue
;;
mgr)
# the mgr is already present so we skip this
continue
;;
osd)
bootstrap_osd
;;
mds)
bootstrap_mds
;;
rgw)
bootstrap_rgw
bootstrap_demo_user
bootstrap_sree
if [[ -n "$DATA_TO_SYNC" ]] && [[ -n "$DATA_TO_SYNC_BUCKET" ]]; then
import_in_s3
fi
;;
nfs)
bootstrap_nfs
;;
rbd_mirror)
bootstrap_rbd_mirror
;;
rest_api)
bootstrap_rest_api
;;
*)
log "ERROR: unknown scenario!"
log "Available scenarios are: mon mgr osd mds rgw nfs rbd_mirror rest_api"
exit 1
;;
esac
done
}
#########
# WATCH #
#########
detect_ceph_files
build_bootstrap
# create 2 files so we can later check that this is a demo container
touch /var/lib/ceph/I_AM_A_DEMO /etc/ceph/I_AM_A_DEMO
log "SUCCESS"
exec ceph "${CLI_OPTS[@]}" -w