diff --git a/install-stack.sh b/install-stack.sh index 24051f5..726c653 100755 --- a/install-stack.sh +++ b/install-stack.sh @@ -253,6 +253,7 @@ gen_secrets() { CASHUP_DB_PASS=$(sed -n 's/^CASHUP_DB_PASS=//p' "$CREDS_FILE" | head -1) HK_PLANNER_DB_PASS=$(sed -n 's/^HK_PLANNER_DB_PASS=//p' "$CREDS_FILE" | head -1) TWIN_OPT_DB_PASS=$(sed -n 's/^TWIN_OPT_DB_PASS=//p' "$CREDS_FILE" | head -1) + ROOM_PLANNER_DB_PASS=$(sed -n 's/^ROOM_PLANNER_DB_PASS=//p' "$CREDS_FILE" | head -1) CENTRAL_AUTH_SECRET=$(sed -n 's/^CENTRAL_AUTH_SECRET=//p' "$CREDS_FILE" | head -1) SETTINGS_SECRET=$(sed -n 's/^SETTINGS_SECRET=//p' "$CREDS_FILE" | head -1) WEBHOOK_SECRET=$(sed -n 's/^WEBHOOK_SECRET=//p' "$CREDS_FILE" | head -1) @@ -271,6 +272,7 @@ gen_secrets() { CASHUP_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) HK_PLANNER_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) TWIN_OPT_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) + ROOM_PLANNER_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) CENTRAL_AUTH_SECRET=$(openssl rand -hex 32) SETTINGS_SECRET=$(openssl rand -hex 32) WEBHOOK_SECRET=$(openssl rand -hex 24) @@ -293,6 +295,7 @@ SETTINGS_DB_PASS=${SETTINGS_DB_PASS} CASHUP_DB_PASS=${CASHUP_DB_PASS} HK_PLANNER_DB_PASS=${HK_PLANNER_DB_PASS} TWIN_OPT_DB_PASS=${TWIN_OPT_DB_PASS} +ROOM_PLANNER_DB_PASS=${ROOM_PLANNER_DB_PASS} CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET} SETTINGS_SECRET=${SETTINGS_SECRET} WEBHOOK_SECRET=${WEBHOOK_SECRET} @@ -621,6 +624,14 @@ CREATE USER twin_optimiser WITH PASSWORD '${TWIN_OPT_DB_PASS}'; CREATE DATABASE twin_optimiser_db OWNER twin_optimiser; \c twin_optimiser_db GRANT ALL ON SCHEMA public TO twin_optimiser; +EOF + + # Init SQL — room-planner DB + push_file 100 /opt/postgres/init/07-room-planner.sql </dev/null @@ -1061,6 +1072,73 @@ ${build_out}" npm_add_location "/twin-optimiser/" "10.10.10.119" 3080 } +# ════════════════════════════════════════════════════════════════════════════ +# PHASE 11 — ROOM PLANNER LXC 120 +# ════════════════════════════════════════════════════════════════════════════ +deploy_room_planner() { + msg_step "11/11 Room Planner (LXC 120 · 10.10.10.120)" + + if [[ -z "${ROOM_PLANNER_DB_PASS:-}" ]]; then + ROOM_PLANNER_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) + printf '\nROOM_PLANNER_DB_PASS=%s\n' "$ROOM_PLANNER_DB_PASS" >> "$CREDS_FILE" + msg_ok "Generated ROOM_PLANNER_DB_PASS → ${CREDS_FILE}" + fi + + msg_info "Creating LXC 120" + create_lxc 120 "10.10.10.120" "room-planner" 1024 1 + msg_ok "LXC 120 created" + + msg_info "Installing Docker" + install_docker 120 + install_mgmt_key 120 + msg_ok "Docker + SSH ready" + + msg_info "Creating room_planner database" + pct exec 100 -- bash -c " + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE USER room_planner WITH PASSWORD '${ROOM_PLANNER_DB_PASS}';\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE DATABASE room_planner_db OWNER room_planner;\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -d room_planner_db -c \ + \"GRANT ALL ON SCHEMA public TO room_planner;\" 2>/dev/null || true + " &>/dev/null + msg_ok "Database room_planner_db ready" + + msg_info "Deploying room-planner" + deploy_service 120 "room-planner" "${REPO_ROOT}/room-planner" /opt/room-planner + + # NEWBOOK_LOCATION_ID is the NewBook property location ID — set in credentials file if known + local nb_location="${NEWBOOK_LOCATION_ID:-}" + [[ -z "$nb_location" ]] && msg_warn "NEWBOOK_LOCATION_ID not set — add it to /opt/room-planner/.env on LXC 120" + + push_file 120 /opt/room-planner/.env <&1"); then + msg_error "docker compose build failed in LXC 120: +${build_out}" + fi + + msg_info "Waiting for room-planner" + wait_healthy 120 "http://localhost:3080/room-planner/health" \ + && msg_ok "Room Planner running at 10.10.10.120:3080" \ + || msg_warn "Room Planner may need extra time — check LXC 120" + + # Add /room-planner/ location to NPM proxy host + npm_add_location "/room-planner/" "10.10.10.120" 3080 +} + # ════════════════════════════════════════════════════════════════════════════ # NPM PROXY HOSTS (via API) # ════════════════════════════════════════════════════════════════════════════ @@ -1309,7 +1387,7 @@ SUMMARY # Sources existing credentials and redeploys just the named service. if [[ "${1:-}" == "--only" ]]; then ONLY="${2:-}" - VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser" + VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser room-planner" [[ -z "$ONLY" ]] && msg_error "Usage: install-stack.sh --only (one of: ${VALID})" grep -qw "$ONLY" <<< "$VALID" || msg_error "Unknown service '${ONLY}'. Valid: ${VALID}" CREDS_FILE=/root/hotel-manage-credentials.txt @@ -1352,6 +1430,7 @@ if [[ "${1:-}" == "--only" ]]; then cashup) deploy_cashup ;; hk-planner) deploy_hk_planner ;; twin-optimiser) deploy_twin_optimiser ;; + room-planner) deploy_room_planner ;; esac exit 0 fi @@ -1372,5 +1451,6 @@ deploy_settings deploy_cashup deploy_hk_planner deploy_twin_optimiser +deploy_room_planner configure_npm_proxy_hosts print_summary