Kolla provides production-ready containers and deployment tools for operating OpenStack clouds
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extend_start.sh 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. if [[ ! -d "/var/log/kolla/ceph" ]]; then
  3. mkdir -p /var/log/kolla/ceph
  4. fi
  5. if [[ $(stat -c %a /var/log/kolla/ceph) != "755" ]]; then
  6. chmod 755 /var/log/kolla/ceph
  7. fi
  8. # Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
  9. # of the KOLLA_BOOTSTRAP variable being set, including empty.
  10. if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
  11. # NOTE(SamYaple): Static gpt partcodes
  12. CEPH_JOURNAL_TYPE_CODE="45B0969E-9B03-4F30-B4C6-B4B80CEFF106"
  13. CEPH_OSD_TYPE_CODE="4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D"
  14. CEPH_OSD_BS_WAL_TYPE_CODE="0FC63DAF-8483-4772-8E79-3D69D8477DE4"
  15. CEPH_OSD_BS_DB_TYPE_CODE="CE8DF73C-B89D-45B0-AD98-D45332906d90"
  16. # Wait for ceph quorum before proceeding
  17. ceph quorum_status
  18. if [[ "${USE_EXTERNAL_JOURNAL}" == "False" ]]; then
  19. # Formatting disk for ceph
  20. if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then
  21. if [ -n "${OSD_BS_BLOCK_DEV}" ]; then
  22. sgdisk --zap-all -- "${OSD_BS_BLOCK_DEV}"
  23. sgdisk --new=1:0:+100M --mbrtogpt -- "${OSD_BS_BLOCK_DEV}"
  24. sgdisk --largest-new=2 --mbrtogpt -- "${OSD_BS_BLOCK_DEV}"
  25. sgdisk --zap-all -- "${OSD_BS_BLOCK_DEV}"2
  26. fi
  27. if [ -n "${OSD_BS_WAL_DEV}" ] && [ "${OSD_BS_BLOCK_DEV}" != "${OSD_BS_WAL_DEV}" ] && [ -n "${OSD_BS_WAL_PARTNUM}" ]; then
  28. sgdisk --zap-all -- "${OSD_BS_WAL_DEV}""${OSD_BS_WAL_PARTNUM}"
  29. fi
  30. if [ -n "${OSD_BS_DB_DEV}" ] && [ "${OSD_BS_BLOCK_DEV}" != "${OSD_BS_DB_DEV}" ] && [ -n "${OSD_BS_DB_PARTNUM}" ]; then
  31. sgdisk --zap-all -- "${OSD_BS_DB_DEV}""${OSD_BS_DB_PARTNUM}"
  32. fi
  33. else
  34. sgdisk --zap-all -- "${OSD_DEV}"
  35. sgdisk --new=2:1M:5G -- "${JOURNAL_DEV}"
  36. sgdisk --largest-new=1 -- "${OSD_DEV}"
  37. fi
  38. # NOTE(SamYaple): This command may throw errors that we can safely ignore
  39. partprobe || true
  40. fi
  41. if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then
  42. OSD_UUID=$(uuidgen)
  43. OSD_ID=$(ceph osd new "${OSD_UUID}")
  44. OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"
  45. mkdir -p "${OSD_DIR}"
  46. mkfs.xfs -f "${OSD_BS_BLOCK_DEV}"1
  47. mount "${OSD_BS_BLOCK_DEV}"1 "${OSD_DIR}"
  48. # This will through an error about no key existing. That is normal. It then
  49. # creates the key in the next step.
  50. ceph-osd -i "${OSD_ID}" --mkkey
  51. echo "bluestore" > "${OSD_DIR}"/type
  52. sgdisk "--change-name=2:KOLLA_CEPH_DATA_BS_B_${OSD_ID}" "--typecode=2:${CEPH_OSD_TYPE_CODE}" -- "${OSD_BS_BLOCK_DEV}"
  53. if [ -n "${OSD_BS_WAL_DEV}" ] && [ "${OSD_BS_BLOCK_DEV}" != "${OSD_BS_WAL_DEV}" ] && [ -n "${OSD_BS_WAL_PARTNUM}" ]; then
  54. sgdisk "--change-name="${OSD_BS_WAL_PARTNUM}":KOLLA_CEPH_DATA_BS_W_${OSD_ID}" "--typecode=1:${CEPH_OSD_BS_WAL_TYPE_CODE}" -- "${OSD_BS_WAL_DEV}"
  55. fi
  56. if [ -n "${OSD_BS_DB_DEV}" ] && [ "${OSD_BS_BLOCK_DEV}" != "${OSD_BS_DB_DEV}" ] && [ -n "${OSD_BS_DB_PARTNUM}" ]; then
  57. sgdisk "--change-name="${OSD_BS_DB_PARTNUM}":KOLLA_CEPH_DATA_BS_D_${OSD_ID}" "--typecode=1:${CEPH_OSD_BS_DB_TYPE_CODE}" -- "${OSD_BS_DB_DEV}"
  58. fi
  59. partprobe || true
  60. ln -sf /dev/disk/by-partlabel/KOLLA_CEPH_DATA_BS_B_"${OSD_ID}" "${OSD_DIR}"/block
  61. if [ -n "${OSD_BS_WAL_DEV}" ] && [ "${OSD_BS_BLOCK_DEV}" != "${OSD_BS_WAL_DEV}" ] && [ -n "${OSD_BS_WAL_PARTNUM}" ]; then
  62. ln -sf /dev/disk/by-partlabel/KOLLA_CEPH_DATA_BS_W_"${OSD_ID}" "${OSD_DIR}"/block.wal
  63. fi
  64. if [ -n "${OSD_BS_DB_DEV}" ] && [ "${OSD_BS_BLOCK_DEV}" != "${OSD_BS_DB_DEV}" ]i && [ -n "${OSD_BS_DB_PARTNUM}" ]; then
  65. ln -sf /dev/disk/by-partlabel/KOLLA_CEPH_DATA_BS_D_"${OSD_ID}" "${OSD_DIR}"/block.db
  66. fi
  67. ceph-osd -i "${OSD_ID}" --mkfs -k "${OSD_DIR}"/keyring --osd-uuid "${OSD_UUID}"
  68. ceph auth add "osd.${OSD_ID}" osd 'allow *' mon 'allow profile osd' -i "${OSD_DIR}/keyring"
  69. umount "${OSD_BS_BLOCK_DEV}"1
  70. else
  71. OSD_ID=$(ceph osd create)
  72. OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"
  73. mkdir -p "${OSD_DIR}"
  74. if [[ "${OSD_FILESYSTEM}" == "btrfs" ]]; then
  75. mkfs.btrfs -f "${OSD_PARTITION}"
  76. elif [[ "${OSD_FILESYSTEM}" == "ext4" ]]; then
  77. mkfs.ext4 "${OSD_PARTITION}"
  78. else
  79. mkfs.xfs -f "${OSD_PARTITION}"
  80. fi
  81. mount "${OSD_PARTITION}" "${OSD_DIR}"
  82. # This will through an error about no key existing. That is normal. It then
  83. # creates the key in the next step.
  84. ceph-osd -i "${OSD_ID}" --mkfs --osd-journal="${JOURNAL_PARTITION}" --mkkey
  85. ceph auth add "osd.${OSD_ID}" osd 'allow *' mon 'allow profile osd' -i "${OSD_DIR}/keyring"
  86. umount "${OSD_PARTITION}"
  87. fi
  88. if [[ "${!CEPH_CACHE[@]}" ]]; then
  89. CEPH_ROOT_NAME=cache
  90. fi
  91. if [[ "${OSD_INITIAL_WEIGHT}" == "auto" ]]; then
  92. OSD_INITIAL_WEIGHT=$(parted --script ${OSD_PARTITION} unit TB print | awk 'match($0, /^Disk.* (.*)TB/, a){printf("%.2f", a[1])}')
  93. fi
  94. # These commands only need to be run once per host but are safe to run
  95. # repeatedly. This can be improved later or if any problems arise.
  96. ceph osd crush add-bucket "${HOSTNAME}${CEPH_ROOT_NAME:+-${CEPH_ROOT_NAME}}" host
  97. ceph osd crush move "${HOSTNAME}${CEPH_ROOT_NAME:+-${CEPH_ROOT_NAME}}" root=${CEPH_ROOT_NAME:-default}
  98. # Adding osd to crush map
  99. ceph osd crush add "${OSD_ID}" "${OSD_INITIAL_WEIGHT}" host="${HOSTNAME}${CEPH_ROOT_NAME:+-${CEPH_ROOT_NAME}}"
  100. # Setting partition name based on ${OSD_ID}
  101. if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then
  102. sgdisk "--change-name=1:KOLLA_CEPH_BSDATA_${OSD_ID}" -- "${OSD_BS_BLOCK_DEV}"
  103. else
  104. sgdisk "--change-name=${OSD_PARTITION_NUM}:KOLLA_CEPH_DATA_${OSD_ID}" "--typecode=${OSD_PARTITION_NUM}:${CEPH_OSD_TYPE_CODE}" -- "${OSD_DEV}"
  105. sgdisk "--change-name=${JOURNAL_PARTITION_NUM}:KOLLA_CEPH_DATA_${OSD_ID}_J" "--typecode=${JOURNAL_PARTITION_NUM}:${CEPH_JOURNAL_TYPE_CODE}" -- "${JOURNAL_DEV}"
  106. fi
  107. partprobe || true
  108. exit 0
  109. fi
  110. OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}"
  111. if [[ "${OSD_STORETYPE}" == "bluestore" ]]; then
  112. ARGS="-i ${OSD_ID}"
  113. else
  114. ARGS="-i ${OSD_ID} --osd-journal ${JOURNAL_PARTITION} -k ${OSD_DIR}/keyring"
  115. fi