added graceful database removal option

This commit is contained in:
Vague Rabbit 2021-02-09 16:12:59 -08:00
parent e5835e1219
commit 6f82beef0f

View file

@ -5,6 +5,12 @@
#!/bin/sh #!/bin/sh
set -e set -e
print_status() {
echo
echo "## $1"
echo
}
sudo systemctl stop saleor sudo systemctl stop saleor
wait wait
sudo ufw delete allow {gql_port} sudo ufw delete allow {gql_port}
@ -91,10 +97,8 @@ done
######################################################################################### #########################################################################################
# Echo the detected operating system # Echo the detected operating system
######################################################################################### #########################################################################################
echo "" print_status "$OS detected"
echo "$OS detected" sleep 2
echo ""
sleep 3
######################################################################################### #########################################################################################
@ -108,7 +112,7 @@ sleep 3
# Fedora CoreOS # Fedora CoreOS
# Kubernetes # Kubernetes
# SUSE CaaS # SUSE CaaS
echo "Removing Saleor's core dependencies..." print_status "Removing Saleor's core dependencies..."
sleep 1 sleep 1
case "$OS" in case "$OS" in
Debian) Debian)
@ -178,24 +182,8 @@ esac
######################################################################################### #########################################################################################
# Tell the user what's happening # Tell the user what's happening
######################################################################################### #########################################################################################
echo "" print_status "Finished purging core dependencies"
echo "Finished purging core dependencies" sleep 1
echo ""
sleep 2
#########################################################################################
#########################################################################################
# Set variables for the database user/database names - For future use
#########################################################################################
# Append the database name for Saleor with the obfuscation string
#PGSQLDBNAME="{pgsqldbname}"
# Append the database username for Saleor with the obfuscation string
#PGSQLUSER="{pgsqluser}"
# Generate a 128 byte password for the Saleor database user
# TODO: Add special characters once we know which ones won't crash the python script
#PGSQLUSERPASS="{pgsqluserpass}"
######################################################################################### #########################################################################################
@ -203,10 +191,15 @@ sleep 2
######################################################################################### #########################################################################################
# Drop Saleor database and user - For future use # Drop Saleor database and user - For future use
######################################################################################### #########################################################################################
# Create the role in the database and assign the generated password if [ "$GRD" = "yes" ]; then
#sudo -i -u postgres psql -c "DROP ROLE $PGSQLUSER;" print_status "Removing the database and database user gracefully..."
# Create the database for Saleor # Drop the role in the database and assign the generated password
#sudo -i -u postgres psql -c "DROP DATABASE $PGSQLDBNAME;" sudo -i -u postgres psql -c "DROP ROLE {pgsqluser};"
wait
# Drop the database for Saleor
sudo -i -u postgres psql -c "DROP DATABASE {pgsqldbname};"
wait
fi
######################################################################################### #########################################################################################
@ -214,16 +207,30 @@ sleep 2
######################################################################################### #########################################################################################
# Tell the user what's happening # Tell the user what's happening
######################################################################################### #########################################################################################
echo "Finished removing database" print_status "Finished removing database"
echo "" sleep 1
print_status "Removing the saleor service..."
sleep 2 sleep 2
######################################################################################### #########################################################################################
# Disable
sudo systemctl disable saleor.service
# Reload the daemon
sudo systemctl daemon-reload
if [ -f "/etc/systemd/system/saleor.service" ]; then if [ -f "/etc/systemd/system/saleor.service" ]; then
sudo rm /etc/systemd/system/saleor.service sudo rm /etc/systemd/system/saleor.service
fi fi
#########################################################################################
# Tell the user what's happening
#########################################################################################
print_status "Finished removing the saleor service"
sleep 1
print_status "Removing the saleor private key file..."
sleep 2
#########################################################################################
if [ -d "/etc/saleor" ]; then if [ -d "/etc/saleor" ]; then
sudo rm -R /etc/saleor sudo rm -R /etc/saleor
fi fi
@ -250,5 +257,4 @@ if [ -d "/var/www/{host}" ]; then
{rm_app_host} {rm_app_host}
fi fi
echo "Saleor has been undeployed!" print_status "Saleor has been undeployed!"
echo ""