diff --git a/odoo-tecnativa/actions/drop b/odoo-tecnativa/actions/drop index 0927a1e..a389342 100755 --- a/odoo-tecnativa/actions/drop +++ b/odoo-tecnativa/actions/drop @@ -54,6 +54,35 @@ while [ "$1" ]; do done +db_drop() { + local dbname="$1" + ( + switch_to_relation_service postgres-database + + set +e + . lib/common + set -e + + ensure_db_docker_running || exit 1 + + if db_has_database "$dbname"; then + info "Found a postgres database '$dbname' and deleting it." + PGM rm -f "$dbname" || exit 1 + else + info "No postgres database '$dbname' found." + fi + + ) || exit 1 + + if [ -d "$SERVICE_DATASTORE"/var/lib/odoo/filestore/"$dbname" ]; then + rm -rf "$SERVICE_DATASTORE"/var/lib/odoo/filestore/"$dbname" >&2 || exit 1 + info "Deleted filestore for database '$dbname'." + else + info "No filestore for database '$dbname' found." + fi +} + + if [ -z "$dbname" ]; then ## @@ -118,21 +147,44 @@ cmd=( http://${container_ip}:8069/web/database/drop ) ## XXXvlab: contains password, left only for advanced debug -#debug "${cmd[@]}" +#echo "${cmd[@]}" >&2 + out=$("${cmd[@]}") || { - die "Posting to odoo drop API through curl was unsuccessfull." + errlvl="$?" + if [ "$errlvl" == "28" ]; then + ## Curl timeout + warn "Standard method through curl timed out. Trying manual drop of database." + db_drop "$dbname" || exit 1 + exit 0 + else + die "Posting to odoo drop API through curl was unsuccessfull ($errlvl)." + fi } if [[ "$out" == *""* ]]; then - errmsg=$(echo "$out" | grep "alert-danger") - errmsg=${errmsg#*>} - errmsg=${errmsg%%<*} - if [ "$errmsg" ]; then + errmsg=$(echo "$out" | grep -m1 "alert-danger") || + errmsg=$(echo "$out" | grep -m1 "errormsg") || + errmsg=$(echo "$out" | grep -m1 "