Skip to content
Snippets Groups Projects
extend_start.sh 2.49 KiB
Newer Older
  • Learn to ignore specific revisions
  • rthallisey's avatar
    rthallisey committed
    #!/bin/bash
    
    # Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
    # of the KOLLA_BOOTSTRAP variable being set, including empty.
    if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
    
        # NOTE(SamYaple): Static gpt partcodes
        CEPH_JOURNAL_TYPE_CODE="45B0969E-9B03-4F30-B4C6-B4B80CEFF106"
        CEPH_OSD_TYPE_CODE="4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D"
    
    
        # Wait for ceph quorum before proceeding
        ceph quorum_status
    
    
        if [[ "${USE_EXTERNAL_JOURNAL}" == "False" ]]; then
            # Formatting disk for ceph
            sgdisk --zap-all -- "${OSD_DEV}"
            sgdisk --new=2:1M:5G -- "${JOURNAL_DEV}"
            sgdisk --largest-new=1 -- "${OSD_DEV}"
            # NOTE(SamYaple): This command may throw errors that we can safely ignore
            partprobe || true
    
    Sam Yaple's avatar
    Sam Yaple committed
    
    
    rthallisey's avatar
    rthallisey committed
    
    
        OSD_ID=$(ceph osd create)
    
    rthallisey's avatar
    rthallisey committed
        OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"
        mkdir -p "${OSD_DIR}"
    
    
        if [[ "${OSD_FILESYSTEM}" == "btrfs" ]]; then
            mkfs.btrfs -f "${OSD_PARTITION}"
        elif [[ "${OSD_FILESYSTEM}" == "ext4" ]]; then
            mkfs.ext4 "${OSD_PARTITION}"
        else
            mkfs.xfs -f "${OSD_PARTITION}"
        fi
    
    Sam Yaple's avatar
    Sam Yaple committed
        mount "${OSD_PARTITION}" "${OSD_DIR}"
    
    rthallisey's avatar
    rthallisey committed
    
    
    Sam Yaple's avatar
    Sam Yaple committed
        # This will through an error about no key existing. That is normal. It then
        # creates the key in the next step.
        ceph-osd -i "${OSD_ID}" --mkfs --osd-journal="${JOURNAL_PARTITION}" --mkkey
        ceph auth add "osd.${OSD_ID}" osd 'allow *' mon 'allow profile osd' -i "${OSD_DIR}/keyring"
        umount "${OSD_PARTITION}"
    
    
        if [[ "${!CEPH_CACHE[@]}" ]]; then
            CEPH_ROOT_NAME=cache
        fi
    
    
    Sam Yaple's avatar
    Sam Yaple committed
        # These commands only need to be run once per host but are safe to run
        # repeatedly. This can be improved later or if any problems arise.
    
    SamYaple's avatar
    SamYaple committed
        ceph osd crush add-bucket "${HOSTNAME}${CEPH_ROOT_NAME:+-${CEPH_ROOT_NAME}}" host
        ceph osd crush move "${HOSTNAME}${CEPH_ROOT_NAME:+-${CEPH_ROOT_NAME}}" root=${CEPH_ROOT_NAME:-default}
    
    Sam Yaple's avatar
    Sam Yaple committed
    
        # Adding osd to crush map
    
    SamYaple's avatar
    SamYaple committed
        ceph osd crush add "${OSD_ID}" "${OSD_INITIAL_WEIGHT}" host="${HOSTNAME}${CEPH_ROOT_NAME:+-${CEPH_ROOT_NAME}}"
    
    
        # Setting partition name based on ${OSD_ID}
        sgdisk "--change-name=${OSD_PARTITION_NUM}:KOLLA_CEPH_DATA_${OSD_ID}" "--typecode=${OSD_PARTITION_NUM}:${CEPH_OSD_TYPE_CODE}" -- "${OSD_DEV}"
        sgdisk "--change-name=${JOURNAL_PARTITION_NUM}:KOLLA_CEPH_DATA_${OSD_ID}_J" "--typecode=${JOURNAL_PARTITION_NUM}:${CEPH_JOURNAL_TYPE_CODE}" -- "${JOURNAL_DEV}"
    
    
    rthallisey's avatar
    rthallisey committed
        exit 0
    fi
    
    
    Sam Yaple's avatar
    Sam Yaple committed
    OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"
    
    Sam Yaple's avatar
    Sam Yaple committed
    ARGS="-i ${OSD_ID} --osd-journal ${JOURNAL_PARTITION} -k ${OSD_DIR}/keyring"