scripts/ceph/remove.lvm-osd

78 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# This script intend to generate another temp script with the differents
# commands to remove a Ceph-OSD previously generated with `ceph-volume lvm`
# Give the OSD number to remove as first argument
OSD_ID_TO_REMOVE="${1}"
## Colors definition {{{
BLACK='\033[49;30m'
BLACKB='\033[49;90m'
RED='\033[0;31m'
REDB='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[94;49m'
MAGENTA='\033[0;35m'
CYAN='\033[36;49m'
WHITE='\033[0;37m'
BOLD='\033[1m'
RESET='\033[0m'
## }}}
# Test the first argument
if [ -z "${OSD_ID_TO_REMOVE}" ]; then
printf '%b\n' "${REDB}You should give the OSD_ID to remove as first argument.${RESET}"
exit 1
fi
# Path of the temp generated script
temp_script="/tmp/lvm-osd.to.remove.sh"
# Get all informations
osd_path="/var/lib/ceph/osd/ceph-${OSD_ID_TO_REMOVE}"
lv_path=$(file /var/lib/ceph/osd/ceph-"${OSD_ID_TO_REMOVE}"/block | cut -d" " -f5)
vg_name=$(lvs --noheadings -o vg_name "${lv_path}" | tr -d ' ')
pv_path=$(lvs --noheadings -o devices "${lv_path}" | sed 's;.*\(/dev/...\).*;\1;')
# Tests {{{
# }}}
printf '%b\n' "OSD path to umount then to remove: ${REDB}${osd_path}${RESET}"
printf '%b\n' "OSD_ID to remove: ${REDB}${OSD_ID_TO_REMOVE}${RESET}"
if [ ! -L "${lv_path}" ]; then
printf '%b\n' "The logical volume doesn't seems to exists."
printf '%b\n' "${REDB}It might be better to manually purge the OSD.${RESET}"
else
printf '%b\n' "Logical Volume to remove: ${REDB}${lv_path}${RESET}"
fi
printf '%b\n' "Volume Group to remove: ${REDB}${vg_name}${RESET}"
printf '%b\n' "Physical volume to remove: ${REDB}${pv_path}${RESET}"
# Generate a temp script with the expected commands
rm -rf -- "${temp_script}"
touch -- "${temp_script}"
printf '%b\n' "#!/bin/sh" >> "${temp_script}"
## Umount the OSD
printf '%b\n' "umount ${osd_path}" >> "${temp_script}"
## Remove mount path
printf '%b\n' "rmdir -- ${osd_path}" >> "${temp_script}"
## Remove the LV
printf '%b\n' "lvremove ${lv_path}" >> "${temp_script}"
## Remove the VG
printf '%b\n' "vgremove ${vg_name}" >> "${temp_script}"
## Remove the PV
printf '%b\n' "pvremove ${pv_path}" >> "${temp_script}"
printf '%b\n' "A temp script with expected commands is available to: ${GREEN}${temp_script}${RESET}"
exit 0