Merge "Add integration with Manila CephFS Native driver"
[apex-tripleo-heat-templates.git] / extraconfig / tasks / major_upgrade_ceph_storage.sh
1 #!/bin/bash
2 #
3 # This delivers the ceph-storage upgrade script to be invoked as part of the tripleo
4 # major upgrade workflow.
5 #
6 set -eu
7 set -o pipefail
8
9 UPGRADE_SCRIPT=/root/tripleo_upgrade_node.sh
10
11 cat > $UPGRADE_SCRIPT << 'ENDOFCAT'
12 #!/bin/bash
13 ### DO NOT MODIFY THIS FILE
14 ### This file is automatically delivered to the ceph-storage nodes as part of the
15 ### tripleo upgrades workflow
16 set -eu
17
18 echo INFO: starting $(basename "$0")
19
20 # Exit if not running
21 if ! pidof ceph-osd; then
22     echo INFO: ceph-osd is not running, skipping
23     exit 0
24 fi
25
26 # Exit if not Hammer
27 INSTALLED_VERSION=$(ceph --version | awk '{print $3}')
28 if ! [[ "$INSTALLED_VERSION" =~ ^0\.94.* ]]; then
29     echo INFO: version of Ceph installed is not 0.94, skipping
30     exit 0
31 fi
32
33 OSD_PIDS=$(pidof ceph-osd)
34 OSD_IDS=$(ls /var/lib/ceph/osd | awk 'BEGIN { FS = "-" } ; { print $2 }')
35
36 # "so that mirrors aren't rebalanced as if the OSD died" - gfidente / leseb
37 ceph osd set noout
38 ceph osd set norebalance
39 ceph osd set nodeep-scrub
40 ceph osd set noscrub
41
42 # Stop daemon using Hammer sysvinit script
43 for OSD_ID in $OSD_IDS; do
44     service ceph stop osd.${OSD_ID}
45 done
46
47 # Nice guy will return non-0 only when all failed
48 timeout 60 bash -c "while kill -0 ${OSD_PIDS} 2> /dev/null; do
49   sleep 2;
50 done"
51
52 # Update (Ceph to Jewel)
53 yum -y install python-zaqarclient  # needed for os-collect-config
54 yum -y update
55
56 # Restart/Exit if not on Jewel, only in that case we need the changes
57 UPDATED_VERSION=$(ceph --version | awk '{print $3}')
58 if [[ "$UPDATED_VERSION" =~ ^0\.94.* ]]; then
59     echo WARNING: Ceph was not upgraded, restarting daemon
60     for OSD_ID in $OSD_IDS; do
61         service ceph start osd.${OSD_ID}
62     done
63 elif [[ "$UPDATED_VERSION" =~ ^10\.2.* ]]; then
64     # RPM could own some of these but we can't take risks on the pre-existing files
65     for d in /var/lib/ceph/osd /var/log/ceph /var/run/ceph /etc/ceph; do
66         chown -R ceph:ceph $d || echo WARNING: chown of $d failed
67     done
68
69     # Replay udev events with newer rules
70     udevadm trigger && udevadm settle
71
72     # Enable systemd unit
73     systemctl enable ceph-osd.target
74     for OSD_ID in $OSD_IDS; do
75         systemctl enable ceph-osd@${OSD_ID}
76         systemctl start ceph-osd@${OSD_ID}
77     done
78
79     echo INFO: Ceph was upgraded to Jewel
80 else
81     echo ERROR: Ceph was upgraded to an unknown release, daemon is stopped, need manual intervention
82     exit 1
83 fi
84
85 ceph osd unset noout
86 ceph osd unset norebalance
87 ceph osd unset nodeep-scrub
88 ceph osd unset noscrub
89 ENDOFCAT
90
91 # ensure the permissions are OK
92 chmod 0755 $UPGRADE_SCRIPT