From 6f82beef0fb78f6f5711a6ccc851662c2ef312ff Mon Sep 17 00:00:00 2001 From: Vague Rabbit Date: Tue, 9 Feb 2021 16:12:59 -0800 Subject: [PATCH] added graceful database removal option --- template.undeploy | 70 +++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/template.undeploy b/template.undeploy index 8f987bb..266b239 100644 --- a/template.undeploy +++ b/template.undeploy @@ -5,6 +5,12 @@ #!/bin/sh set -e +print_status() { + echo + echo "## $1" + echo +} + sudo systemctl stop saleor wait sudo ufw delete allow {gql_port} @@ -91,10 +97,8 @@ done ######################################################################################### # Echo the detected operating system ######################################################################################### -echo "" -echo "$OS detected" -echo "" -sleep 3 +print_status "$OS detected" +sleep 2 ######################################################################################### @@ -108,7 +112,7 @@ sleep 3 # Fedora CoreOS # Kubernetes # SUSE CaaS -echo "Removing Saleor's core dependencies..." +print_status "Removing Saleor's core dependencies..." sleep 1 case "$OS" in Debian) @@ -178,24 +182,8 @@ esac ######################################################################################### # Tell the user what's happening ######################################################################################### -echo "" -echo "Finished purging core dependencies" -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}" +print_status "Finished purging core dependencies" +sleep 1 ######################################################################################### @@ -203,10 +191,15 @@ sleep 2 ######################################################################################### # Drop Saleor database and user - For future use ######################################################################################### -# Create the role in the database and assign the generated password -#sudo -i -u postgres psql -c "DROP ROLE $PGSQLUSER;" -# Create the database for Saleor -#sudo -i -u postgres psql -c "DROP DATABASE $PGSQLDBNAME;" +if [ "$GRD" = "yes" ]; then + print_status "Removing the database and database user gracefully..." + # Drop the role in the database and assign the generated password + 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 ######################################################################################### -echo "Finished removing database" -echo "" +print_status "Finished removing database" +sleep 1 +print_status "Removing the saleor service..." sleep 2 ######################################################################################### - +# Disable +sudo systemctl disable saleor.service +# Reload the daemon +sudo systemctl daemon-reload if [ -f "/etc/systemd/system/saleor.service" ]; then sudo rm /etc/systemd/system/saleor.service 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 sudo rm -R /etc/saleor fi @@ -250,5 +257,4 @@ if [ -d "/var/www/{host}" ]; then {rm_app_host} fi -echo "Saleor has been undeployed!" -echo "" \ No newline at end of file +print_status "Saleor has been undeployed!" \ No newline at end of file