refactor: COMMITs added to release locks immediately. UTC usage. Testing env for test branch.
This commit is contained in:
134
postgresql/docker/run_test_env.sh
Executable file
134
postgresql/docker/run_test_env.sh
Executable file
@@ -0,0 +1,134 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Default values
|
||||
PG_VERSION=""
|
||||
ZABBIX_VERSION=""
|
||||
|
||||
# Color codes
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 --pg <16|17|18> --zabbix <7.0|7.4>"
|
||||
echo "Example: $0 --pg 16 --zabbix 7.0"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--pg) PG_VERSION="$2"; shift ;;
|
||||
--zabbix) ZABBIX_VERSION="$2"; shift ;;
|
||||
*) echo "Unknown parameter: $1"; usage ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -z "$PG_VERSION" || -z "$ZABBIX_VERSION" ]]; then
|
||||
echo -e "${RED}Error: detailed arguments required.${NC}"
|
||||
usage
|
||||
fi
|
||||
|
||||
# Map Zabbix version to sql-scripts folder
|
||||
if [[ "$ZABBIX_VERSION" == "7.0" ]]; then
|
||||
SQL_DIR="../sql-scripts-70"
|
||||
elif [[ "$ZABBIX_VERSION" == "7.4" ]]; then
|
||||
SQL_DIR="../sql-scripts-74"
|
||||
else
|
||||
echo -e "${RED}Error: Unsupported Zabbix version. Use 7.0 or 7.4.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}Preparing environment for PostgreSQL $PG_VERSION and Zabbix $ZABBIX_VERSION...${NC}"
|
||||
|
||||
# Cleanup previous run
|
||||
echo "Cleaning up containers and volumes..."
|
||||
docker compose down -v > /dev/null 2>&1
|
||||
rm -rf init_scripts
|
||||
mkdir -p init_scripts
|
||||
|
||||
# Symlink SQL scripts
|
||||
echo "Setting up initialization scripts from $SQL_DIR..."
|
||||
|
||||
# 0. Extra Users
|
||||
if [[ -f "../init_extra_users.sql" ]]; then
|
||||
cp "../init_extra_users.sql" ./init_scripts/00_init_extra_users.sql
|
||||
echo "Copied extra user init script."
|
||||
fi
|
||||
|
||||
# 1. Schema
|
||||
if [[ -f "$SQL_DIR/schema.sql" ]]; then
|
||||
# Use 01_00 to ensure it comes before 01_10
|
||||
cp "$SQL_DIR/schema.sql" ./init_scripts/01_00_schema.sql
|
||||
|
||||
# 1.1 Partitioning Infrastructure
|
||||
if [[ -f "../procedures/00_partitions_init.sql" ]]; then
|
||||
cp "../procedures/00_partitions_init.sql" ./init_scripts/01_10_partitions_init.sql
|
||||
fi
|
||||
if [[ -f "../procedures/01_auditlog_prep.sql" ]]; then
|
||||
cp "../procedures/01_auditlog_prep.sql" ./init_scripts/01_20_auditlog_prep.sql
|
||||
fi
|
||||
if [[ -f "../procedures/02_maintenance.sql" ]]; then
|
||||
cp "../procedures/02_maintenance.sql" ./init_scripts/01_30_maintenance.sql
|
||||
fi
|
||||
if [[ -f "../procedures/03_enable_partitioning.sql" ]]; then
|
||||
cp "../procedures/03_enable_partitioning.sql" ./init_scripts/01_40_enable.sql
|
||||
fi
|
||||
if [[ -f "../procedures/04_monitoring_view.sql" ]]; then
|
||||
cp "../procedures/04_monitoring_view.sql" ./init_scripts/01_50_monitoring.sql
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}Error: schema.sql not found in $SQL_DIR${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Images
|
||||
if [[ -f "$SQL_DIR/images.sql" ]]; then
|
||||
cp "$SQL_DIR/images.sql" ./init_scripts/02_images.sql
|
||||
else
|
||||
echo -e "${RED}Error: images.sql not found in $SQL_DIR${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Data
|
||||
if [[ -f "$SQL_DIR/data.sql" ]]; then
|
||||
cp "$SQL_DIR/data.sql" ./init_scripts/03_data.sql
|
||||
else
|
||||
echo -e "${RED}Error: data.sql not found in $SQL_DIR${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Mock History Data
|
||||
if [[ -f "../z_gen_history_data.sql" ]]; then
|
||||
cp "../z_gen_history_data.sql" ./init_scripts/04_gen_data.sql
|
||||
echo "Copied mock data generator."
|
||||
else
|
||||
echo -e "${RED}Warning: z_gen_history_data.sql not found!${NC}"
|
||||
fi
|
||||
|
||||
# Check logic for 7.4 vs 7.0 (file names might slightly differ or be organized differently if using packages, but assuming source layout provided)
|
||||
|
||||
# Export variable for Docker Compose
|
||||
export PG_VERSION=$PG_VERSION
|
||||
|
||||
# Run Docker Compose
|
||||
echo -e "${GREEN}Starting PostgreSQL container...${NC}"
|
||||
docker compose up -d
|
||||
|
||||
echo -e "${GREEN}Waiting for database to be ready...${NC}"
|
||||
# Simple wait loop
|
||||
for i in {1..30}; do
|
||||
if docker exec zabbix-db-test pg_isready -U zabbix > /dev/null 2>&1; then
|
||||
echo -e "${GREEN}Database is ready!${NC}"
|
||||
break
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Check if data generation finished (it runs as part of init, which might take a bit longer than just port open)
|
||||
# We can check logs
|
||||
echo "To follow initialization logs, run: docker logs -f zabbix-db-test"
|
||||
echo -e "${GREEN}Environment ready.${NC}"
|
||||
echo "Connect: psql -h localhost -p 5432 -U zabbix -d zabbix"
|
||||
Reference in New Issue
Block a user