Merge PR #56755 into main
[ceph.git] / src / vstart.sh
1 #!/usr/bin/env bash
2 # -*- mode:sh; tab-width:4; sh-basic-offset:4; indent-tabs-mode:nil -*-
3 # vim: softtabstop=4 shiftwidth=4 expandtab
4
5 # abort on failure
6 set -e
7
8 quoted_print() {
9     for s in "$@"; do
10         if [[ "$s" =~ \  ]]; then
11             printf -- "'%s' " "$s"
12         else
13             printf -- "$s "
14         fi
15     done
16     printf '\n'
17 }
18
19 debug() {
20   "$@" >&2
21 }
22
23 prunb() {
24     debug quoted_print "$@" '&'
25     "$@" &
26 }
27
28 prun() {
29     debug quoted_print "$@"
30     "$@"
31 }
32
33
34 if [ -n "$VSTART_DEST" ]; then
35     SRC_PATH=`dirname $0`
36     SRC_PATH=`(cd $SRC_PATH; pwd)`
37
38     CEPH_DIR=$SRC_PATH
39     CEPH_BIN=${PWD}/bin
40     CEPH_LIB=${PWD}/lib
41
42     CEPH_CONF_PATH=$VSTART_DEST
43     CEPH_DEV_DIR=$VSTART_DEST/dev
44     CEPH_OUT_DIR=$VSTART_DEST/out
45     CEPH_ASOK_DIR=$VSTART_DEST/out
46 fi
47
48 get_cmake_variable() {
49     local variable=$1
50     grep "${variable}:" CMakeCache.txt | cut -d "=" -f 2
51 }
52
53 # for running out of the CMake build directory
54 if [ -e CMakeCache.txt ]; then
55     # Out of tree build, learn source location from CMakeCache.txt
56     CEPH_ROOT=$(get_cmake_variable ceph_SOURCE_DIR)
57     CEPH_BUILD_DIR=`pwd`
58     [ -z "$MGR_PYTHON_PATH" ] && MGR_PYTHON_PATH=$CEPH_ROOT/src/pybind/mgr
59 fi
60
61 # use CEPH_BUILD_ROOT to vstart from a 'make install'
62 if [ -n "$CEPH_BUILD_ROOT" ]; then
63     [ -z "$CEPH_BIN" ] && CEPH_BIN=$CEPH_BUILD_ROOT/bin
64     [ -z "$CEPH_LIB" ] && CEPH_LIB=$CEPH_BUILD_ROOT/lib
65     [ -z "$EC_PATH" ] && EC_PATH=$CEPH_LIB/erasure-code
66     [ -z "$OBJCLASS_PATH" ] && OBJCLASS_PATH=$CEPH_LIB/rados-classes
67     # make install should install python extensions into PYTHONPATH
68 elif [ -n "$CEPH_ROOT" ]; then
69     [ -z "$CEPHFS_SHELL" ] && CEPHFS_SHELL=$CEPH_ROOT/src/tools/cephfs/cephfs-shell
70     [ -z "$PYBIND" ] && PYBIND=$CEPH_ROOT/src/pybind
71     [ -z "$CEPH_BIN" ] && CEPH_BIN=$CEPH_BUILD_DIR/bin
72     [ -z "$CEPH_ADM" ] && CEPH_ADM=$CEPH_BIN/ceph
73     [ -z "$INIT_CEPH" ] && INIT_CEPH=$CEPH_BIN/init-ceph
74     [ -z "$CEPH_LIB" ] && CEPH_LIB=$CEPH_BUILD_DIR/lib
75     [ -z "$OBJCLASS_PATH" ] && OBJCLASS_PATH=$CEPH_LIB
76     [ -z "$EC_PATH" ] && EC_PATH=$CEPH_LIB
77     [ -z "$CEPH_PYTHON_COMMON" ] && CEPH_PYTHON_COMMON=$CEPH_ROOT/src/python-common
78 fi
79
80 if [ -z "${CEPH_VSTART_WRAPPER}" ]; then
81     PATH=$(pwd):$PATH
82 fi
83
84 [ -z "$PYBIND" ] && PYBIND=./pybind
85
86 [ -n "$CEPH_PYTHON_COMMON" ] && CEPH_PYTHON_COMMON="$CEPH_PYTHON_COMMON:"
87 CYTHON_PYTHONPATH="$CEPH_LIB/cython_modules/lib.3"
88 export PYTHONPATH=$PYBIND:$CYTHON_PYTHONPATH:$CEPH_PYTHON_COMMON$PYTHONPATH
89
90 export LD_LIBRARY_PATH=$CEPH_LIB:$LD_LIBRARY_PATH
91 export DYLD_LIBRARY_PATH=$CEPH_LIB:$DYLD_LIBRARY_PATH
92 # Suppress logging for regular use that indicated that we are using a
93 # development version. vstart.sh is only used during testing and
94 # development
95 export CEPH_DEV=1
96
97 [ -z "$CEPH_NUM_MON" ] && CEPH_NUM_MON="$MON"
98 [ -z "$CEPH_NUM_OSD" ] && CEPH_NUM_OSD="$OSD"
99 [ -z "$CEPH_NUM_MDS" ] && CEPH_NUM_MDS="$MDS"
100 [ -z "$CEPH_NUM_MGR" ] && CEPH_NUM_MGR="$MGR"
101 [ -z "$CEPH_NUM_FS"  ] && CEPH_NUM_FS="$FS"
102 [ -z "$CEPH_NUM_RGW" ] && CEPH_NUM_RGW="$RGW"
103 [ -z "$GANESHA_DAEMON_NUM" ] && GANESHA_DAEMON_NUM="$NFS"
104
105 # if none of the CEPH_NUM_* number is specified, kill the existing
106 # cluster.
107 if [ -z "$CEPH_NUM_MON" -a \
108      -z "$CEPH_NUM_OSD" -a \
109      -z "$CEPH_NUM_MDS" -a \
110      -z "$CEPH_NUM_MGR" -a \
111      -z "$GANESHA_DAEMON_NUM" ]; then
112     kill_all=1
113 else
114     kill_all=0
115 fi
116
117 [ -z "$CEPH_NUM_MON" ] && CEPH_NUM_MON=3
118 [ -z "$CEPH_NUM_OSD" ] && CEPH_NUM_OSD=3
119 [ -z "$CEPH_NUM_MDS" ] && CEPH_NUM_MDS=3
120 [ -z "$CEPH_NUM_MGR" ] && CEPH_NUM_MGR=1
121 [ -z "$CEPH_NUM_FS"  ] && CEPH_NUM_FS=1
122 [ -z "$CEPH_MAX_MDS" ] && CEPH_MAX_MDS=1
123 [ -z "$CEPH_NUM_RGW" ] && CEPH_NUM_RGW=0
124 [ -z "$GANESHA_DAEMON_NUM" ] && GANESHA_DAEMON_NUM=0
125
126 [ -z "$CEPH_DIR" ] && CEPH_DIR="$PWD"
127 [ -z "$CEPH_DEV_DIR" ] && CEPH_DEV_DIR="$CEPH_DIR/dev"
128 [ -z "$CEPH_OUT_DIR" ] && CEPH_OUT_DIR="$CEPH_DIR/out"
129 [ -z "$CEPH_RGW_PORT" ] && CEPH_RGW_PORT=8000
130 [ -z "$CEPH_CONF_PATH" ] && CEPH_CONF_PATH=$CEPH_DIR
131
132 if [ $CEPH_NUM_OSD -gt 3 ]; then
133     OSD_POOL_DEFAULT_SIZE=3
134 else
135     OSD_POOL_DEFAULT_SIZE=$CEPH_NUM_OSD
136 fi
137
138 extra_conf=""
139 new=0
140 standby=0
141 debug=0
142 ip=""
143 nodaemon=0
144 redirect=0
145 smallmds=0
146 short=0
147 ec=0
148 cephadm=0
149 parallel=true
150 hitset=""
151 overwrite_conf=0
152 cephx=1 #turn cephx on by default
153 gssapi_authx=0
154 cache=""
155 if [ `uname` = FreeBSD ]; then
156     objectstore="filestore"
157 else
158     objectstore="bluestore"
159 fi
160 ceph_osd=ceph-osd
161 rgw_frontend="beast"
162 rgw_compression=""
163 lockdep=${LOCKDEP:-1}
164 spdk_enabled=0 #disable SPDK by default
165 zoned_enabled=0
166
167 with_mgr_dashboard=true
168 if [[ "$(get_cmake_variable WITH_MGR_DASHBOARD_FRONTEND)" != "ON" ]] ||
169    [[ "$(get_cmake_variable WITH_RBD)" != "ON" ]]; then
170     debug echo "ceph-mgr dashboard not built - disabling."
171     with_mgr_dashboard=false
172 fi
173
174 filestore_path=
175 kstore_path=
176 bluestore_dev=
177
178 VSTART_SEC="client.vstart.sh"
179
180 MON_ADDR=""
181 DASH_URLS=""
182 RESTFUL_URLS=""
183
184 conf_fn="$CEPH_CONF_PATH/ceph.conf"
185 keyring_fn="$CEPH_CONF_PATH/keyring"
186 osdmap_fn="/tmp/ceph_osdmap.$$"
187 monmap_fn="/tmp/ceph_monmap.$$"
188 inc_osd_num=0
189
190 msgr="21"
191
192 usage="usage: $0 [option]... \nex: MON=3 OSD=1 MDS=1 MGR=1 RGW=1 NFS=1 $0 -n -d\n"
193 usage=$usage"options:\n"
194 usage=$usage"\t-d, --debug\n"
195 usage=$usage"\t-s, --standby_mds: Generate standby-replay MDS for each active\n"
196 usage=$usage"\t-l, --localhost: use localhost instead of hostname\n"
197 usage=$usage"\t-i <ip>: bind to specific ip\n"
198 usage=$usage"\t-n, --new\n"
199 usage=$usage"\t--valgrind[_{osd,mds,mon,rgw}] 'toolname args...'\n"
200 usage=$usage"\t--nodaemon: use ceph-run as wrapper for mon/osd/mds\n"
201 usage=$usage"\t--redirect-output: only useful with nodaemon, directs output to log file\n"
202 usage=$usage"\t--smallmds: limit mds cache memory limit\n"
203 usage=$usage"\t-m ip:port\t\tspecify monitor address\n"
204 usage=$usage"\t-k keep old configuration files (default)\n"
205 usage=$usage"\t-x enable cephx (on by default)\n"
206 usage=$usage"\t-X disable cephx\n"
207 usage=$usage"\t-g --gssapi enable Kerberos/GSSApi authentication\n"
208 usage=$usage"\t-G disable Kerberos/GSSApi authentication\n"
209 usage=$usage"\t--hitset <pool> <hit_set_type>: enable hitset tracking\n"
210 usage=$usage"\t-e : create an erasure pool\n";
211 usage=$usage"\t-o config\t\t add extra config parameters to all sections\n"
212 usage=$usage"\t--rgw_port specify ceph rgw http listen port\n"
213 usage=$usage"\t--rgw_frontend specify the rgw frontend configuration\n"
214 usage=$usage"\t--rgw_compression specify the rgw compression plugin\n"
215 usage=$usage"\t-b, --bluestore use bluestore as the osd objectstore backend (default)\n"
216 usage=$usage"\t-f, --filestore use filestore as the osd objectstore backend\n"
217 usage=$usage"\t-K, --kstore use kstore as the osd objectstore backend\n"
218 usage=$usage"\t--memstore use memstore as the osd objectstore backend\n"
219 usage=$usage"\t--cache <pool>: enable cache tiering on pool\n"
220 usage=$usage"\t--short: short object names only; necessary for ext4 dev\n"
221 usage=$usage"\t--nolockdep disable lockdep\n"
222 usage=$usage"\t--multimds <count> allow multimds with maximum active count\n"
223 usage=$usage"\t--without-dashboard: do not run using mgr dashboard\n"
224 usage=$usage"\t--bluestore-spdk: enable SPDK and with a comma-delimited list of PCI-IDs of NVME device (e.g, 0000:81:00.0)\n"
225 usage=$usage"\t--msgr1: use msgr1 only\n"
226 usage=$usage"\t--msgr2: use msgr2 only\n"
227 usage=$usage"\t--msgr21: use msgr2 and msgr1\n"
228 usage=$usage"\t--crimson: use crimson-osd instead of ceph-osd\n"
229 usage=$usage"\t--osd-args: specify any extra osd specific options\n"
230 usage=$usage"\t--bluestore-devs: comma-separated list of blockdevs to use for bluestore\n"
231 usage=$usage"\t--bluestore-zoned: blockdevs listed by --bluestore-devs are zoned devices (HM-SMR HDD or ZNS SSD)\n"
232 usage=$usage"\t--inc-osd: append some more osds into existing vcluster\n"
233 usage=$usage"\t--cephadm: enable cephadm orchestrator with ~/.ssh/id_rsa[.pub]\n"
234 usage=$usage"\t--no-parallel: dont start all OSDs in parallel\n"
235
236 usage_exit() {
237     printf "$usage"
238     exit
239 }
240
241 while [ $# -ge 1 ]; do
242 case $1 in
243     -d | --debug )
244         debug=1
245         ;;
246     -s | --standby_mds)
247         standby=1
248         ;;
249     -l | --localhost )
250         ip="127.0.0.1"
251         ;;
252     -i )
253         [ -z "$2" ] && usage_exit
254         ip="$2"
255         shift
256         ;;
257     -e )
258         ec=1
259         ;;
260     --new | -n )
261         new=1
262         ;;
263     --inc-osd )
264         new=0
265         kill_all=0
266         inc_osd_num=$2
267         if [ "$inc_osd_num" == "" ]; then
268             inc_osd_num=1
269         else
270             shift
271         fi
272         ;;
273     --short )
274         short=1
275         ;;
276     --crimson )
277         ceph_osd=crimson-osd
278         ;;
279     --osd-args )
280         extra_osd_args="$2"
281         shift
282         ;;
283     --msgr1 )
284         msgr="1"
285         ;;
286     --msgr2 )
287         msgr="2"
288         ;;
289     --msgr21 )
290         msgr="21"
291         ;;
292     --cephadm )
293         cephadm=1
294         ;;
295     --no-parallel )
296         parallel=false
297         ;;
298     --valgrind )
299         [ -z "$2" ] && usage_exit
300         valgrind=$2
301         shift
302         ;;
303     --valgrind_args )
304         valgrind_args="$2"
305         shift
306         ;;
307     --valgrind_mds )
308         [ -z "$2" ] && usage_exit
309         valgrind_mds=$2
310         shift
311         ;;
312     --valgrind_osd )
313         [ -z "$2" ] && usage_exit
314         valgrind_osd=$2
315         shift
316         ;;
317     --valgrind_mon )
318         [ -z "$2" ] && usage_exit
319         valgrind_mon=$2
320         shift
321         ;;
322     --valgrind_mgr )
323         [ -z "$2" ] && usage_exit
324         valgrind_mgr=$2
325         shift
326         ;;
327     --valgrind_rgw )
328         [ -z "$2" ] && usage_exit
329         valgrind_rgw=$2
330         shift
331         ;;
332     --nodaemon )
333         nodaemon=1
334         ;;
335     --redirect-output)
336         redirect=1
337         ;;
338     --smallmds )
339         smallmds=1
340         ;;
341     --rgw_port )
342         CEPH_RGW_PORT=$2
343         shift
344         ;;
345     --rgw_frontend )
346         rgw_frontend=$2
347         shift
348         ;;
349     --rgw_compression )
350         rgw_compression=$2
351         shift
352         ;;
353     --kstore_path )
354         kstore_path=$2
355         shift
356         ;;
357     --filestore_path )
358         filestore_path=$2
359         shift
360         ;;
361     -m )
362         [ -z "$2" ] && usage_exit
363         MON_ADDR=$2
364         shift
365         ;;
366     -x )
367         cephx=1 # this is on be default, flag exists for historical consistency
368         ;;
369     -X )
370         cephx=0
371         ;;
372
373     -g | --gssapi)
374         gssapi_authx=1
375         ;;
376     -G)
377         gssapi_authx=0
378         ;;
379
380     -k )
381         if [ ! -r $conf_fn ]; then
382             echo "cannot use old configuration: $conf_fn not readable." >&2
383             exit
384         fi
385         new=0
386         ;;
387     --memstore )
388         objectstore="memstore"
389         ;;
390     -b | --bluestore )
391         objectstore="bluestore"
392         ;;
393     -f | --filestore )
394         objectstore="filestore"
395         ;;
396     -K | --kstore )
397         objectstore="kstore"
398         ;;
399     --hitset )
400         hitset="$hitset $2 $3"
401         shift
402         shift
403         ;;
404     -o )
405         extra_conf="$extra_conf $2
406 "
407         shift
408         ;;
409     --cache )
410         if [ -z "$cache" ]; then
411             cache="$2"
412         else
413             cache="$cache $2"
414         fi
415         shift
416         ;;
417     --nolockdep )
418         lockdep=0
419         ;;
420     --multimds)
421         CEPH_MAX_MDS="$2"
422         shift
423         ;;
424     --without-dashboard)
425         with_mgr_dashboard=false
426         ;;
427     --bluestore-spdk )
428         [ -z "$2" ] && usage_exit
429         IFS=',' read -r -a bluestore_spdk_dev <<< "$2"
430         spdk_enabled=1
431         shift
432         ;;
433     --bluestore-devs )
434         IFS=',' read -r -a bluestore_dev <<< "$2"
435         for dev in "${bluestore_dev[@]}"; do
436             if [ ! -b $dev -o ! -w $dev ]; then
437                 echo "All --bluestore-devs must refer to writable block devices"
438                 exit 1
439             fi
440         done
441         shift
442         ;;
443     --bluestore-zoned )
444         zoned_enabled=1
445         ;;
446     * )
447         usage_exit
448 esac
449 shift
450 done
451
452 if [ $kill_all -eq 1 ]; then
453     $SUDO $INIT_CEPH stop
454 fi
455
456 if [ "$new" -eq 0 ]; then
457     if [ -z "$CEPH_ASOK_DIR" ]; then
458         CEPH_ASOK_DIR=`dirname $($CEPH_BIN/ceph-conf  -c $conf_fn --show-config-value admin_socket)`
459     fi
460     mkdir -p $CEPH_ASOK_DIR
461     MON=`$CEPH_BIN/ceph-conf -c $conf_fn --name $VSTART_SEC --lookup num_mon 2>/dev/null` && \
462         CEPH_NUM_MON="$MON"
463     OSD=`$CEPH_BIN/ceph-conf -c $conf_fn --name $VSTART_SEC --lookup num_osd 2>/dev/null` && \
464         CEPH_NUM_OSD="$OSD"
465     MDS=`$CEPH_BIN/ceph-conf -c $conf_fn --name $VSTART_SEC --lookup num_mds 2>/dev/null` && \
466         CEPH_NUM_MDS="$MDS"
467     MGR=`$CEPH_BIN/ceph-conf -c $conf_fn --name $VSTART_SEC --lookup num_mgr 2>/dev/null` && \
468         CEPH_NUM_MGR="$MGR"
469     RGW=`$CEPH_BIN/ceph-conf -c $conf_fn --name $VSTART_SEC --lookup num_rgw 2>/dev/null` && \
470         CEPH_NUM_RGW="$RGW"
471     NFS=`$CEPH_BIN/ceph-conf -c $conf_fn --name $VSTART_SEC --lookup num_ganesha 2>/dev/null` && \
472         GANESHA_DAEMON_NUM="$NFS"
473 else
474     # only delete if -n
475     if [ -e "$conf_fn" ]; then
476         asok_dir=`dirname $($CEPH_BIN/ceph-conf  -c $conf_fn --show-config-value admin_socket)`
477         rm -- "$conf_fn"
478         if [ $asok_dir != /var/run/ceph ]; then
479             [ -d $asok_dir ] && rm -f $asok_dir/* && rmdir $asok_dir
480         fi
481     fi
482     if [ -z "$CEPH_ASOK_DIR" ]; then
483         CEPH_ASOK_DIR=`mktemp -u -d "${TMPDIR:-/tmp}/ceph-asok.XXXXXX"`
484     fi
485 fi
486
487 ARGS="-c $conf_fn"
488
489 run() {
490     type=$1
491     shift
492     num=$1
493     shift
494     eval "valg=\$valgrind_$type"
495     [ -z "$valg" ] && valg="$valgrind"
496
497     if [ -n "$valg" ]; then
498         prunb valgrind --tool="$valg" $valgrind_args "$@" -f
499         sleep 1
500     else
501         if [ "$nodaemon" -eq 0 ]; then
502             prun "$@"
503         elif [ "$redirect" -eq 0 ]; then
504             prunb ${CEPH_ROOT}/src/ceph-run "$@" -f
505         else
506             ( prunb ${CEPH_ROOT}/src/ceph-run "$@" -f ) >$CEPH_OUT_DIR/$type.$num.stdout 2>&1
507         fi
508     fi
509 }
510
511 wconf() {
512     if [ "$new" -eq 1 -o "$overwrite_conf" -eq 1 ]; then
513         cat >> "$conf_fn"
514     fi
515 }
516
517
518 do_rgw_conf() {
519
520     if [ $CEPH_NUM_RGW -eq 0 ]; then
521         return 0
522     fi
523
524     # setup each rgw on a sequential port, starting at $CEPH_RGW_PORT.
525     # individual rgw's ids will be their ports.
526     current_port=$CEPH_RGW_PORT
527     for n in $(seq 1 $CEPH_NUM_RGW); do
528         wconf << EOF
529 [client.rgw.${current_port}]
530         rgw frontends = $rgw_frontend port=${current_port}
531         admin socket = ${CEPH_OUT_DIR}/radosgw.${current_port}.asok
532 EOF
533         current_port=$((current_port + 1))
534 done
535
536 }
537
538 prepare_conf() {
539     local DAEMONOPTS="
540         log file = $CEPH_OUT_DIR/\$name.log
541         admin socket = $CEPH_ASOK_DIR/\$name.asok
542         chdir = \"\"
543         pid file = $CEPH_OUT_DIR/\$name.pid
544         heartbeat file = $CEPH_OUT_DIR/\$name.heartbeat
545 "
546
547     local mgr_modules="restful iostat"
548     if $with_mgr_dashboard; then
549         mgr_modules="dashboard $mgr_modules"
550     fi
551
552     local msgr_conf=''
553     if [ $msgr -eq 21 ]; then
554         msgr_conf="
555         ms bind msgr2 = true
556         ms bind msgr1 = true
557 ";
558     fi
559     if [ $msgr -eq 2 ]; then
560         msgr_conf="
561         ms bind msgr2 = true
562         ms bind msgr1 = false
563 ";
564     fi
565     if [ $msgr -eq 1 ]; then
566         msgr_conf="
567         ms bind msgr2 = false
568         ms bind msgr1 = true
569 ";
570     fi
571
572     wconf <<EOF
573 ; generated by vstart.sh on `date`
574 [$VSTART_SEC]
575         num mon = $CEPH_NUM_MON
576         num osd = $CEPH_NUM_OSD
577         num mds = $CEPH_NUM_MDS
578         num mgr = $CEPH_NUM_MGR
579         num rgw = $CEPH_NUM_RGW
580         num ganesha = $GANESHA_DAEMON_NUM
581
582 [global]
583         fsid = $(uuidgen)
584         osd failsafe full ratio = .99
585         mon osd full ratio = .99
586         mon osd nearfull ratio = .99
587         mon osd backfillfull ratio = .99
588         mon_max_pg_per_osd = ${MON_MAX_PG_PER_OSD:-1000}
589         erasure code dir = $EC_PATH
590         plugin dir = $CEPH_LIB
591         filestore fd cache size = 32
592         run dir = $CEPH_OUT_DIR
593         crash dir = $CEPH_OUT_DIR
594         enable experimental unrecoverable data corrupting features = *
595         osd_crush_chooseleaf_type = 0
596         debug asok assert abort = true
597 $msgr_conf
598 $extra_conf
599 EOF
600     if [ "$lockdep" -eq 1 ] ; then
601         wconf <<EOF
602         lockdep = true
603 EOF
604     fi
605     if [ "$cephx" -eq 1 ] ; then
606         wconf <<EOF
607         auth cluster required = cephx
608         auth service required = cephx
609         auth client required = cephx
610 EOF
611     elif [ "$gssapi_authx" -eq 1 ] ; then
612         wconf <<EOF
613         auth cluster required = gss
614         auth service required = gss
615         auth client required = gss
616         gss ktab client file = $CEPH_DEV_DIR/gss_\$name.keytab
617 EOF
618     else
619         wconf <<EOF
620         auth cluster required = none
621         auth service required = none
622         auth client required = none
623 EOF
624     fi
625     if [ "$short" -eq 1 ]; then
626         COSDSHORT="        osd max object name len = 460
627         osd max object namespace len = 64"
628     fi
629     if [ "$objectstore" == "bluestore" ]; then
630         if [ "$spdk_enabled" -eq 1 ]; then
631             BLUESTORE_OPTS="        bluestore_block_db_path = \"\"
632         bluestore_block_db_size = 0
633         bluestore_block_db_create = false
634         bluestore_block_wal_path = \"\"
635         bluestore_block_wal_size = 0
636         bluestore_block_wal_create = false
637         bluestore_spdk_mem = 2048"
638         else
639             BLUESTORE_OPTS="        bluestore block db path = $CEPH_DEV_DIR/osd\$id/block.db.file
640         bluestore block db size = 1073741824
641         bluestore block db create = true
642         bluestore block wal path = $CEPH_DEV_DIR/osd\$id/block.wal.file
643         bluestore block wal size = 1048576000
644         bluestore block wal create = true"
645         fi
646         if [ "$zoned_enabled" -eq 1 ]; then
647             BLUESTORE_OPTS="${BLUESTORE_OPTS}
648         bluestore min alloc size = 65536
649         bluestore prefer deferred size = 0
650         bluestore prefer deferred size hdd = 0
651         bluestore prefer deferred size ssd = 0
652         bluestore allocator = zoned"
653         fi
654     fi
655     wconf <<EOF
656 [client]
657         keyring = $keyring_fn
658         log file = $CEPH_OUT_DIR/\$name.\$pid.log
659         admin socket = $CEPH_ASOK_DIR/\$name.\$pid.asok
660
661         ; needed for s3tests
662         rgw crypt s3 kms backend = testing
663         rgw crypt s3 kms encryption keys = testkey-1=YmluCmJvb3N0CmJvb3N0LWJ1aWxkCmNlcGguY29uZgo= testkey-2=aWIKTWFrZWZpbGUKbWFuCm91dApzcmMKVGVzdGluZwo=
664         rgw crypt require ssl = false
665         ; uncomment the following to set LC days as the value in seconds;
666         ; needed for passing lc time based s3-tests (can be verbose)
667         ; rgw lc debug interval = 10
668
669 $extra_conf
670 EOF
671         do_rgw_conf
672         wconf << EOF
673 [mds]
674 $DAEMONOPTS
675         mds data = $CEPH_DEV_DIR/mds.\$id
676         mds root ino uid = `id -u`
677         mds root ino gid = `id -g`
678 $extra_conf
679 [mgr]
680         mgr data = $CEPH_DEV_DIR/mgr.\$id
681         mgr module path = $MGR_PYTHON_PATH
682         cephadm path = $CEPH_ROOT/src/cephadm/cephadm
683 $DAEMONOPTS
684 $extra_conf
685 [osd]
686 $DAEMONOPTS
687         osd_check_max_object_name_len_on_startup = false
688         osd data = $CEPH_DEV_DIR/osd\$id
689         osd journal = $CEPH_DEV_DIR/osd\$id/journal
690         osd journal size = 100
691         osd class tmp = out
692         osd class dir = $OBJCLASS_PATH
693         osd class load list = *
694         osd class default list = *
695         osd fast shutdown = false
696
697         filestore wbthrottle xfs ios start flusher = 10
698         filestore wbthrottle xfs ios hard limit = 20
699         filestore wbthrottle xfs inodes hard limit = 30
700         filestore wbthrottle btrfs ios start flusher = 10
701         filestore wbthrottle btrfs ios hard limit = 20
702         filestore wbthrottle btrfs inodes hard limit = 30
703         bluestore fsck on mount = true
704         bluestore block create = true
705 $BLUESTORE_OPTS
706
707         ; kstore
708         kstore fsck on mount = true
709         osd objectstore = $objectstore
710 $COSDSHORT
711 $extra_conf
712 [mon]
713         mgr initial modules = $mgr_modules
714 $DAEMONOPTS
715 $CMONDEBUG
716 $extra_conf
717         mon cluster log file = $CEPH_OUT_DIR/cluster.mon.\$id.log
718         osd pool default erasure code profile = plugin=jerasure technique=reed_sol_van k=2 m=1 crush-failure-domain=osd
719 EOF
720 }
721
722 write_logrotate_conf() {
723     out_dir=$(pwd)"/out/*.log"
724
725     cat << EOF
726 $out_dir
727 {
728     rotate 5
729     size 1G
730     copytruncate
731     compress
732     notifempty
733     missingok
734     sharedscripts
735     postrotate
736         # NOTE: assuring that the absence of one of the following processes
737         # won't abort the logrotate command.
738         killall -u $USER -q -1 ceph-mon ceph-mgr ceph-mds ceph-osd ceph-fuse radosgw rbd-mirror || echo ""
739     endscript
740 }
741 EOF
742 }
743
744 init_logrotate() {
745     logrotate_conf_path=$(pwd)"/logrotate.conf"
746     logrotate_state_path=$(pwd)"/logrotate.state"
747
748     if ! test -a $logrotate_conf_path; then
749         if test -a $logrotate_state_path; then
750             rm -f $logrotate_state_path
751         fi
752         write_logrotate_conf > $logrotate_conf_path
753     fi
754 }
755
756 start_mon() {
757     local MONS=""
758     local count=0
759     for f in a b c d e f g h i j k l m n o p q r s t u v w x y z
760     do
761         [ $count -eq $CEPH_NUM_MON ] && break;
762         count=$(($count + 1))
763         if [ -z "$MONS" ]; then
764             MONS="$f"
765         else
766             MONS="$MONS $f"
767         fi
768     done
769
770     if [ "$new" -eq 1 ]; then
771         if [ `echo $IP | grep '^127\\.'` ]; then
772             echo
773             echo "NOTE: hostname resolves to loopback; remote hosts will not be able to"
774             echo "  connect.  either adjust /etc/hosts, or edit this script to use your"
775             echo "  machine's real IP."
776             echo
777         fi
778
779         prun $SUDO "$CEPH_BIN/ceph-authtool" --create-keyring --gen-key --name=mon. "$keyring_fn" --cap mon 'allow *'
780         prun $SUDO "$CEPH_BIN/ceph-authtool" --gen-key --name=client.admin \
781              --cap mon 'allow *' \
782              --cap osd 'allow *' \
783              --cap mds 'allow *' \
784              --cap mgr 'allow *' \
785              "$keyring_fn"
786
787         # build a fresh fs monmap, mon fs
788         local params=()
789         local count=0
790         local mon_host=""
791         for f in $MONS
792         do
793             if [ $msgr -eq 1 ]; then
794                 A="v1:$IP:$(($CEPH_PORT+$count+1))"
795             fi
796             if [ $msgr -eq 2 ]; then
797                 A="v2:$IP:$(($CEPH_PORT+$count+1))"
798             fi
799             if [ $msgr -eq 21 ]; then
800                 A="[v2:$IP:$(($CEPH_PORT+$count)),v1:$IP:$(($CEPH_PORT+$count+1))]"
801             fi
802             params+=("--addv" "$f" "$A")
803             mon_host="$mon_host $A"
804             wconf <<EOF
805 [mon.$f]
806         host = $HOSTNAME
807         mon data = $CEPH_DEV_DIR/mon.$f
808 EOF
809             count=$(($count + 2))
810         done
811         wconf <<EOF
812 [global]
813         mon host = $mon_host
814 EOF
815         prun "$CEPH_BIN/monmaptool" --create --clobber "${params[@]}" --print "$monmap_fn"
816
817         for f in $MONS
818         do
819             prun rm -rf -- "$CEPH_DEV_DIR/mon.$f"
820             prun mkdir -p "$CEPH_DEV_DIR/mon.$f"
821             prun "$CEPH_BIN/ceph-mon" --mkfs -c "$conf_fn" -i "$f" --monmap="$monmap_fn" --keyring="$keyring_fn"
822         done
823
824         prun rm -- "$monmap_fn"
825     fi
826
827     # start monitors
828     for f in $MONS
829     do
830         run 'mon' $f $CEPH_BIN/ceph-mon -i $f $ARGS $CMON_ARGS
831     done
832 }
833
834 start_osd() {
835     if [ $inc_osd_num -gt 0 ]; then
836         old_maxosd=$($CEPH_BIN/ceph osd getmaxosd | sed -e 's/max_osd = //' -e 's/ in epoch.*//')
837         start=$old_maxosd
838         end=$(($start-1+$inc_osd_num))
839         overwrite_conf=1 # fake wconf
840     else
841         start=0
842         end=$(($CEPH_NUM_OSD-1))
843     fi
844     local osds_wait
845     for osd in `seq $start $end`
846     do
847         local extra_seastar_args
848         if [ "$ceph_osd" == "crimson-osd" ]; then
849             # designate a single CPU node $osd for osd.$osd
850             extra_seastar_args="--smp 1 --cpuset $osd"
851             if [ "$debug" -ne 0 ]; then
852                 extra_seastar_args+=" --debug"
853             fi
854         fi
855         if [ "$new" -eq 1 -o $inc_osd_num -gt 0 ]; then
856             wconf <<EOF
857 [osd.$osd]
858         host = $HOSTNAME
859 EOF
860             if [ "$spdk_enabled" -eq 1 ]; then
861                 wconf <<EOF
862         bluestore_block_path = spdk:${bluestore_spdk_dev[$osd]}
863 EOF
864             fi
865
866             rm -rf $CEPH_DEV_DIR/osd$osd || true
867             if command -v btrfs > /dev/null; then
868                 for f in $CEPH_DEV_DIR/osd$osd/*; do btrfs sub delete $f &> /dev/null || true; done
869             fi
870             if [ -n "$filestore_path" ]; then
871                 ln -s $filestore_path $CEPH_DEV_DIR/osd$osd
872             elif [ -n "$kstore_path" ]; then
873                 ln -s $kstore_path $CEPH_DEV_DIR/osd$osd
874             else
875                 mkdir -p $CEPH_DEV_DIR/osd$osd
876                 if [ -n "${bluestore_dev[$osd]}" ]; then
877                     dd if=/dev/zero of=${bluestore_dev[$osd]} bs=1M count=1
878                     ln -s ${bluestore_dev[$osd]} $CEPH_DEV_DIR/osd$osd/block
879                     wconf <<EOF
880         bluestore fsck on mount = false
881 EOF
882                 fi
883             fi
884
885             local uuid=`uuidgen`
886             echo "add osd$osd $uuid"
887             OSD_SECRET=$($CEPH_BIN/ceph-authtool --gen-print-key)
888             echo "{\"cephx_secret\": \"$OSD_SECRET\"}" > $CEPH_DEV_DIR/osd$osd/new.json
889             ceph_adm osd new $uuid -i $CEPH_DEV_DIR/osd$osd/new.json
890             rm $CEPH_DEV_DIR/osd$osd/new.json
891             $SUDO $CEPH_BIN/$ceph_osd $extra_osd_args -i $osd $ARGS --mkfs --key $OSD_SECRET --osd-uuid $uuid $extra_seastar_args
892
893             local key_fn=$CEPH_DEV_DIR/osd$osd/keyring
894             cat > $key_fn<<EOF
895 [osd.$osd]
896         key = $OSD_SECRET
897 EOF
898         fi
899         echo start osd.$osd
900         local osd_pid
901         run 'osd' $osd $SUDO $CEPH_BIN/$ceph_osd \
902             $extra_seastar_args $extra_osd_args \
903             -i $osd $ARGS $COSD_ARGS &
904         osd_pid=$!
905         if $parallel; then
906             osds_wait=$osd_pid
907         else
908             wait $osd_pid
909         fi
910     done
911     if $parallel; then
912         for p in $osds_wait; do
913             wait $p
914         done
915         debug echo OSDs started
916     fi
917     if [ $inc_osd_num -gt 0 ]; then
918         # update num osd
919         new_maxosd=$($CEPH_BIN/ceph osd getmaxosd | sed -e 's/max_osd = //' -e 's/ in epoch.*//')
920         sed -i "s/num osd = .*/num osd = $new_maxosd/g" $conf_fn
921     fi
922 }
923
924 start_mgr() {
925     local mgr=0
926     local ssl=${DASHBOARD_SSL:-1}
927     # avoid monitors on nearby ports (which test/*.sh use extensively)
928     MGR_PORT=$(($CEPH_PORT + 1000))
929     PROMETHEUS_PORT=9283
930     for name in x y z a b c d e f g h i j k l m n o p
931     do
932         [ $mgr -eq $CEPH_NUM_MGR ] && break
933         mgr=$(($mgr + 1))
934         if [ "$new" -eq 1 ]; then
935             mkdir -p $CEPH_DEV_DIR/mgr.$name
936             key_fn=$CEPH_DEV_DIR/mgr.$name/keyring
937             $SUDO $CEPH_BIN/ceph-authtool --create-keyring --gen-key --name=mgr.$name $key_fn
938             ceph_adm -i $key_fn auth add mgr.$name mon 'allow profile mgr' mds 'allow *' osd 'allow *'
939
940             wconf <<EOF
941 [mgr.$name]
942         host = $HOSTNAME
943 EOF
944
945             if $with_mgr_dashboard ; then
946                 local port_option="ssl_server_port"
947                 local http_proto="https"
948                 if [ "$ssl" == "0" ]; then
949                     port_option="server_port"
950                     http_proto="http"
951                     ceph_adm config set mgr mgr/dashboard/ssl false --force
952                 fi
953                 ceph_adm config set mgr mgr/dashboard/$name/$port_option $MGR_PORT --force
954                 if [ $mgr -eq 1 ]; then
955                     DASH_URLS="$http_proto://$IP:$MGR_PORT"
956                 else
957                     DASH_URLS+=", $http_proto://$IP:$MGR_PORT"
958                 fi
959             fi
960             MGR_PORT=$(($MGR_PORT + 1000))
961             ceph_adm config set mgr mgr/prometheus/$name/server_port $PROMETHEUS_PORT --force
962             PROMETHEUS_PORT=$(($PROMETHEUS_PORT + 1000))
963
964             ceph_adm config set mgr mgr/restful/$name/server_port $MGR_PORT --force
965             if [ $mgr -eq 1 ]; then
966                 RESTFUL_URLS="https://$IP:$MGR_PORT"
967             else
968                 RESTFUL_URLS+=", https://$IP:$MGR_PORT"
969             fi
970             MGR_PORT=$(($MGR_PORT + 1000))
971         fi
972
973         debug echo "Starting mgr.${name}"
974         run 'mgr' $name $CEPH_BIN/ceph-mgr -i $name $ARGS
975     done
976
977     if [ "$new" -eq 1 ]; then
978         # setting login credentials for dashboard
979         if $with_mgr_dashboard; then
980             while ! ceph_adm -h | grep -c -q ^dashboard ; do
981                 debug echo 'waiting for mgr dashboard module to start'
982                 sleep 1
983             done
984             ceph_adm dashboard ac-user-create --force-password admin admin administrator
985             if [ "$ssl" != "0" ]; then
986                 if ! ceph_adm dashboard create-self-signed-cert;  then
987                     debug echo dashboard module not working correctly!
988                 fi
989             fi
990         fi
991
992         while ! ceph_adm -h | grep -c -q ^restful ; do
993             debug echo 'waiting for mgr restful module to start'
994             sleep 1
995         done
996         if ceph_adm restful create-self-signed-cert; then
997             SF=`mktemp`
998             ceph_adm restful create-key admin -o $SF
999             RESTFUL_SECRET=`cat $SF`
1000             rm $SF
1001         else
1002             debug echo MGR Restful is not working, perhaps the package is not installed?
1003         fi
1004     fi
1005
1006     if [ "$cephadm" -eq 1 ]; then
1007         debug echo Enabling cephadm orchestrator
1008         if [ "$new" -eq 1 ]; then
1009                 digest=$(curl -s \
1010                 https://registry.hub.docker.com/v2/repositories/ceph/daemon-base/tags/latest-master-devel \
1011                 | jq -r '.images[].digest')
1012                 ceph_adm config set global container_image "docker.io/ceph/daemon-base@$digest"
1013         fi
1014         ceph_adm config-key set mgr/cephadm/ssh_identity_key -i ~/.ssh/id_rsa
1015         ceph_adm config-key set mgr/cephadm/ssh_identity_pub -i ~/.ssh/id_rsa.pub
1016         ceph_adm mgr module enable cephadm
1017         ceph_adm orch set backend cephadm
1018         ceph_adm orch host add "$(hostname)"
1019         ceph_adm orch apply crash '*'
1020         ceph_adm config set mgr mgr/cephadm/allow_ptrace true
1021     fi
1022 }
1023
1024 start_mds() {
1025     local mds=0
1026     for name in a b c d e f g h i j k l m n o p
1027     do
1028         [ $mds -eq $CEPH_NUM_MDS ] && break
1029         mds=$(($mds + 1))
1030
1031         if [ "$new" -eq 1 ]; then
1032             prun mkdir -p "$CEPH_DEV_DIR/mds.$name"
1033             key_fn=$CEPH_DEV_DIR/mds.$name/keyring
1034             wconf <<EOF
1035 [mds.$name]
1036         host = $HOSTNAME
1037 EOF
1038             if [ "$standby" -eq 1 ]; then
1039                 mkdir -p $CEPH_DEV_DIR/mds.${name}s
1040                 wconf <<EOF
1041         mds standby for rank = $mds
1042 [mds.${name}s]
1043         mds standby replay = true
1044         mds standby for name = ${name}
1045 EOF
1046             fi
1047             prun $SUDO "$CEPH_BIN/ceph-authtool" --create-keyring --gen-key --name="mds.$name" "$key_fn"
1048             ceph_adm -i "$key_fn" auth add "mds.$name" mon 'allow profile mds' osd 'allow rw tag cephfs *=*' mds 'allow' mgr 'allow profile mds'
1049             if [ "$standby" -eq 1 ]; then
1050                 prun $SUDO "$CEPH_BIN/ceph-authtool" --create-keyring --gen-key --name="mds.${name}s" \
1051                      "$CEPH_DEV_DIR/mds.${name}s/keyring"
1052                 ceph_adm -i "$CEPH_DEV_DIR/mds.${name}s/keyring" auth add "mds.${name}s" \
1053                              mon 'allow profile mds' osd 'allow *' mds 'allow' mgr 'allow profile mds'
1054             fi
1055         fi
1056
1057         run 'mds' $name $CEPH_BIN/ceph-mds -i $name $ARGS $CMDS_ARGS
1058         if [ "$standby" -eq 1 ]; then
1059             run 'mds' $name $CEPH_BIN/ceph-mds -i ${name}s $ARGS $CMDS_ARGS
1060         fi
1061
1062         #valgrind --tool=massif $CEPH_BIN/ceph-mds $ARGS --mds_log_max_segments 2 --mds_thrash_fragments 0 --mds_thrash_exports 0 > m  #--debug_ms 20
1063         #$CEPH_BIN/ceph-mds -d $ARGS --mds_thrash_fragments 0 --mds_thrash_exports 0 #--debug_ms 20
1064         #ceph_adm mds set max_mds 2
1065     done
1066
1067     if [ $new -eq 1 ]; then
1068         if [ "$CEPH_NUM_FS" -gt "0" ] ; then
1069             sleep 5 # time for MDS to come up as standby to avoid health warnings on fs creation
1070             if [ "$CEPH_NUM_FS" -gt "1" ] ; then
1071                 ceph_adm fs flag set enable_multiple true --yes-i-really-mean-it
1072             fi
1073
1074             # wait for volume module to load
1075             while ! ceph_adm fs volume ls ; do sleep 1 ; done
1076             local fs=0
1077             for name in a b c d e f g h i j k l m n o p
1078             do
1079                 ceph_adm fs volume create ${name}
1080                 ceph_adm fs authorize ${name} "client.fs_${name}" / rwp >> "$keyring_fn"
1081                 fs=$(($fs + 1))
1082                 [ $fs -eq $CEPH_NUM_FS ] && break
1083             done
1084         fi
1085     fi
1086
1087 }
1088
1089 # Ganesha Daemons requires nfs-ganesha nfs-ganesha-ceph nfs-ganesha-rados-grace
1090 # nfs-ganesha-rados-urls (version 3.3 and above) packages installed. On
1091 # Fedora>=31 these packages can be installed directly with 'dnf'. For CentOS>=8
1092 # the packages are available at
1093 # https://wiki.centos.org/SpecialInterestGroup/Storage
1094 # Similarly for Ubuntu>=16.04 follow the instructions on
1095 # https://launchpad.net/~nfs-ganesha
1096
1097 start_ganesha() {
1098     cluster_id="vstart"
1099     GANESHA_PORT=$(($CEPH_PORT + 4000))
1100     local ganesha=0
1101     test_user="ganesha-$cluster_id"
1102     pool_name="nfs-ganesha"
1103     namespace=$cluster_id
1104     url="rados://$pool_name/$namespace/conf-nfs.$test_user"
1105
1106     prun ceph_adm auth get-or-create client.$test_user \
1107         mon "allow r" \
1108         osd "allow rw pool=$pool_name namespace=$namespace, allow rw tag cephfs data=a" \
1109         mds "allow rw path=/" \
1110         >> "$keyring_fn"
1111
1112     ceph_adm mgr module enable test_orchestrator
1113     ceph_adm orch set backend test_orchestrator
1114     ceph_adm test_orchestrator load_data -i $CEPH_ROOT/src/pybind/mgr/test_orchestrator/dummy_data.json
1115     prun ceph_adm nfs cluster create cephfs $cluster_id
1116     prun ceph_adm nfs export create cephfs "a" $cluster_id "/cephfs"
1117
1118     for name in a b c d e f g h i j k l m n o p
1119     do
1120         [ $ganesha -eq $GANESHA_DAEMON_NUM ] && break
1121
1122         port=$(($GANESHA_PORT + ganesha))
1123         ganesha=$(($ganesha + 1))
1124         ganesha_dir="$CEPH_DEV_DIR/ganesha.$name"
1125         prun rm -rf $ganesha_dir
1126         prun mkdir -p $ganesha_dir
1127
1128         echo "NFS_CORE_PARAM {
1129             Enable_NLM = false;
1130             Enable_RQUOTA = false;
1131             Protocols = 4;
1132             NFS_Port = $port;
1133         }
1134
1135         MDCACHE {
1136            Dir_Chunk = 0;
1137         }
1138
1139         NFSv4 {
1140            RecoveryBackend = rados_cluster;
1141            Minor_Versions = 1, 2;
1142         }
1143
1144         %url $url
1145
1146         RADOS_KV {
1147            pool = $pool_name;
1148            namespace = $namespace;
1149            UserId = $test_user;
1150            nodeid = $name;
1151         }
1152
1153         RADOS_URLS {
1154            Userid = $test_user;
1155            watch_url = \"$url\";
1156         }" > "$ganesha_dir/ganesha-$name.conf"
1157         wconf <<EOF
1158 [ganesha.$name]
1159         host = $HOSTNAME
1160         ip = $IP
1161         port = $port
1162         ganesha data = $ganesha_dir
1163         pid file = $ganesha_dir/ganesha-$name.pid
1164 EOF
1165
1166         prun env CEPH_CONF="${conf_fn}" ganesha-rados-grace --userid $test_user -p $pool_name -n $namespace add $name
1167         prun env CEPH_CONF="${conf_fn}" ganesha-rados-grace --userid $test_user -p $pool_name -n $namespace
1168
1169         prun env CEPH_CONF="${conf_fn}" ganesha.nfsd -L "$CEPH_OUT_DIR/ganesha-$name.log" -f "$ganesha_dir/ganesha-$name.conf" -p "$CEPH_OUT_DIR/ganesha-$name.pid" -N NIV_DEBUG
1170
1171         # Wait few seconds for grace period to be removed
1172         sleep 2
1173
1174         prun env CEPH_CONF="${conf_fn}" ganesha-rados-grace --userid $test_user -p $pool_name -n $namespace
1175
1176         if $with_mgr_dashboard; then
1177             $CEPH_BIN/rados -p $pool_name put "conf-$name" "$ganesha_dir/ganesha-$name.conf"
1178         fi
1179
1180         echo "$test_user ganesha daemon $name started on port: $port"
1181     done
1182
1183     if $with_mgr_dashboard; then
1184         ceph_adm dashboard set-ganesha-clusters-rados-pool-namespace $pool_name
1185     fi
1186 }
1187
1188 if [ "$debug" -eq 0 ]; then
1189     CMONDEBUG='
1190         debug mon = 10
1191         debug ms = 1'
1192 else
1193     debug echo "** going verbose **"
1194     CMONDEBUG='
1195         debug mon = 20
1196         debug paxos = 20
1197         debug auth = 20
1198         debug mgrc = 20
1199         debug ms = 1'
1200 fi
1201
1202 if [ -n "$MON_ADDR" ]; then
1203     CMON_ARGS=" -m "$MON_ADDR
1204     COSD_ARGS=" -m "$MON_ADDR
1205     CMDS_ARGS=" -m "$MON_ADDR
1206 fi
1207
1208 if [ -z "$CEPH_PORT" ]; then
1209     while [ true ]
1210     do
1211         CEPH_PORT="$(echo $(( RANDOM % 1000 + 40000 )))"
1212         ss -a -n | egrep "\<LISTEN\>.+:${CEPH_PORT}\s+" 1>/dev/null 2>&1 || break
1213     done
1214 fi
1215
1216 [ -z "$INIT_CEPH" ] && INIT_CEPH=$CEPH_BIN/init-ceph
1217
1218 # sudo if btrfs
1219 [ -d $CEPH_DEV_DIR/osd0/. ] && [ -e $CEPH_DEV_DIR/sudo ] && SUDO="sudo"
1220
1221 if [ $inc_osd_num -eq 0 ]; then
1222     prun $SUDO rm -f core*
1223 fi
1224
1225 [ -d $CEPH_ASOK_DIR ] || mkdir -p $CEPH_ASOK_DIR
1226 [ -d $CEPH_OUT_DIR  ] || mkdir -p $CEPH_OUT_DIR
1227 [ -d $CEPH_DEV_DIR  ] || mkdir -p $CEPH_DEV_DIR
1228 if [ $inc_osd_num -eq 0 ]; then
1229     $SUDO find "$CEPH_OUT_DIR" -type f -delete
1230 fi
1231 [ -d gmon ] && $SUDO rm -rf gmon/*
1232
1233 [ "$cephx" -eq 1 ] && [ "$new" -eq 1 ] && [ -e $keyring_fn ] && rm $keyring_fn
1234
1235
1236 # figure machine's ip
1237 HOSTNAME=`hostname -s`
1238 if [ -n "$ip" ]; then
1239     IP="$ip"
1240 else
1241     echo hostname $HOSTNAME
1242     if [ -x "$(which ip 2>/dev/null)" ]; then
1243         IP_CMD="ip addr"
1244     else
1245         IP_CMD="ifconfig"
1246     fi
1247     # filter out IPv4 and localhost addresses
1248     IP="$($IP_CMD | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n1)"
1249     # if nothing left, try using localhost address, it might work
1250     if [ -z "$IP" ]; then IP="127.0.0.1"; fi
1251 fi
1252 echo "ip $IP"
1253 echo "port $CEPH_PORT"
1254
1255
1256 [ -z $CEPH_ADM ] && CEPH_ADM=$CEPH_BIN/ceph
1257
1258 ceph_adm() {
1259     if [ "$cephx" -eq 1 ]; then
1260         prun $SUDO "$CEPH_ADM" -c "$conf_fn" -k "$keyring_fn" "$@"
1261     else
1262         prun $SUDO "$CEPH_ADM" -c "$conf_fn" "$@"
1263     fi
1264 }
1265
1266 if [ $inc_osd_num -gt 0 ]; then
1267     start_osd
1268     exit
1269 fi
1270
1271 if [ "$new" -eq 1 ]; then
1272     prepare_conf
1273 fi
1274
1275 if [ $CEPH_NUM_MON -gt 0 ]; then
1276     start_mon
1277
1278     debug echo Populating config ...
1279     cat <<EOF | $CEPH_BIN/ceph -c $conf_fn config assimilate-conf -i -
1280 [global]
1281 osd_pool_default_size = $OSD_POOL_DEFAULT_SIZE
1282 osd_pool_default_min_size = 1
1283
1284 [mon]
1285 mon_osd_reporter_subtree_level = osd
1286 mon_data_avail_warn = 2
1287 mon_data_avail_crit = 1
1288 mon_allow_pool_delete = true
1289 mon_allow_pool_size_one = true
1290
1291 [osd]
1292 osd_scrub_load_threshold = 2000
1293 osd_debug_op_order = true
1294 osd_debug_misdirected_ops = true
1295 osd_copyfrom_max_chunk = 524288
1296
1297 [mds]
1298 mds_debug_frag = true
1299 mds_debug_auth_pins = true
1300 mds_debug_subtrees = true
1301
1302 [mgr]
1303 mgr/telemetry/nag = false
1304 mgr/telemetry/enable = false
1305
1306 EOF
1307
1308     if [ "$debug" -ne 0 ]; then
1309         debug echo Setting debug configs ...
1310         cat <<EOF | $CEPH_BIN/ceph -c $conf_fn config assimilate-conf -i -
1311 [mgr]
1312 debug_ms = 1
1313 debug_mgr = 20
1314 debug_monc = 20
1315 debug_mon = 20
1316
1317 [osd]
1318 debug_ms = 1
1319 debug_osd = 25
1320 debug_objecter = 20
1321 debug_monc = 20
1322 debug_mgrc = 20
1323 debug_journal = 20
1324 debug_filestore = 20
1325 debug_bluestore = 20
1326 debug_bluefs = 20
1327 debug_rocksdb = 20
1328 debug_bdev = 20
1329 debug_reserver = 10
1330 debug_objclass = 20
1331
1332 [mds]
1333 debug_ms = 1
1334 debug_mds = 20
1335 debug_monc = 20
1336 debug_mgrc = 20
1337 mds_debug_scatterstat = true
1338 mds_verify_scatter = true
1339 EOF
1340     fi
1341     if [ "$cephadm" -gt 0 ]; then
1342         debug echo Setting mon public_network ...
1343         public_network=$(ip route list | grep -w "$IP" | awk '{print $1}')
1344         ceph_adm config set mon public_network $public_network
1345     fi
1346 fi
1347
1348 if [ $CEPH_NUM_MGR -gt 0 ]; then
1349     start_mgr
1350 fi
1351
1352 # osd
1353 if [ $CEPH_NUM_OSD -gt 0 ]; then
1354     start_osd
1355 fi
1356
1357 # mds
1358 if [ "$smallmds" -eq 1 ]; then
1359     wconf <<EOF
1360 [mds]
1361         mds log max segments = 2
1362         # Default 'mds cache memory limit' is 1GiB, and here we set it to 100MiB.
1363         mds cache memory limit = 100M
1364 EOF
1365 fi
1366
1367 if [ $CEPH_NUM_MDS -gt 0 ]; then
1368     start_mds
1369     # key with access to all FS
1370     ceph_adm fs authorize \* "client.fs" / rwp >> "$keyring_fn"
1371 fi
1372
1373 # Don't set max_mds until all the daemons are started, otherwise
1374 # the intended standbys might end up in active roles.
1375 if [ "$CEPH_MAX_MDS" -gt 1 ]; then
1376     sleep 5  # wait for daemons to make it into FSMap before increasing max_mds
1377 fi
1378 fs=0
1379 for name in a b c d e f g h i j k l m n o p
1380 do
1381     [ $fs -eq $CEPH_NUM_FS ] && break
1382     fs=$(($fs + 1))
1383     if [ "$CEPH_MAX_MDS" -gt 1 ]; then
1384         ceph_adm fs set "${name}" max_mds "$CEPH_MAX_MDS"
1385     fi
1386 done
1387
1388 # mgr
1389
1390 if [ "$ec" -eq 1 ]; then
1391     ceph_adm <<EOF
1392 osd erasure-code-profile set ec-profile m=2 k=2
1393 osd pool create ec erasure ec-profile
1394 EOF
1395 fi
1396
1397 # Ganesha Daemons
1398 if [ $GANESHA_DAEMON_NUM -gt 0 ]; then
1399     pseudo_path="/cephfs"
1400     if [ "$cephadm" -gt 0 ]; then
1401         cluster_id="vstart"
1402         prun ceph_adm nfs cluster create cephfs $cluster_id
1403         prun ceph_adm nfs export create cephfs "a" $cluster_id $pseudo_path
1404         port="2049"
1405     else
1406         start_ganesha
1407         port="<ganesha-port-num>"
1408     fi
1409     echo "Mount using: mount -t nfs -o port=$port $IP:$pseudo_path mountpoint"
1410 fi
1411
1412 do_cache() {
1413     while [ -n "$*" ]; do
1414         p="$1"
1415         shift
1416         debug echo "creating cache for pool $p ..."
1417         ceph_adm <<EOF
1418 osd pool create ${p}-cache
1419 osd tier add $p ${p}-cache
1420 osd tier cache-mode ${p}-cache writeback
1421 osd tier set-overlay $p ${p}-cache
1422 EOF
1423     done
1424 }
1425 do_cache $cache
1426
1427 do_hitsets() {
1428     while [ -n "$*" ]; do
1429         pool="$1"
1430         type="$2"
1431         shift
1432         shift
1433         debug echo "setting hit_set on pool $pool type $type ..."
1434         ceph_adm <<EOF
1435 osd pool set $pool hit_set_type $type
1436 osd pool set $pool hit_set_count 8
1437 osd pool set $pool hit_set_period 30
1438 EOF
1439     done
1440 }
1441 do_hitsets $hitset
1442
1443 do_rgw_create_users()
1444 {
1445     # Create S3 user
1446     local akey='0555b35654ad1656d804'
1447     local skey='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='
1448     debug echo "setting up user testid"
1449     $CEPH_BIN/radosgw-admin user create --uid testid --access-key $akey --secret $skey --display-name 'M. Tester' --email tester@ceph.com -c $conf_fn > /dev/null
1450
1451     # Create S3-test users
1452     # See: https://github.com/ceph/s3-tests
1453     debug echo "setting up s3-test users"
1454     $CEPH_BIN/radosgw-admin user create \
1455         --uid 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef \
1456         --access-key ABCDEFGHIJKLMNOPQRST \
1457         --secret abcdefghijklmnopqrstuvwxyzabcdefghijklmn \
1458         --display-name youruseridhere \
1459         --email s3@example.com -c $conf_fn > /dev/null
1460     $CEPH_BIN/radosgw-admin user create \
1461         --uid 56789abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234 \
1462         --access-key NOPQRSTUVWXYZABCDEFG \
1463         --secret nopqrstuvwxyzabcdefghijklmnabcdefghijklm \
1464         --display-name john.doe \
1465         --email john.doe@example.com -c $conf_fn > /dev/null
1466     $CEPH_BIN/radosgw-admin user create \
1467         --tenant testx \
1468         --uid 9876543210abcdef0123456789abcdef0123456789abcdef0123456789abcdef \
1469         --access-key HIJKLMNOPQRSTUVWXYZA \
1470         --secret opqrstuvwxyzabcdefghijklmnopqrstuvwxyzab \
1471         --display-name tenanteduser \
1472         --email tenanteduser@example.com -c $conf_fn > /dev/null
1473
1474     # Create Swift user
1475     debug echo "setting up user tester"
1476     $CEPH_BIN/radosgw-admin user create -c $conf_fn --subuser=test:tester --display-name=Tester-Subuser --key-type=swift --secret=testing --access=full > /dev/null
1477
1478     echo ""
1479     echo "S3 User Info:"
1480     echo "  access key:  $akey"
1481     echo "  secret key:  $skey"
1482     echo ""
1483     echo "Swift User Info:"
1484     echo "  account   : test"
1485     echo "  user      : tester"
1486     echo "  password  : testing"
1487     echo ""
1488 }
1489
1490 do_rgw()
1491 {
1492     if [ "$new" -eq 1 ]; then
1493         do_rgw_create_users
1494         if [ -n "$rgw_compression" ]; then
1495             debug echo "setting compression type=$rgw_compression"
1496             $CEPH_BIN/radosgw-admin zone placement modify -c $conf_fn --rgw-zone=default --placement-id=default-placement --compression=$rgw_compression > /dev/null
1497         fi
1498     fi
1499     # Start server
1500     RGWDEBUG=""
1501     if [ "$debug" -ne 0 ]; then
1502         RGWDEBUG="--debug-rgw=20 --debug-ms=1"
1503     fi
1504
1505     local CEPH_RGW_PORT_NUM="${CEPH_RGW_PORT}"
1506     local CEPH_RGW_HTTPS="${CEPH_RGW_PORT: -1}"
1507     if [[ "${CEPH_RGW_HTTPS}" = "s" ]]; then
1508         CEPH_RGW_PORT_NUM="${CEPH_RGW_PORT::-1}"
1509     else
1510         CEPH_RGW_HTTPS=""
1511     fi
1512     RGWSUDO=
1513     [ $CEPH_RGW_PORT_NUM -lt 1024 ] && RGWSUDO=sudo
1514
1515     current_port=$CEPH_RGW_PORT
1516     for n in $(seq 1 $CEPH_NUM_RGW); do
1517         rgw_name="client.rgw.${current_port}"
1518
1519         ceph_adm auth get-or-create $rgw_name \
1520             mon 'allow rw' \
1521             osd 'allow rwx' \
1522             mgr 'allow rw' \
1523             >> "$keyring_fn"
1524
1525         debug echo start rgw on http${CEPH_RGW_HTTPS}://localhost:${current_port}
1526         run 'rgw' $current_port $RGWSUDO $CEPH_BIN/radosgw -c $conf_fn \
1527             --log-file=${CEPH_OUT_DIR}/radosgw.${current_port}.log \
1528             --admin-socket=${CEPH_OUT_DIR}/radosgw.${current_port}.asok \
1529             --pid-file=${CEPH_OUT_DIR}/radosgw.${current_port}.pid \
1530             ${RGWDEBUG} \
1531             -n ${rgw_name} \
1532             "--rgw_frontends=${rgw_frontend} port=${current_port}${CEPH_RGW_HTTPS}"
1533
1534         i=$(($i + 1))
1535         [ $i -eq $CEPH_NUM_RGW ] && break
1536
1537         current_port=$((current_port+1))
1538     done
1539 }
1540 if [ "$CEPH_NUM_RGW" -gt 0 ]; then
1541     do_rgw
1542 fi
1543
1544 debug echo "vstart cluster complete. Use stop.sh to stop. See out/* (e.g. 'tail -f out/????') for debug output."
1545
1546 echo ""
1547 if [ "$new" -eq 1 ]; then
1548     if $with_mgr_dashboard; then
1549         echo "dashboard urls: $DASH_URLS"
1550         echo "  w/ user/pass: admin / admin"
1551     fi
1552     echo "restful urls: $RESTFUL_URLS"
1553     echo "  w/ user/pass: admin / $RESTFUL_SECRET"
1554     echo ""
1555 fi
1556 echo ""
1557 # add header to the environment file
1558 {
1559     echo "#"
1560     echo "# source this file into your shell to set up the environment."
1561     echo "# For example:"
1562     echo "# $ . $CEPH_DIR/vstart_environment.sh"
1563     echo "#"
1564 } > $CEPH_DIR/vstart_environment.sh
1565 {
1566     echo "export PYTHONPATH=$PYBIND:$CYTHON_PYTHONPATH:$CEPH_PYTHON_COMMON\$PYTHONPATH"
1567     echo "export LD_LIBRARY_PATH=$CEPH_LIB:\$LD_LIBRARY_PATH"
1568
1569     if [ "$CEPH_DIR" != "$PWD" ]; then
1570         echo "export CEPH_CONF=$conf_fn"
1571         echo "export CEPH_KEYRING=$keyring_fn"
1572     fi
1573
1574     if [ -n "$CEPHFS_SHELL" ]; then
1575         echo "alias cephfs-shell=$CEPHFS_SHELL"
1576     fi
1577 } | tee -a $CEPH_DIR/vstart_environment.sh
1578
1579 echo "CEPH_DEV=1"
1580
1581 # always keep this section at the very bottom of this file
1582 STRAY_CONF_PATH="/etc/ceph/ceph.conf"
1583 if [ -f "$STRAY_CONF_PATH" -a -n "$conf_fn" -a ! "$conf_fn" -ef "$STRAY_CONF_PATH" ]; then
1584     echo ""
1585     echo ""
1586     echo "WARNING:"
1587     echo "    Please remove stray $STRAY_CONF_PATH if not needed."
1588     echo "    Your conf files $conf_fn and $STRAY_CONF_PATH may not be in sync"
1589     echo "    and may lead to undesired results."
1590     echo ""
1591     echo "NOTE:"
1592     echo "    Remember to restart cluster after removing $STRAY_CONF_PATH"
1593 fi
1594
1595 init_logrotate