Merge "Add deployed server bootstrap to noop-ctlplane"
[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 declare -f special_case_ovs_upgrade_if_needed > $UPGRADE_SCRIPT
12 # use >> here so we don't lose the declaration we added above
13 cat >> $UPGRADE_SCRIPT << 'ENDOFCAT'
14 #!/bin/bash
15 ### DO NOT MODIFY THIS FILE
16 ### This file is automatically delivered to the ceph-storage nodes as part of the
17 ### tripleo upgrades workflow
18 set -eu
19
20 echo INFO: starting $(basename "$0")
21
22 # Exit if not running
23 if ! pidof ceph-osd &> /dev/null; then
24     echo INFO: ceph-osd is not running, skipping
25     exit 0
26 fi
27
28 # Exit if not Hammer
29 INSTALLED_VERSION=$(ceph --version | awk '{print $3}')
30 if ! [[ "$INSTALLED_VERSION" =~ ^0\.94.* ]]; then
31     echo INFO: version of Ceph installed is not 0.94, skipping
32     exit 0
33 fi
34
35 OSD_PIDS=$(pidof ceph-osd)
36 OSD_IDS=$(ls /var/lib/ceph/osd | awk 'BEGIN { FS = "-" } ; { print $2 }')
37
38 # "so that mirrors aren't rebalanced as if the OSD died" - gfidente / leseb
39 ceph osd set noout
40 ceph osd set norebalance
41 ceph osd set nodeep-scrub
42 ceph osd set noscrub
43
44 # Stop daemon using Hammer sysvinit script
45 for OSD_ID in $OSD_IDS; do
46     service ceph stop osd.${OSD_ID}
47 done
48
49 # Nice guy will return non-0 only when all failed
50 timeout 60 bash -c "while kill -0 ${OSD_PIDS} 2> /dev/null; do
51   sleep 2;
52 done"
53
54 special_case_ovs_upgrade_if_needed
55
56 # Update (Ceph to Jewel)
57 yum -y install python-zaqarclient  # needed for os-collect-config
58 yum -y update
59
60 # Restart/Exit if not on Jewel, only in that case we need the changes
61 UPDATED_VERSION=$(ceph --version | awk '{print $3}')
62 if [[ "$UPDATED_VERSION" =~ ^0\.94.* ]]; then
63     echo WARNING: Ceph was not upgraded, restarting daemon
64     for OSD_ID in $OSD_IDS; do
65         service ceph start osd.${OSD_ID}
66     done
67 elif [[ "$UPDATED_VERSION" =~ ^10\.2.* ]]; then
68     # RPM could own some of these but we can't take risks on the pre-existing files
69     for d in /var/lib/ceph/osd /var/log/ceph /var/run/ceph /etc/ceph; do
70         chown -L -R ceph:ceph $d || echo WARNING: chown of $d failed
71     done
72
73     # Replay udev events with newer rules
74     udevadm trigger && udevadm settle
75
76     # If on ext4, we need to enforce lower values for name and namespace len
77     # or ceph-osd will refuse to start, see: http://tracker.ceph.com/issues/16187
78     for OSD_ID in $OSD_IDS; do
79       OSD_FS=$(df -l --output=fstype /var/lib/ceph/osd/ceph-${OSD_ID} | tail -n +2)
80       if [ ${OSD_FS} = ext4 ]; then
81         crudini --set /etc/ceph/ceph.conf global osd_max_object_name_len 256
82         crudini --set /etc/ceph/ceph.conf global osd_max_object_namespace_len 64
83       fi
84     done
85
86     # Enable systemd unit
87     systemctl enable ceph-osd.target
88     for OSD_ID in $OSD_IDS; do
89         systemctl enable ceph-osd@${OSD_ID}
90         systemctl start ceph-osd@${OSD_ID}
91     done
92
93     echo INFO: Ceph was upgraded to Jewel
94 else
95     echo ERROR: Ceph was upgraded to an unknown release, daemon is stopped, need manual intervention
96     exit 1
97 fi
98
99 ceph osd unset noout
100 ceph osd unset norebalance
101 ceph osd unset nodeep-scrub
102 ceph osd unset noscrub
103 ENDOFCAT
104
105 # ensure the permissions are OK
106 chmod 0755 $UPGRADE_SCRIPT