2017-04-04 01:55:11 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
RETRIES="{{ handler_health_osd_check_retries }}"
|
|
|
|
DELAY="{{ handler_health_osd_check_delay }}"
|
|
|
|
CEPH_CLI="--name client.bootstrap-osd --keyring /var/lib/ceph/bootstrap-osd/{{ cluster }}.keyring --cluster {{ cluster }}"
|
|
|
|
|
|
|
|
check_pgs() {
|
|
|
|
while [ $RETRIES -ne 0 ]; do
|
2017-06-22 23:42:03 +08:00
|
|
|
test "[""$(ceph $CEPH_CLI -s -f json | python -c 'import sys, json; print(json.load(sys.stdin)["pgmap"]["num_pgs"])')""]" = "$(ceph $CEPH_CLI -s -f json | python -c 'import sys, json; print [ i["count"] for i in json.load(sys.stdin)["pgmap"]["pgs_by_state"] if i["state_name"] == "active+clean"]')"
|
2017-04-04 01:55:11 +08:00
|
|
|
RET=$?
|
2017-06-12 16:30:22 +08:00
|
|
|
test $RET -eq 0 && return 0
|
2017-04-04 01:55:11 +08:00
|
|
|
sleep $DELAY
|
|
|
|
let RETRIES=RETRIES-1
|
|
|
|
done
|
|
|
|
# PGs not clean, exiting with return code 1
|
2017-05-12 23:01:03 +08:00
|
|
|
echo "Error while running 'ceph $CEPH_CLI -s', PGs were not reported as active+clean"
|
|
|
|
echo "It is possible that the cluster has less OSDs than the replica configuration"
|
|
|
|
echo "Will refuse to continue"
|
|
|
|
ceph $CEPH_CLI -s
|
2017-04-04 01:55:11 +08:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
for id in $(ls /var/lib/ceph/osd/ | sed 's/.*-//'); do
|
|
|
|
# First, restart daemon(s)
|
|
|
|
systemctl restart ceph-osd@${id}
|
|
|
|
# We need to wait because it may take some time for the socket to actually exists
|
|
|
|
COUNT=10
|
|
|
|
# Wait and ensure the socket exists after restarting the daemon
|
|
|
|
SOCKET=/var/run/ceph/{{ cluster }}-osd.${id}.asok
|
|
|
|
while [ $COUNT -ne 0 ]; do
|
2017-06-12 16:30:22 +08:00
|
|
|
test -S $SOCKET && check_pgs && continue 2
|
2017-04-04 01:55:11 +08:00
|
|
|
sleep 1
|
|
|
|
let COUNT=COUNT-1
|
|
|
|
done
|
|
|
|
# If we reach this point, it means the socket is not present.
|
2017-04-18 18:40:43 +08:00
|
|
|
echo "Socket file ${SOCKET} could not be found, which means the osd daemon is not running."
|
2017-04-04 01:55:11 +08:00
|
|
|
exit 1
|
|
|
|
done
|