21a2b5bcd8aa6b063df2bb6dfeb2b96fc6aed6d0
[apex-tripleo-heat-templates.git] / extraconfig / tasks / major_upgrade_ceph_mon.sh
1 #!/bin/bash
2 set -eu
3 set -o pipefail
4
5 echo INFO: starting $(basename "$0")
6
7 # Exit if not running
8 if ! pidof ceph-mon; then
9     echo INFO: ceph-mon is not running, skipping
10     exit 0
11 fi
12
13 # Exit if not Hammer
14 INSTALLED_VERSION=$(ceph --version | awk '{print $3}')
15 if ! [[ "$INSTALLED_VERSION" =~ ^0\.94.* ]]; then
16     echo INFO: version of Ceph installed is not 0.94, skipping
17     exit 0
18 fi
19
20 CEPH_STATUS=$(ceph health | awk '{print $1}')
21 if [ ${CEPH_STATUS} = HEALTH_ERR ]; then
22     echo ERROR: Ceph cluster status is HEALTH_ERR, cannot be upgraded
23     exit 1
24 fi
25
26 # Useful when upgrading with OSDs num < replica size
27 if [ ${ignore_ceph_upgrade_warnings:-false} != "true" ]; then
28     timeout 300 bash -c "while [ ${CEPH_STATUS} != HEALTH_OK ]; do
29       echo WARNING: Waiting for Ceph cluster status to go HEALTH_OK;
30       sleep 30;
31       CEPH_STATUS=$(ceph health | awk '{print $1}')
32     done"
33 fi
34
35 MON_PID=$(pidof ceph-mon)
36 MON_ID=$(hostname -s)
37
38 # Stop daemon using Hammer sysvinit script
39 service ceph stop mon.${MON_ID}
40
41 # Ensure it's stopped
42 timeout 60 bash -c "while kill -0 ${MON_PID} 2> /dev/null; do
43   sleep 2;
44 done"
45
46 # Update to Jewel
47 yum -y -q update ceph-mon ceph
48
49 # Restart/Exit if not on Jewel, only in that case we need the changes
50 UPDATED_VERSION=$(ceph --version | awk '{print $3}')
51 if [[ "$UPDATED_VERSION" =~ ^0\.94.* ]]; then
52     echo WARNING: Ceph was not upgraded, restarting daemons
53     service ceph start mon.${MON_ID}
54 elif [[ "$UPDATED_VERSION" =~ ^10\.2.* ]]; then
55     # RPM could own some of these but we can't take risks on the pre-existing files
56     for d in /var/lib/ceph/mon /var/log/ceph /var/run/ceph /etc/ceph; do
57         chown -R ceph:ceph $d || echo WARNING: chown of $d failed
58     done
59
60     # Replay udev events with newer rules
61     udevadm trigger
62
63     # Enable systemd unit
64     systemctl enable ceph-mon.target
65     systemctl enable ceph-mon@${MON_ID}
66     systemctl start ceph-mon@${MON_ID}
67
68     # Wait for daemon to be back in the quorum
69     timeout 300 bash -c "until (ceph quorum_status | jq .quorum_names | grep -sq ${MON_ID}); do
70       echo WARNING: Waiting for mon.${MON_ID} to re-join quorum;
71       sleep 10;
72     done"
73
74     echo INFO: Ceph was upgraded to Jewel
75 else
76     echo ERROR: Ceph was upgraded to an unknown release, daemon is stopped, need manual intervention
77     exit 1
78 fi