Merge "Upgrade ceph-mon"
[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 MON_PID=$(pidof ceph-mon)
21 MON_ID=$(hostname -s)
22
23 # Stop daemon using Hammer sysvinit script
24 service ceph stop mon.${MON_ID}
25
26 # Ensure it's stopped
27 timeout 60 bash -c "while kill -0 ${MON_PID} 2> /dev/null; do
28   sleep 2;
29 done"
30
31 # Update to Jewel
32 yum -y -q update ceph-mon
33
34 # Restart/Exit if not on Jewel, only in that case we need the changes
35 UPDATED_VERSION=$(ceph --version | awk '{print $3}')
36 if [[ "$UPDATED_VERSION" =~ ^0\.94.* ]]; then
37     echo WARNING: Ceph was not upgraded, restarting daemons
38     service ceph start mon.${MON_ID}
39 elif [[ "$UPDATED_VERSION" =~ ^10\.2.* ]]; then
40     echo INFO: Ceph was upgraded to Jewel
41
42     # RPM could own some of these but we can't take risks on the pre-existing files
43     for d in /var/lib/ceph/mon /var/log/ceph /var/run/ceph /etc/ceph; do
44         chown -R ceph:ceph $d
45     done
46
47     # Replay udev events with newer rules
48     udevadm trigger
49
50     # Enable systemd unit
51     systemctl enable ceph-mon.target
52     systemctl enable ceph-mon@${MON_ID}
53     systemctl start ceph-mon@${MON_ID}
54
55     # Wait for daemon to be back in the quorum
56     timeout 300 bash -c "until (ceph quorum_status | jq .quorum_names | grep -sq ${MON_ID}); do
57       echo Waiting for mon.${MON_ID} to re-join quorum;
58       sleep 10;
59     done"
60 else
61     echo ERROR: Ceph was upgraded to an unknown release, daemon is stopped, need manual intervention
62     exit 1
63 fi