#!/bin/bash
merge_num=-2
split_num=16
while [[ "$(ceph health)" != "HEALTH_OK" ]]; do
sleep 10
done
# Some method to set your ceph.conf file to the subfolder splitting settings you want.
# If you are not changing the ceph.conf settings, then you can start the osd at the end of the loop instead of at the end.
conf=/etc/ceph/ceph.conf
if ! grep -q '^\[global\]' $conf; then
echo $conf is badly formed
exit
fi
merge=$(grep -E filestore.merge.threshold $conf)
merge=${merge:-false}
split=$(grep -E filestore.split.multiple $conf)
split=${split:-false}
if [[ "$merge" != false ]]; then
sudo sed -i "/filestore.merge.threshold/c filestore_merge_threshold = $merge_num" $conf
else
sudo sed -i "/^\[global\]/a filestore_merge_threshold = $merge_num" $conf
fi
if [[ "$split" != false ]]; then
sudo sed -i "/filestore.split.multiple/c filestore_split_multiple = $split_num" $conf
else
sudo sed -i "/^\[global\]/a filestore_split_multiple = $split_num" $conf
fi
ceph osd set noout
#sudo systemctl stop ceph.target && sleep 30
/etc/init.d/ceph stop osd && sleep 30
for osd in $(sudo mount | grep -Eo ceph-[0-9]+ | cut -d- -f2 | sort -nu); do
for run_in_background in true; do
echo "Starting osd $osd"
sudo -u ceph ceph-osd --flush-journal -i=${osd}
for pool in $(ceph osd lspools | awk 'BEGIN {RS=","} {print $2}'); do
sudo -u ceph ceph-objectstore-tool --data-path /var/lib/ceph/osd/ceph-${osd} \
--journal-path /var/lib/ceph/osd/ceph-${osd}/journal \
--log-file=/var/log/ceph/objectstore_tool.${osd}.log \
--op apply-layout-settings \
--pool $pool \
--debug
done
echo "Finished osd.${osd}"
# sudo systemctl start ceph-osd@${osd}.service
done &
done
wait
# set ceph.conf back to normal before starting the OSDs
if [[ "$merge" != false ]]; then
sudo sed -i "/filestore.merge.threshold/c \\${merge}" $conf
else
sudo sed -i "/filestore.merge.threshold/d" $conf
fi
if [[ "$split" != false ]]; then
sudo sed -i "/filestore.split.multiple/c \\${split}" $conf
else
sudo sed -i "/filestore.merge.multiple/d" $conf
fi
echo starting OSDs
# sudo systemctl start ceph.target
/etc/init.d/ceph start osd
#while true; do
# stat=$(ceph osd stat)
# up=$(echo "$stat" | grep -Eo '[[:digit:]]+\s+up' | awk '{print $1}')
# in=$(echo "$stat" | grep -Eo '[[:digit:]]+\s+in' | awk '{print $1}')
# if (( $up == $in )); then
# ceph tell osd.\* injectargs --osd_max_backfills=1
# #ceph osd unset noout
# break
# else
# sleep 10
# fi
#done