From ColdSphinX, 2 Years ago, written in Bash.
Embed
  1. #!/bin/bash
  2. mon_host=mon01.example.com
  3. cluster=ceph
  4.  
  5. osd_host=$1
  6.  
  7. [ -z $osd_host ] && exit 1
  8.  
  9. ssh_osd() {
  10.   ssh root@$osd_host "$*"
  11. }
  12.  
  13. ssh_mon() {
  14.   ssh root@$mon_host "$*"
  15. }
  16.  
  17. recreate_dev() {
  18.   id=$1
  19.   dev=$2
  20.   ssh_osd "systemctl stop ceph-osd@${id}"
  21.   ssh_mon "ceph osd down ${id}"
  22.   ssh_mon "ceph osd out ${id}"
  23.   sleep 1
  24.   ssh_mon "ceph osd destroy ${id} --yes-i-really-mean-it"
  25.   sleep 1
  26.   ssh_osd "ceph-volume lvm zap ${dev}"
  27.   ssh_osd "ceph-volume lvm create --osd-id ${id} --data ${dev}"
  28. }
  29.  
  30. get_num_osds() {
  31.   ssh_osd "mount | grep -v tmpfs | grep 'osd/${cluster}' | awk '{printf \"%s %s\n\",\$1,\$3}' | sed 's_/var/lib/ceph/osd/${cluster}-__g' | wc -l"
  32. }
  33.  
  34. get_next_osd() {
  35.   ssh_osd "mount | grep -v tmpfs | grep 'osd/${cluster}' | awk '{printf \"%s %s\n\",\$1,\$3}' | sed 's_/var/lib/ceph/osd/${cluster}-__g' | sort -u | head -n 1"
  36. }
  37.  
  38. for i in $(seq 1 `get_num_osds` )
  39. do
  40.   osd=$(get_next_osd)
  41.   dev=$(echo $osd | awk '{print $1}')
  42.   dev=${dev/[0-9]/}
  43.   id=$(echo $osd | awk '{print $2}')
  44.   echo "$i: id{$id} dev{$dev}"
  45.   recreate_dev $id $dev
  46. done
  47.