#!/usr/bin/env bash set -Eeuo pipefail umask 077 : "${CLUSTER_NAME:?set CLUSTER_NAME}" CEPHMIG_OSD_GIB=${CEPHMIG_OSD_GIB:-4} if [[ ! $CEPHMIG_OSD_GIB =~ ^[0-9]+$ ]] || ((10#$CEPHMIG_OSD_GIB < 4 || 10#$CEPHMIG_OSD_GIB > 64)); then echo 'CEPHMIG_OSD_GIB must be an integer between 4 and 64' >&2; exit 1 fi block_bytes=$((10#$CEPHMIG_OSD_GIB * 1024 * 1024 * 1024)) rm -f /run/cephmig-ready mkdir -p /state/{mon,osd,mgr,mds} /etc/ceph /run/ceph pids=() cleanup() { trap - EXIT TERM INT rm -f /run/cephmig-ready if ((${#pids[@]})); then kill "${pids[@]}" 2>/dev/null || true wait "${pids[@]}" 2>/dev/null || true fi } trap cleanup EXIT trap 'exit 0' TERM INT start() { "$@" & pids+=("$!"); } retry() { local attempt for ((attempt=0; attempt<90; attempt++)); do if "$@"; then return 0; fi sleep 2 done echo "Timeout: $*" >&2 return 1 } if [[ ! -f /state/fsid ]]; then cat /proc/sys/kernel/random/uuid > /state/fsid; fi ip=$(hostname -i | awk '{print $1}') cat > /etc/ceph/ceph.conf < /state/osd-uuid; fi ceph osd new "$(cat /state/osd-uuid)" 0 ceph-osd -i 0 --mkfs --mkkey --osd-uuid "$(cat /state/osd-uuid)" --no-mon-config fi ceph auth add osd.0 osd 'allow *' mon 'allow profile osd' mgr 'allow profile osd' \ -i /state/osd/keyring start ceph-osd -i 0 -f retry bash -c 'ceph osd stat --format json | python3 -c '\''import json,sys; s=json.load(sys.stdin); sys.exit(s["num_up_osds"] != 1)'\''' ceph auth get-or-create mds.a mon 'allow profile mds' mgr 'allow profile mds' \ osd 'allow rw tag cephfs *=*' mds 'allow' -o /state/mds/keyring start ceph-mds -i a -f # Explicit PG counts avoid an EINVAL in Umbrella's volume-create pool defaults. retry ceph osd pool create cephfs.cephfs.meta 8 retry ceph osd pool create cephfs.cephfs.data 8 retry ceph fs new cephfs cephfs.cephfs.meta cephfs.cephfs.data retry ceph fs subvolumegroup create cephfs migration retry ceph fs subvolume create cephfs demo --group_name migration ceph fs subvolume getpath cephfs demo --group_name migration > /etc/ceph/subvolume-path touch /run/cephmig-ready echo "Cluster $CLUSTER_NAME ready" wait -n "${pids[@]}" exit 1