fix: initialize databases before starting dependent services

- start postgresql first, then run init_databases.sh, then other services
- add depends_on postgres for lightrag service
- remove unused nocodb from databases list
- document database initialization in add-new-service workflow
This commit is contained in:
Yury Kossakovsky
2025-12-25 13:15:07 -07:00
parent f32c92287e
commit 30e4c9407b
6 changed files with 66 additions and 17 deletions

View File

@@ -92,13 +92,18 @@ $COMPOSE_CMD -p "localai" "${COMPOSE_FILES_FOR_PULL[@]}" pull --ignore-buildable
exit 1
}
# Start services using the 06_run_services.sh script
log_info "Running Services..."
bash "$RUN_SERVICES_SCRIPT" || { log_error "Failed to start services. Check logs for details."; exit 1; }
# Start PostgreSQL first to initialize databases before other services
log_info "Starting PostgreSQL..."
$COMPOSE_CMD -p "localai" up -d postgres || { log_error "Failed to start PostgreSQL"; exit 1; }
# Initialize PostgreSQL databases for services (creates if not exist)
# This must run BEFORE other services that depend on these databases
bash "$SCRIPT_DIR/init_databases.sh" || { log_warning "Database initialization had issues, but continuing..."; }
# Start all services using the 06_run_services.sh script (postgres is already running)
log_info "Running Services..."
bash "$RUN_SERVICES_SCRIPT" || { log_error "Failed to start services. Check logs for details."; exit 1; }
log_success "Update application completed successfully!"
# --- Fix file permissions ---

View File

@@ -5,7 +5,7 @@
# This script runs during install/update and creates databases if they don't exist.
# Safe to run multiple times - only creates missing databases.
#
# Usage: Called automatically from install.sh and update.sh
# Usage: Called automatically from install.sh and apply_update.sh
# =============================================================================
source "$(dirname "$0")/utils.sh" && init_paths
@@ -15,7 +15,6 @@ source "$(dirname "$0")/utils.sh" && init_paths
DATABASES=(
"langfuse"
"lightrag"
"nocodb"
"postiz"
"waha"
)
@@ -44,7 +43,7 @@ EXISTING=0
for db in "${DATABASES[@]}"; do
# Check if database exists
EXISTS=$(docker exec postgres psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname = '$db'" 2>/dev/null)
EXISTS=$(docker exec postgres psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname = '$db'" 2>/dev/null | tr -d ' ')
if [ "$EXISTS" = "1" ]; then
log_info "Database '$db' already exists"

View File

@@ -120,12 +120,18 @@ bash "$SCRIPT_DIR/05_configure_services.sh" || { log_error "Configure Services f
log_success "Configure Services complete!"
show_step 6 8 "Running Services"
bash "$SCRIPT_DIR/06_run_services.sh" || { log_error "Running Services failed"; exit 1; }
log_success "Running Services complete!"
# Start PostgreSQL first to initialize databases before other services
log_info "Starting PostgreSQL..."
docker compose -p localai up -d postgres || { log_error "Failed to start PostgreSQL"; exit 1; }
# Initialize PostgreSQL databases for services (creates if not exist)
# This must run BEFORE other services that depend on these databases
bash "$SCRIPT_DIR/init_databases.sh" || { log_warning "Database initialization had issues, but continuing..."; }
# Now start all services (postgres is already running)
bash "$SCRIPT_DIR/06_run_services.sh" || { log_error "Running Services failed"; exit 1; }
log_success "Running Services complete!"
show_step 7 8 "Generating Final Report"
# --- Installation Summary ---
log_info "Installation Summary:"