#!/bin/bash # --- Configuration Variables (YOU MUST CHANGE THESE) --- # These variables configure the database connection for Guacamole. # Note: These map to the POSTGRESQL_* variables in the Guacamole container. export POSTGRES_DATABASE="guacamole_db" export POSTGRES_USER="guacamole_user" export POSTGRES_PASSWORD="YourSecureDBPassword123" # <<< CHANGE THIS PASSWORD # -------------------------------------------------------- echo "Starting Apache Guacamole Docker deployment setup..." # 1. Create the docker-compose.yml file echo "Creating docker-compose.yml..." cat << EOF > docker-compose.yml services: guacd: image: guacamole/guacd:latest container_name: guacamole-guacd restart: always # Optional: Add basic healthcheck for better reliability status (recommended) healthcheck: test: ["CMD", "sh", "-c", "echo 'guacd is alive' | nc -w 1 localhost 4822"] interval: 30s timeout: 10s retries: 5 db: image: postgres:13-alpine container_name: guacamole-postgres restart: always environment: POSTGRES_DB: ${POSTGRES_DATABASE} POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - guacamole_db_data:/var/lib/postgresql/data guacamole: image: guacamole/guacamole:latest container_name: guacamole-app restart: always ports: - 8080:8080 environment: GUACD_HOSTNAME: guacd # --- FIX: Use POSTGRESQL_ prefix and explicitly define hostname for reliability --- POSTGRESQL_HOSTNAME: db POSTGRESQL_DATABASE: ${POSTGRES_DATABASE} POSTGRESQL_USERNAME: ${POSTGRES_USER} # Guacamole uses USERNAME, not USER POSTGRESQL_PASSWORD: ${POSTGRES_PASSWORD} depends_on: - guacd - db volumes: guacamole_db_data: EOF # 2. Start the database and guacd services echo "Starting Guacamole Proxy (guacd) and Database (db)..." docker compose up -d guacd db # 3. Wait for PostgreSQL to be ready echo "Waiting for the database to be ready..." until docker compose exec db pg_isready -U "${POSTGRES_USER}" -d "${POSTGRES_DATABASE}"; do echo "Postgres is unavailable - sleeping (5s)..." sleep 5 done echo "Postgres is now ready." # 4. Generate the Guacamole database initialization script echo "Generating database initialization script (initdb.sql)..." # --- FIX: Changed --postgres to the correct --postgresql flag --- docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgresql > initdb.sql # 5. Execute the initialization script on the PostgreSQL database echo "Executing the initialization script on the database..." docker compose exec -T db psql -U "${POSTGRES_USER}" -d "${POSTGRES_DATABASE}" < initdb.sql # 6. Start the Guacamole web application echo "Starting the Guacamole web application..." docker compose up -d guacamole # 7. Clean up the SQL script rm initdb.sql # 8. Final message echo -e "\n--- DEPLOYMENT COMPLETE ---" echo "Apache Guacamole is now running." echo "Access it at: http://:8080/guacamole/" echo "Default Credentials: guacadmin / guacadmin" echo "!!! IMPORTANT: Log in and change the default password immediately. !!!" echo "---------------------------"