2022-01-27 10:08:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Used for debugging
|
|
|
|
# set -ax
|
|
|
|
|
|
|
|
# This script is required after a reboot of the cloud after the cloud has been
|
|
|
|
# shut down
|
|
|
|
|
|
|
|
get_lead()
|
|
|
|
{
|
|
|
|
app_name=$1
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
jq -rc ".applications.\"${app_name}\".units | to_entries[] | select(.value.leader == "true") | .key" "${juju_status}"
|
2022-01-27 10:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_vault()
|
|
|
|
{
|
|
|
|
vault_vip=$(juju config vault vip)
|
|
|
|
echo export VAULT_ADDR="http://${vault_vip}:8200"
|
|
|
|
export VAULT_ADDR="http://${vault_vip}:8200"
|
|
|
|
|
|
|
|
echo " "
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
IPS=$(jq -r '.applications.vault.units | to_entries[].value."public-address"' "${juju_status}")
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
for ip in $IPS;do
|
2022-03-14 11:32:10 +00:00
|
|
|
echo export VAULT_ADDR=http://"${ip}":8200;
|
|
|
|
export VAULT_ADDR=http://"${ip}":8200;
|
2022-01-27 10:08:00 +00:00
|
|
|
for vault_key in $(head -n3 vault-secrets.txt | awk '{print $4}');do
|
2022-03-14 11:32:10 +00:00
|
|
|
echo vault operator unseal -tls-skip-verify "$vault_key"
|
|
|
|
vault operator unseal -tls-skip-verify "$vault_key"
|
2022-01-27 10:08:00 +00:00
|
|
|
done;
|
|
|
|
done;
|
|
|
|
|
|
|
|
juju run -a vault "hooks/update-status"
|
|
|
|
}
|
|
|
|
|
|
|
|
juju-wait -v
|
|
|
|
|
|
|
|
juju_status=$(mktemp)
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
juju status --format json > "${juju_status}"
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
bootstrap_unit=""
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
mysql_status=$(jq -rc ".applications.\"mysql-innodb-cluster\".units | to_entries[] | {sub:.key,status:.value[\"workload-status\"].message}" "${juju_status}")
|
|
|
|
|
|
|
|
is_ready=$(echo "$mysql_status" | jq -rc . | grep "Mode: R/W, Cluster is ONLINE" | jq -r .sub)
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
if [[ -z "${is_ready}" ]] ; then
|
|
|
|
reboot_status=$(juju run-action mysql-innodb-cluster/leader reboot-cluster-from-complete-outage --wait --format json)
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
outcome=$(echo "$reboot_status" | jq .[].results.outcome)
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
if [[ ${outcome} == null ]] ; then
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
output=$(echo "$reboot_status" | jq .[].results.output)
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
mysql_ip=$(echo "$output" | sed -e 's/\\n/\n/g' 2>&1| grep Please | sed -e "s|.*Please use the most up to date instance: '\(.*\):.*|\1|")
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
bootstrap_unit=$(jq -r ".applications.\"mysql-innodb-cluster\".units | to_entries[] | select(.value.\"public-address\" == \"${mysql_ip}\") | .key" "${juju_status}")
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
juju run-action "${bootstrap_unit}" reboot-cluster-from-complete-outage --wait
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
juju run --application mysql-innodb-cluster "hooks/update-status"
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
# Run update-status on all mysql-router units, to ensure that theyave connected to the mysql-innodb-cluster
|
|
|
|
jq -r ".applications | to_entries[] | select(.value[\"charm-name\"] == \"mysql-router\") | .key" "${juju_status}" \
|
|
|
|
| xargs -I{} juju run -a "{}" -- 'hooks/update-status'
|
2022-01-27 10:08:00 +00:00
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
fi
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
juju run -a heat -- sudo systemctl restart heat-engine &
|
|
|
|
juju run -a vault -- sudo systemctl restart vault &
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
for app in heat vault ; do
|
|
|
|
juju run -a $app "hooks/update-status" &
|
|
|
|
done
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
# cleanup all crm resources
|
2022-03-14 11:32:10 +00:00
|
|
|
jq -r ".applications | to_entries[] | select(.value[\"charm-name\"] == \"hacluster\") | .key" "${juju_status}" \
|
|
|
|
| xargs -I{} juju run --unit "{}"/leader -- 'sudo crm_resource -l | sed s/:.*//g | uniq | xargs -i sudo crm resource cleanup \"\{\}\"'
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
do_vault
|
|
|
|
|
|
|
|
# Wait 10 seconds, and ensure that vault is unsealed
|
|
|
|
echo "Sleeping 10 seconds to wait for vault to finalise unseal"
|
|
|
|
sleep 10
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
ceph_osd_apps=$(jq -rc ".applications | to_entries[] | select(.value[\"charm-name\"] == \"ceph-osd\") | .key" "${juju_status}")
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
ceph_osds=""
|
|
|
|
for apps in ${ceph_osd_apps}
|
|
|
|
do
|
2022-03-14 11:32:10 +00:00
|
|
|
ceph_osds="${ceph_osds} $(jq -rc ". | .applications[\"${apps}\"].units | to_entries[] | .key" "${juju_status}")"
|
2022-01-27 10:08:00 +00:00
|
|
|
done
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
juju run --all -- sudo systemctl restart systemd-resolved
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
for ceph_osd in ${ceph_osds}
|
|
|
|
do
|
2022-03-14 11:32:10 +00:00
|
|
|
juju ssh "${ceph_osd}" -- 'sudo systemctl kill --all --type=service vaultlocker-decrypt@* ;
|
2022-01-27 10:08:00 +00:00
|
|
|
sudo systemctl start --all --type=service vaultlocker-decrypt@* ;
|
|
|
|
sudo systemctl start --all --type=service ceph-volume@*' &
|
|
|
|
done
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
juju run -a ceph-osd "hooks/update-status"
|
|
|
|
|
2022-03-14 11:32:10 +00:00
|
|
|
lds_servers=$(jq -rc ". | .applications[\"landscape-server\"].units | to_entries[] | .key" "${juju_status}")
|
2022-01-27 10:08:00 +00:00
|
|
|
|
|
|
|
cat > /tmp/restart-landscape.sh << EOF
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
sudo systemctl restart landscape-*
|
|
|
|
EOF
|
|
|
|
|
|
|
|
for lds_server in ${lds_servers}
|
|
|
|
do
|
2022-03-14 11:32:10 +00:00
|
|
|
juju scp /tmp/restart-landscape.sh "${lds_server}":.
|
|
|
|
juju ssh "${lds_server}" chmod +x restart-landscape.sh
|
|
|
|
juju ssh "${lds_server}" sudo ./restart-landscape.sh &
|
2022-01-27 10:08:00 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
wait
|