aboutsummaryrefslogtreecommitdiff
path: root/scripts/remove
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/remove')
-rw-r--r--scripts/remove102
1 files changed, 52 insertions, 50 deletions
diff --git a/scripts/remove b/scripts/remove
index 0ea12df..303ccf7 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -6,78 +6,83 @@
# IMPORT GENERIC HELPERS
#=================================================
-source _common.sh # Loads the generic functions usually used in the script
-# Source app helpers
+source _common.sh
+source ynh_install_ruby
+source ynh_add_secure_repos__3
source /usr/share/yunohost/helpers
-source _future.sh
-
-
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
-# Retrieve app settings
-domain=$(ynh_app_setting_get "$app" domain)
-db_name=$(ynh_app_setting_get "$app" db_name)
-if [ -z "$db_name" ]; then
- db_name="${app}_production"
- ynh_app_setting_set "$app" db_name "$db_name"
-fi
-db_user=$(ynh_sanitize_dbid "$app")
-final_path=$(ynh_app_setting_get "$app" final_path)
+domain=$(ynh_app_setting_get $app domain)
+db_name=$(ynh_app_setting_get $app db_name)
+final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# STANDARD REMOVE
#=================================================
-# STOP AND REMOVE SERVICE
-#=================================================
-
-ynh_remove_systemd_config "$app-web"
-ynh_remove_systemd_config "$app-sidekiq"
-ynh_remove_systemd_config "$app-streaming"
-
-#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
-#==============================================
+#=================================================
-if yunohost service status | grep -q "$app-web"
+# Remove a service from the admin panel, added by `yunohost service add`
+if yunohost service status "$app-web" >/dev/null 2>&1
then
- echo "Remove $app-web service"
+ ynh_print_info "Removing $app-web service"
yunohost service remove "$app-web"
fi
-if yunohost service status | grep -q "$app-sidekiq"
+if yunohost service status "$app-sidekiq" >/dev/null 2>&1
then
- echo "Remove $app-sidekiq service"
+ ynh_print_info "Removing $app-sidekiq service"
yunohost service remove "$app-sidekiq"
fi
-if yunohost service status | grep -q "$app-streaming"
+if yunohost service status "$app-streaming" >/dev/null 2>&1
then
- echo "Remove $app-streaming service"
+ ynh_print_info "Removing $app-streaming service"
yunohost service remove "$app-streaming"
fi
#=================================================
-# REMOVE DEPENDENCIES
+# STOP AND REMOVE SERVICE
#=================================================
+ynh_print_info "Stopping and removing the systemd service"
-# Remove metapackage and its dependencies
-ynh_remove_app_dependencies
+# Remove the dedicated systemd config
+ynh_remove_systemd_config "$app-web"
+ynh_remove_systemd_config "$app-sidekiq"
+ynh_remove_systemd_config "$app-streaming"
#=================================================
-# REMOVE THE PostgreSQL DATABASE
+# REMOVE THE POSTGRESQL DATABASE
#=================================================
+ynh_print_info "Removing the PostgreSQL database"
+
+ynh_psql_execute_as_root "\connect $db_name
+SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';"
# delete postgresql database & user
-ynh_psql_remove_db "$db_name" "$db_user"
+ynh_psql_remove_db --db_name="$db_name" --db_user="$app"
+
+#=================================================
+# REMOVE DEPENDENCIES
+#=================================================
+ynh_print_info "Removing dependencies"
+
+# Remove metapackage and its dependencies
+ynh_remove_ruby
+ynh_remove_app_dependencies
+ynh_remove_nodejs
+ynh_remove_extra_repo
#=================================================
# REMOVE APP MAIN DIR
#=================================================
+ynh_print_info "Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
@@ -85,9 +90,10 @@ ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
+ynh_print_info "Removing nginx web server configuration"
-ynh_secure_remove "/etc/nginx/conf.d/${domain}.d/${app}.conf"
-systemctl reload nginx
+# Remove the dedicated nginx config
+ynh_remove_nginx_config
#=================================================
# SPECIFIC REMOVE
@@ -95,25 +101,21 @@ systemctl reload nginx
# REMOVE THE CRON FILE
#=================================================
-# Delete cronlog
-ynh_secure_remove /etc/cron.d/$app
+# Remove a cron file
+ynh_secure_remove "/etc/cron.d/$app"
#=================================================
-# REMOVE source.list
+# GENERIC FINALIZATION
#=================================================
-if [ "$(lsb_release --codename --short)" == "jessie" ]; then
- ynh_secure_remove /etc/apt/sources.list.d/backports.list
- ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list
-fi
-ynh_secure_remove /etc/apt/sources.list.d/yarn.list
+# REMOVE DEDICATED USER
+#=================================================
+ynh_print_info "Removing the dedicated system user"
-# Delete ruby exec
-#ynh_secure_remove /usr/bin/ruby
+# Delete a system user
+ynh_system_user_delete $app
#=================================================
-# GENERIC FINALIZATION
-#=================================================
-# REMOVE DEDICATED USER
+# END OF SCRIPT
#=================================================
-userdel -f $app
+ynh_print_info "Removal of $app completed"