diff --git a/install-stack.sh b/install-stack.sh index b33ecf1..12dadfe 100755 --- a/install-stack.sh +++ b/install-stack.sh @@ -1337,6 +1337,92 @@ ${build_out}" npm_add_location "/forecasting/" "10.10.10.113" 3080 } +deploy_rates() { + msg_step "Rate Monitor (LXC 115 · 10.10.10.115)" + + if [[ -z "${RATES_DB_PASS:-}" ]]; then + RATES_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) + printf '\nRATES_DB_PASS=%s\n' "$RATES_DB_PASS" >> "$CREDS_FILE" + msg_ok "Generated RATES_DB_PASS → ${CREDS_FILE}" + fi + if [[ -z "${RATES_SECRET:-}" ]]; then + RATES_SECRET=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 32) + printf '\nRATES_SECRET=%s\n' "$RATES_SECRET" >> "$CREDS_FILE" + msg_ok "Generated RATES_SECRET → ${CREDS_FILE}" + fi + + msg_info "Creating LXC 115 (2 GB RAM, 2 cores)" + create_lxc 115 "10.10.10.115" "rates" 2048 2 + msg_ok "LXC 115 created" + + msg_info "Installing Docker" + install_docker 115 + install_mgmt_key 115 + msg_ok "Docker + SSH ready" + + msg_info "Creating rates database" + pct exec 100 -- bash -c " + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE USER rates WITH PASSWORD '${RATES_DB_PASS}';\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE DATABASE rates_db OWNER rates;\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -d rates_db -c \ + \"GRANT ALL ON SCHEMA public TO rates;\" 2>/dev/null || true + " &>/dev/null + + msg_ok "Database rates_db ready (schema applied by Python backend on first start)" + + msg_info "Deploying rates" + deploy_service 115 "rates" "${REPO_ROOT}/rates" /opt/rates + + push_file 115 /opt/rates/.env <&1"); then + msg_error "docker compose build failed in LXC 115: +${build_out}" + fi + + msg_info "Waiting for rates" + wait_healthy 115 "http://localhost:3080/rates/health" 200 \ + && msg_ok "Rate Monitor running at 10.10.10.115:3080" \ + || msg_warn "Rate Monitor may need extra time — check LXC 115 logs" + + # Seed app + capabilities into auth DB + msg_info "Seeding rates into auth DB" + pct exec 100 -- docker exec hotel-manage-postgres psql -U postgres -d auth_db -c " + INSERT INTO apps (slug, name, description, base_path, icon, theme_color, category, internal_host, internal_port) + VALUES ('rates', 'Rate Monitor', 'Competitor rate monitoring and direct booking engine rates', '/rates', 'Tag', '#7b4f00', 'Finance', '10.10.10.115', 3080) + ON CONFLICT (slug) DO UPDATE SET + name=EXCLUDED.name, description=EXCLUDED.description, base_path=EXCLUDED.base_path, + icon=EXCLUDED.icon, theme_color=EXCLUDED.theme_color, category=EXCLUDED.category, + internal_host=EXCLUDED.internal_host, internal_port=EXCLUDED.internal_port; + INSERT INTO app_capabilities (app_id, slug, name, description, sort_order) + SELECT a.id, c.slug, c.name, c.description, c.sort_order + FROM apps a, (VALUES + ('view_own_rates','View Bookability','View own hotel rate and tariff availability',1), + ('view_competitors','View Market View','View competitor Booking.com rates',2), + ('view_direct_rates','View Direct Rates','View competitor direct booking engine rates',3), + ('rate_analysis','Rate Analysis','Drill into competitor pricing structure',4), + ('manage_scraper','Manage Scraper','Configure scraper, trigger manual scrapes',5), + ('manage_hotels','Manage Competitors','Classify and configure competitor hotels',6) + ) AS c(slug, name, description, sort_order) + WHERE a.slug = 'rates' + ON CONFLICT (app_id, slug) DO NOTHING; + " &>/dev/null \ + && msg_ok "rates seeded into auth DB" \ + || msg_warn "Seed failed — run auth db.js manually" + + npm_add_location "/rates/" "10.10.10.115" 3080 +} + # ════════════════════════════════════════════════════════════════════════════ # NPM PROXY HOSTS (via API) # ════════════════════════════════════════════════════════════════════════════ @@ -1633,6 +1719,7 @@ if [[ "${1:-}" == "--only" ]]; then room-planner) deploy_room_planner ;; maintenance) deploy_maintenance ;; forecasting) deploy_forecasting ;; + rates) deploy_rates ;; esac exit 0 fi @@ -1656,5 +1743,6 @@ deploy_twin_optimiser deploy_room_planner deploy_maintenance deploy_forecasting +deploy_rates configure_npm_proxy_hosts print_summary