Merge "Fix typo in Keystone Sensu subscription"
[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 &> /dev/null; 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 # Special-case OVS for https://bugs.launchpad.net/tripleo/+bug/1635205
53 if [[ -n $(rpm -q --scripts openvswitch | awk '/postuninstall/,/*/' | grep "systemctl.*try-restart") ]]; then
54     echo "Manual upgrade of openvswitch - restart in postun detected"
55     mkdir OVS_UPGRADE || true
56     pushd OVS_UPGRADE
57     echo "Attempting to downloading latest openvswitch with yumdownloader"
58     yumdownloader --resolve openvswitch
59     echo "Updating openvswitch with nopostun option"
60     rpm -U --replacepkgs --nopostun ./*.rpm
61     popd
62 else
63     echo "Skipping manual upgrade of openvswitch - no restart in postun detected"
64 fi
65
66 # Update (Ceph to Jewel)
67 yum -y install python-zaqarclient  # needed for os-collect-config
68 yum -y update
69
70 # Restart/Exit if not on Jewel, only in that case we need the changes
71 UPDATED_VERSION=$(ceph --version | awk '{print $3}')
72 if [[ "$UPDATED_VERSION" =~ ^0\.94.* ]]; then
73     echo WARNING: Ceph was not upgraded, restarting daemon
74     for OSD_ID in $OSD_IDS; do
75         service ceph start osd.${OSD_ID}
76     done
77 elif [[ "$UPDATED_VERSION" =~ ^10\.2.* ]]; then
78     # RPM could own some of these but we can't take risks on the pre-existing files
79     for d in /var/lib/ceph/osd /var/log/ceph /var/run/ceph /etc/ceph; do
80         chown -L -R ceph:ceph $d || echo WARNING: chown of $d failed
81     done
82
83     # Replay udev events with newer rules
84     udevadm trigger && udevadm settle
85
86     # If on ext4, we need to enforce lower values for name and namespace len
87     # or ceph-osd will refuse to start, see: http://tracker.ceph.com/issues/16187
88     for OSD_ID in $OSD_IDS; do
89       OSD_FS=$(findmnt -n -o FSTYPE -T /var/lib/ceph/osd/ceph-${OSD_ID})
90       if [ ${OSD_FS} = ext4 ]; then
91         crudini --set /etc/ceph/ceph.conf global osd_max_object_name_len 256
92         crudini --set /etc/ceph/ceph.conf global osd_max_object_namespace_len 64
93       fi
94     done
95
96     # Enable systemd unit
97     systemctl enable ceph-osd.target
98     for OSD_ID in $OSD_IDS; do
99         systemctl enable ceph-osd@${OSD_ID}
100         systemctl start ceph-osd@${OSD_ID}
101     done
102
103     echo INFO: Ceph was upgraded to Jewel
104 else
105     echo ERROR: Ceph was upgraded to an unknown release, daemon is stopped, need manual intervention
106     exit 1
107 fi
108
109 ceph osd unset noout
110 ceph osd unset norebalance
111 ceph osd unset nodeep-scrub
112 ceph osd unset noscrub
113 ENDOFCAT
114
115 # ensure the permissions are OK
116 chmod 0755 $UPGRADE_SCRIPT