2021-10-12 19:24:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-10-12 19:36:06 +00:00
|
|
|
# Used for debugging
|
|
|
|
# set -ax
|
2021-10-12 19:24:31 +00:00
|
|
|
|
|
|
|
# This script is required after a reboot of the cloud after the cloud has been
|
|
|
|
# shut down
|
|
|
|
|
2022-10-24 10:37:22 +00:00
|
|
|
check_juju_version()
|
|
|
|
{
|
|
|
|
juju_version=$(juju version | cut -d'-' -f1 | cut -d'.' -f1)
|
|
|
|
juju_run="juju run"
|
|
|
|
juju_run_action="juju run-action"
|
|
|
|
|
|
|
|
if [[ ${juju_version} -ge 3 ]] ; then
|
|
|
|
juju_run="juju exec"
|
|
|
|
juju_run_action="juju run"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-10-12 19:24:31 +00:00
|
|
|
check_unit_status()
|
|
|
|
{
|
|
|
|
|
|
|
|
app_name=$1
|
|
|
|
status_check="$2"
|
|
|
|
|
|
|
|
unit_status=$(juju status --format json | jq -rc ".applications.${app_name}.units | to_entries[] | {sub:.key,status:.value[\"workload-status\"].message}")
|
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
app_units=$(echo "${unit_status}" | jq -r .sub)
|
2021-10-12 19:24:31 +00:00
|
|
|
|
|
|
|
num=0
|
|
|
|
for unit in ${app_units} ; do
|
2022-07-01 19:28:36 +00:00
|
|
|
this_unit_status=$(echo "$unit_status" | jq -rc . | grep "${unit}" | jq -r .status)
|
2021-10-12 19:24:31 +00:00
|
|
|
if [[ "${this_unit_status}" == "${status_check}" ]] ; then
|
|
|
|
(( num++ ))
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $num -ge 3 ]] ; then echo 1
|
|
|
|
else echo 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_lead()
|
|
|
|
{
|
|
|
|
app_name=$1
|
|
|
|
|
2022-07-01 19:32:35 +00:00
|
|
|
jq -rc '.applications.${app_name}.units | to_entries[] | select(.value.leader == "true") | .key' "${juju_status}"
|
2021-10-12 19:24:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 19:36:06 +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-07-01 19:28:36 +00:00
|
|
|
IPS=$(jq -r '.applications.vault.units | to_entries[].value."public-address"' "${juju_status}")
|
2021-10-12 19:36:06 +00:00
|
|
|
|
|
|
|
for ip in $IPS;do
|
2022-07-01 19:28:36 +00:00
|
|
|
echo export VAULT_ADDR=http://"${ip}":8200;
|
|
|
|
export VAULT_ADDR=http://"${ip}":8200;
|
2021-10-12 19:36:06 +00:00
|
|
|
for vault_key in $(head -n3 vault-secrets.txt | awk '{print $4}');do
|
2022-07-01 19:28:36 +00:00
|
|
|
echo vault operator unseal -tls-skip-verify "$vault_key"
|
|
|
|
vault operator unseal -tls-skip-verify "$vault_key"
|
2021-10-12 19:36:06 +00:00
|
|
|
done;
|
|
|
|
done;
|
|
|
|
|
2022-10-24 10:37:22 +00:00
|
|
|
#${juju_run} -a vault "hooks/update-status"
|
2021-10-12 19:36:06 +00:00
|
|
|
}
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-10-24 10:37:22 +00:00
|
|
|
check_juju_version
|
|
|
|
|
2021-10-12 19:24:31 +00:00
|
|
|
juju-wait -v
|
|
|
|
|
2021-10-12 19:36:06 +00:00
|
|
|
juju_status=$(mktemp)
|
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
juju status --format json > "${juju_status}"
|
2021-10-12 19:36:06 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
# Check if we're using percona-cluster or mysql-innodb-cluster
|
|
|
|
percona_cluster=$(jq -r ".applications | to_entries[] | select(.value[\"charm-name\"] == \"percona-cluster\") | .key" "${juju_status}")
|
|
|
|
mysql_innodb_cluster=$(jq -r ".applications | to_entries[] | select(.value[\"charm-name\"] == \"mysql-innodb-cluster\") | .key" "${juju_status}")
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
if [[ -n "${percona_cluster}" ]] ; then
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
mysql_status=$(jq -rc ".applications.mysql.units | to_entries[] | {sub:.key,status:.value[\"workload-status\"].message}" "${juju_status}")
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
#{"sub":"mysql/0","status":"MySQL is down. Sequence Number: 102921. Safe To Bootstrap: 1"}
|
|
|
|
#{"sub":"mysql/1","status":"MySQL is down. Sequence Number: 102921. Safe To Bootstrap: 0"}
|
|
|
|
#{"sub":"mysql/2","status":"MySQL is down. Sequence Number: 102921. Safe To Bootstrap: 0"}
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
mysql_units=$(echo "${mysql_status}" | jq -r .sub)
|
|
|
|
bootstrap_unit=""
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
mysql_lead=$(get_lead mysql)
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
safe_to_bootstrap=$(echo "$mysql_status" | jq -rc . | grep "Safe To Bootstrap: 1" | jq -r .sub)
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
if [[ -n "$safe_to_bootstrap" ]]
|
2022-07-01 19:32:35 +00:00
|
|
|
then
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
bootstrap_unit=$safe_to_bootstrap
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
else
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
seq_number=$(echo "$mysql_status" | jq -rc . | grep "Sequence Number" )
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
if [[ -n "${seq_number}" ]]
|
|
|
|
then
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
seqs=$(echo "$seq_number" | jq -rc ". | {sub:.sub,seq:(.status|split(\".\")[1]|split(\": \")[1])}")
|
2021-10-12 19:36:06 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
uniq_seqs=$(echo "$seqs" | jq -r .seq | sort -n | uniq)
|
|
|
|
seq_count=$(echo "$uniq_seqs" | xargs | wc -w)
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
highest_seq=$(echo "${seqs}" | jq -r .seq | sort -n | uniq | tail -n 1)
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
if [[ ${seq_count} -eq 1 ]]
|
|
|
|
then # same seq numbers all round
|
|
|
|
if [[ ${highest_seq} -eq -1 ]]
|
|
|
|
then # if all seq numbers are -1
|
|
|
|
echo "The sequence number is -1 ... exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
bootstrap_unit=${mysql_lead}
|
|
|
|
else # we have different seq numbers
|
|
|
|
|
|
|
|
unit_high_seq=$(echo "$seqs" | jq -rc . | grep "${highest_seq}" | jq -r .sub | tail -n 1)
|
|
|
|
|
|
|
|
bootstrap_unit=${unit_high_seq}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
if [[ -n ${bootstrap_unit} ]]
|
|
|
|
then
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run_action} --wait "${bootstrap_unit}" bootstrap-pxc
|
2022-10-24 10:38:42 +00:00
|
|
|
${juju_run} -a mysql "hooks/update-status"
|
2021-10-12 19:24:31 +00:00
|
|
|
until [[ $(check_unit_status mysql "Unit waiting for cluster bootstrap") -eq 1 ]]
|
|
|
|
do
|
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
if [[ "${bootstrap_unit}" == "${mysql_lead}" ]] ; then
|
|
|
|
for unit in ${mysql_units}; do
|
|
|
|
if [[ "${unit}" != "${mysql_lead}" ]] ; then
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run_action} --wait "${unit}" notify-bootstrapped
|
2021-10-12 19:24:31 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run_action} --wait "${mysql_lead}" notify-bootstrapped
|
2021-10-12 19:24:31 +00:00
|
|
|
fi
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run} -a mysql "hooks/update-status"
|
2021-10-12 19:24:31 +00:00
|
|
|
until [[ $(check_unit_status mysql "Unit is ready") -eq 1 ]]
|
|
|
|
do
|
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
# This is so that nagios doesn't report that the mysql daemon is down
|
|
|
|
# although the process is running. juju will then automatically start
|
|
|
|
# the mysqld process
|
2022-07-01 19:28:36 +00:00
|
|
|
juju ssh "${bootstrap_unit}" -- sudo reboot
|
|
|
|
fi
|
|
|
|
|
2022-10-24 10:37:22 +00:00
|
|
|
juju exec -a nova-cloud-controller -- sudo systemctl restart nova-api-os-compute nova-conductor nova-consoleauth &
|
2021-10-12 19:24:31 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
if [[ -n "${mysql_innodb_cluster}" ]] ; then
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
mysql_status=$(jq -rc ".applications.\"mysql-innodb-cluster\".units | to_entries[] | {sub:.key,status:.value[\"workload-status\"].message}" "${juju_status}")
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
is_ready=$(echo "$mysql_status" | jq -rc . | grep "Mode: R/W, Cluster is ONLINE" | jq -r .sub)
|
|
|
|
|
|
|
|
if [[ -z "${is_ready}" ]] ; then
|
2022-10-24 10:37:22 +00:00
|
|
|
reboot_status=$(${juju_run_action} mysql-innodb-cluster/leader reboot-cluster-from-complete-outage --wait --format json)
|
2022-07-01 19:32:35 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
outcome=$(echo "$reboot_status" | jq .[].results.outcome)
|
|
|
|
|
|
|
|
if [[ ${outcome} == null ]] ; then
|
|
|
|
|
|
|
|
output=$(echo "$reboot_status" | jq .[].results.output)
|
|
|
|
|
|
|
|
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|")
|
|
|
|
|
|
|
|
bootstrap_unit=$(jq -r ".applications.\"mysql-innodb-cluster\".units | to_entries[] | select(.value.\"public-address\" == \"${mysql_ip}\") | .key" "${juju_status}")
|
|
|
|
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run_action} "${bootstrap_unit}" reboot-cluster-from-complete-outage --wait
|
2022-07-01 19:28:36 +00:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
2022-10-24 10:38:42 +00:00
|
|
|
#${juju_run} -a mysql-innodb-cluster "hooks/update-status"
|
2022-07-01 19:28:36 +00:00
|
|
|
|
|
|
|
# Run update-status on all mysql-router units, to ensure that theyave connected to the mysql-innodb-cluster
|
2022-10-20 13:41:17 +00:00
|
|
|
#jq -r ".applications | to_entries[] | select(.value[\"charm-name\"] == \"mysql-router\") | .key" "${juju_status}" \
|
2022-10-24 10:37:22 +00:00
|
|
|
# | xargs -I{} ${juju_run} -a "{}" -- 'hooks/update-status'
|
2022-07-01 19:28:36 +00:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run} -u elasticsearch/leader -- sudo systemctl restart elasticsearch &
|
|
|
|
${juju_run} -a heat -- sudo systemctl restart heat-engine &
|
|
|
|
${juju_run} -a vault -- sudo systemctl restart vault &
|
2021-10-12 19:36:06 +00:00
|
|
|
|
|
|
|
wait
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2021-10-12 19:36:06 +00:00
|
|
|
# cleanup all crm resources
|
2022-07-01 19:28:36 +00:00
|
|
|
jq -r ".applications | to_entries[] | select(.value[\"charm-name\"] == \"hacluster\") | .key" "${juju_status}" \
|
2022-10-24 10:38:42 +00:00
|
|
|
| xargs -I{} ${juju_run} -u "{}"/leader -- 'sudo crm_resource -l | sed s/:.*//g | uniq | xargs -i sudo crm resource cleanup \"\{\}\"'
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2021-10-12 19:36:06 +00:00
|
|
|
do_vault
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-22 08:42:40 +00:00
|
|
|
# remove DNS entry for external network
|
2022-10-24 11:11:35 +00:00
|
|
|
${juju_run} --all -- "sudo sed -i -e s/192.168.1.13,//g -e s/192.168.1.9,//g /etc/netplan/99-juju.yaml"
|
|
|
|
${juju_run} --all -- "sudo netplan apply ; sudo systemctl restart systemd-resolved"
|
2021-10-12 19:24:31 +00:00
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
ceph_osd_apps=$(jq -rc ".applications | to_entries[] | select(.value[\"charm-name\"] == \"ceph-osd\") | .key" "${juju_status}")
|
2021-10-12 19:36:06 +00:00
|
|
|
|
|
|
|
for apps in ${ceph_osd_apps}
|
|
|
|
do
|
2022-10-24 10:37:22 +00:00
|
|
|
${juju_run} -a "${apps}" --timeout 30s -- 'sudo systemctl kill --all --type=service vaultlocker-decrypt@*'
|
|
|
|
${juju_run} -a "${apps}" --timeout 30s -- 'sudo systemctl start --all --type=service vaultlocker-decrypt@*'
|
|
|
|
${juju_run} -a "${apps}" --timeout 30s -- 'sudo systemctl start --all --type=service ceph-volume@*' &
|
2021-10-12 19:24:31 +00:00
|
|
|
done
|
|
|
|
|
2021-10-12 19:36:06 +00:00
|
|
|
wait
|
|
|
|
|
2022-07-01 19:28:36 +00:00
|
|
|
lds_servers=$(jq -rc ". | .applications[\"landscape-server\"].units | to_entries[] | .key" "${juju_status}")
|
2021-10-12 19:24:31 +00:00
|
|
|
|
|
|
|
cat > /tmp/restart-landscape.sh << EOF
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
sudo systemctl restart landscape-*
|
|
|
|
EOF
|
|
|
|
|
|
|
|
for lds_server in ${lds_servers}
|
|
|
|
do
|
2022-07-01 19:28:36 +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 &
|
2021-10-12 19:24:31 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
wait
|