[IMP] add structured logging functions
Add logging functions to lib/common.sh for consistent output formatting: - log_info(): Standard informational messages with [INFO] prefix - log_warn(): Warning messages to stderr with [WARN] prefix - log_error(): Error messages to stderr with [ERROR] prefix - log_step(): Section headers with visual separators Update upgrade.sh to use these functions throughout, replacing ad-hoc echo statements. This provides: - Consistent visual formatting across all scripts - Clear distinction between info, warnings and errors - Errors properly sent to stderr - Easier log parsing and filtering Also removed redundant '|| exit 1' statements since set -e handles command failures automatically.
This commit is contained in:
@@ -9,6 +9,11 @@ set -euo pipefail
|
||||
readonly DATASTORE_PATH="/srv/datastore/data"
|
||||
readonly FILESTORE_SUBPATH="var/lib/odoo/filestore"
|
||||
|
||||
log_info() { printf "[INFO] %s\n" "$*"; }
|
||||
log_warn() { printf "[WARN] %s\n" "$*" >&2; }
|
||||
log_error() { printf "[ERROR] %s\n" "$*" >&2; }
|
||||
log_step() { printf "\n===== %s =====\n" "$*"; }
|
||||
|
||||
query_postgres_container() {
|
||||
local query="$1"
|
||||
local db_name="$2"
|
||||
@@ -58,4 +63,5 @@ exec_python_script_in_odoo_shell() {
|
||||
}
|
||||
|
||||
export DATASTORE_PATH FILESTORE_SUBPATH
|
||||
export -f log_info log_warn log_error log_step
|
||||
export -f query_postgres_container copy_database copy_filestore exec_python_script_in_odoo_shell
|
||||
|
||||
136
upgrade.sh
136
upgrade.sh
@@ -25,7 +25,7 @@ EOF
|
||||
}
|
||||
|
||||
if [[ $# -lt 4 ]]; then
|
||||
echo "ERROR: Missing arguments. Expected 4, got $#." >&2
|
||||
log_error "Missing arguments. Expected 4, got $#."
|
||||
usage
|
||||
fi
|
||||
|
||||
@@ -51,151 +51,103 @@ POSTGRES_CONTAINERS=$(docker ps --format '{{.Names}}' | grep postgres)
|
||||
POSTGRES_COUNT=$(echo "$POSTGRES_CONTAINERS" | grep -c .)
|
||||
|
||||
if [[ "$POSTGRES_COUNT" -eq 0 ]]; then
|
||||
echo "ERROR: No running PostgreSQL container found. Please start a PostgreSQL container and try again." >&2
|
||||
log_error "No running PostgreSQL container found. Please start a PostgreSQL container and try again."
|
||||
exit 1
|
||||
elif [[ "$POSTGRES_COUNT" -gt 1 ]]; then
|
||||
echo "ERROR: Multiple PostgreSQL containers found:" >&2
|
||||
log_error "Multiple PostgreSQL containers found:"
|
||||
echo "$POSTGRES_CONTAINERS" >&2
|
||||
echo "Please ensure only one PostgreSQL container is running." >&2
|
||||
log_error "Please ensure only one PostgreSQL container is running."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export POSTGRES_SERVICE_NAME="$POSTGRES_CONTAINERS"
|
||||
|
||||
#############################################
|
||||
# DISPLAYS ALL INPUTS PARAMETERS
|
||||
#############################################
|
||||
log_step "INPUT PARAMETERS"
|
||||
log_info "Origin version .......... $ORIGIN_VERSION"
|
||||
log_info "Final version ........... $FINAL_VERSION"
|
||||
log_info "Origin DB name ........... $ORIGIN_DB_NAME"
|
||||
log_info "Origin service name ..... $ORIGIN_SERVICE_NAME"
|
||||
|
||||
echo "===== INPUT PARAMETERS ====="
|
||||
echo "Origin version .......... $ORIGIN_VERSION"
|
||||
echo "Final version ........... $FINAL_VERSION"
|
||||
echo "Origin DB name ........... $ORIGIN_DB_NAME"
|
||||
echo "Origin service name ..... $ORIGIN_SERVICE_NAME"
|
||||
|
||||
echo "
|
||||
===== COMPUTED GLOBALE VARIABLES ====="
|
||||
echo "Copy DB name ............. $COPY_DB_NAME"
|
||||
echo "Finale DB name ........... $FINALE_DB_NAME"
|
||||
echo "Finale service name ...... $FINALE_SERVICE_NAME"
|
||||
echo "Postgres service name .... $POSTGRES_SERVICE_NAME"
|
||||
log_step "COMPUTED GLOBAL VARIABLES"
|
||||
log_info "Copy DB name ............. $COPY_DB_NAME"
|
||||
log_info "Finale DB name ........... $FINALE_DB_NAME"
|
||||
log_info "Finale service name ...... $FINALE_SERVICE_NAME"
|
||||
log_info "Postgres service name .... $POSTGRES_SERVICE_NAME"
|
||||
|
||||
|
||||
|
||||
##############################################
|
||||
# CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE #
|
||||
##############################################
|
||||
log_step "CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE"
|
||||
|
||||
echo "
|
||||
==== CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE ===="
|
||||
|
||||
# Check origin database is in the local postgres
|
||||
DB_EXISTS=$(docker exec -it -u 70 "$POSTGRES_SERVICE_NAME" psql -tc "SELECT 1 FROM pg_database WHERE datname = '$ORIGIN_DB_NAME'" | tr -d '[:space:]')
|
||||
if [[ "$DB_EXISTS" ]]; then
|
||||
echo "UPGRADE: Database '$ORIGIN_DB_NAME' found."
|
||||
log_info "Database '$ORIGIN_DB_NAME' found."
|
||||
else
|
||||
echo "ERROR: Database '$ORIGIN_DB_NAME' not found in the local postgress service. Please add it and restart the upgrade process."
|
||||
log_error "Database '$ORIGIN_DB_NAME' not found in the local postgres service. Please add it and restart the upgrade process."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check that the origin filestore exist
|
||||
REPERTOIRE="/srv/datastore/data/${ORIGIN_SERVICE_NAME}/var/lib/odoo/filestore/${ORIGIN_DB_NAME}"
|
||||
REPERTOIRE="${DATASTORE_PATH}/${ORIGIN_SERVICE_NAME}/${FILESTORE_SUBPATH}/${ORIGIN_DB_NAME}"
|
||||
if [[ -d "$REPERTOIRE" ]]; then
|
||||
echo "UPGRADE: '$REPERTOIRE' filestore found."
|
||||
log_info "Filestore '$REPERTOIRE' found."
|
||||
else
|
||||
echo "ERROR: '$REPERTOIRE' filestore not found, please add it and restart the upgrade process."
|
||||
log_error "Filestore '$REPERTOIRE' not found, please add it and restart the upgrade process."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#######################################
|
||||
# LAUNCH VIRGIN ODOO IN FINAL VERSION #
|
||||
#######################################
|
||||
log_step "LAUNCH VIRGIN ODOO IN FINAL VERSION"
|
||||
|
||||
# Remove finale database and datastore if already exists (we need a virgin Odoo)
|
||||
if docker exec -u 70 "$POSTGRES_SERVICE_NAME" pgm ls | grep -q "$FINALE_SERVICE_NAME"; then
|
||||
log_info "Removing existing finale database and filestore..."
|
||||
docker exec -u 70 "$POSTGRES_SERVICE_NAME" pgm rm -f "$FINALE_SERVICE_NAME"
|
||||
sudo rm -rf /srv/datastore/data/"$FINALE_SERVICE_NAME"/var/lib/odoo/filestore/"$FINALE_SERVICE_NAME"
|
||||
sudo rm -rf "${DATASTORE_PATH}/${FINALE_SERVICE_NAME}/${FILESTORE_SUBPATH}/${FINALE_SERVICE_NAME}"
|
||||
fi
|
||||
|
||||
compose --debug run "$FINALE_SERVICE_NAME" -i base --stop-after-init --no-http
|
||||
|
||||
echo "Model database in final Odoo version created."
|
||||
log_info "Model database in final Odoo version created."
|
||||
|
||||
############################
|
||||
# COPY ORIGINAL COMPONENTS #
|
||||
############################
|
||||
log_step "COPY ORIGINAL COMPONENTS"
|
||||
|
||||
echo "
|
||||
==== COPY ORIGINAL COMPONENTS ===="
|
||||
echo "UPGRADE: Start copy"
|
||||
copy_database "$ORIGIN_DB_NAME" "$COPY_DB_NAME" "$COPY_DB_NAME"
|
||||
log_info "Original database copied to ${COPY_DB_NAME}@${COPY_DB_NAME}."
|
||||
|
||||
# Copy database
|
||||
copy_database "$ORIGIN_DB_NAME" "$COPY_DB_NAME" "$COPY_DB_NAME" || exit 1
|
||||
echo "UPGRADE: original database copied in ${COPY_DB_NAME}@${COPY_DB_NAME}."
|
||||
|
||||
# Copy filestore
|
||||
copy_filestore "$ORIGIN_SERVICE_NAME" "$ORIGIN_DB_NAME" "$COPY_DB_NAME" "$COPY_DB_NAME" || exit 1
|
||||
echo "UPGRADE: original filestore copied."
|
||||
copy_filestore "$ORIGIN_SERVICE_NAME" "$ORIGIN_DB_NAME" "$COPY_DB_NAME" "$COPY_DB_NAME"
|
||||
log_info "Original filestore copied."
|
||||
|
||||
|
||||
#####################
|
||||
# PATH OF MIGRATION #
|
||||
####################
|
||||
log_step "PATH OF MIGRATION"
|
||||
|
||||
echo "
|
||||
==== PATH OF MIGRATION ===="
|
||||
# List all the versions to migrate through
|
||||
declare -a versions
|
||||
nb_migrations=$((FINAL_VERSION - ORIGIN_VERSION))
|
||||
|
||||
# Build the migration path
|
||||
for ((i = 0; i < nb_migrations; i++)); do
|
||||
versions[i]=$((ORIGIN_VERSION + 1 + i))
|
||||
done
|
||||
echo "UPGRADE: Migration path is ${versions[@]}"
|
||||
log_info "Migration path is ${versions[*]}"
|
||||
|
||||
|
||||
########################
|
||||
# DATABASE PREPARATION #
|
||||
########################
|
||||
log_step "DATABASE PREPARATION"
|
||||
|
||||
echo "
|
||||
==== DATABASE PREPARATION ===="
|
||||
|
||||
./prepare_db.sh "$COPY_DB_NAME" "$COPY_DB_NAME" "$FINALE_DB_MODEL_NAME" "$FINALE_SERVICE_NAME" || exit 1
|
||||
./prepare_db.sh "$COPY_DB_NAME" "$COPY_DB_NAME" "$FINALE_DB_MODEL_NAME" "$FINALE_SERVICE_NAME"
|
||||
|
||||
|
||||
###################
|
||||
# UPGRADE PROCESS #
|
||||
###################
|
||||
log_step "UPGRADE PROCESS"
|
||||
|
||||
for version in "${versions[@]}"
|
||||
do
|
||||
echo "START UPGRADE TO ${version}.0"
|
||||
start_version=$((version-1))
|
||||
end_version="$version"
|
||||
for version in "${versions[@]}"; do
|
||||
log_info "START UPGRADE TO ${version}.0"
|
||||
|
||||
### Go to the repository holding the upgrate scripts
|
||||
cd "${end_version}.0"
|
||||
cd "${version}.0"
|
||||
|
||||
### Execute pre_upgrade scripts
|
||||
./pre_upgrade.sh || exit 1
|
||||
./pre_upgrade.sh
|
||||
./upgrade.sh
|
||||
./post_upgrade.sh
|
||||
|
||||
### Start upgrade
|
||||
./upgrade.sh || exit 1
|
||||
|
||||
### Execute post-upgrade scripts
|
||||
./post_upgrade.sh || exit 1
|
||||
|
||||
### Return to parent repository for the following steps
|
||||
cd ..
|
||||
echo "END UPGRADE TO ${version}.0"
|
||||
log_info "END UPGRADE TO ${version}.0"
|
||||
done
|
||||
## END UPGRADE LOOP
|
||||
|
||||
##########################
|
||||
# POST-UPGRADE PROCESSES #
|
||||
##########################
|
||||
./finalize_db.sh "$FINALE_DB_NAME" "$FINALE_SERVICE_NAME" || exit 1
|
||||
log_step "POST-UPGRADE PROCESSES"
|
||||
|
||||
./finalize_db.sh "$FINALE_DB_NAME" "$FINALE_SERVICE_NAME"
|
||||
|
||||
echo "UPGRADE PROCESS ENDED WITH SUCCESS"
|
||||
log_step "UPGRADE PROCESS ENDED WITH SUCCESS"
|
||||
|
||||
Reference in New Issue
Block a user