Created
February 21, 2020 17:57
-
-
Save tpsilva/c1176cd890b1f3565497e715195c36c3 to your computer and use it in GitHub Desktop.
Delete failed heat stacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if ! dpkg -l | grep mysql-client>/dev/null; then | |
echo "We need to install mysql-client to delete the stacks. Continue? [y/n]" | |
read answer | |
[ "${answer,,}" = "y" ] || { echo "Canceled"; exit 0; } | |
sudo apt install mysql-client -y | |
printf "\n\n" | |
fi | |
CONN=$(sudo cat /etc/heat/heat.conf | grep 'connection = mysql.*') | |
PASSWORD=$(echo $CONN | cut -d "@" -f 1 | cut -d ":" -f 3) | |
HOST=$(echo $CONN | cut -d "@" -f 2 | cut -d "/" -f 1) | |
rows=$(mysql --host=$HOST --user=heat --password=$PASSWORD --database=heat -e "select id, name from stack where action = 'DELETE' and status = 'FAILED'" 2>/dev/null) | |
[ -z "$rows" ] && echo "No FAILED stacks found" && exit 0 | |
printf '%s\n\n' "${rows[@]}" | |
echo "Delete entries above? [y/n]" | |
read answer | |
[ "${answer,,}" = "y" ] || { echo "Canceled"; exit 0; } | |
mysql --host=$HOST --user=heat --password=$PASSWORD --database=heat -e "update stack set status = 'COMPLETE', deleted_at = NOW() where action = 'DELETE' and status = 'FAILED'" 2>/dev/null | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment