diff --git a/install-stack.sh b/install-stack.sh index 334080f..dbb925d 100755 --- a/install-stack.sh +++ b/install-stack.sh @@ -252,6 +252,7 @@ gen_secrets() { SETTINGS_DB_PASS=$(sed -n 's/^SETTINGS_DB_PASS=//p' "$CREDS_FILE" | head -1) 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) 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) @@ -269,6 +270,7 @@ gen_secrets() { SETTINGS_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) 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) CENTRAL_AUTH_SECRET=$(openssl rand -hex 32) SETTINGS_SECRET=$(openssl rand -hex 32) WEBHOOK_SECRET=$(openssl rand -hex 24) @@ -290,6 +292,7 @@ NOTICES_DB_PASS=${NOTICES_DB_PASS} 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} CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET} SETTINGS_SECRET=${SETTINGS_SECRET} WEBHOOK_SECRET=${WEBHOOK_SECRET} @@ -610,6 +613,14 @@ CREATE USER hk_planner WITH PASSWORD '${HK_PLANNER_DB_PASS}'; CREATE DATABASE hk_planner_db OWNER hk_planner; \c hk_planner_db GRANT ALL ON SCHEMA public TO hk_planner; +EOF + + # Init SQL — twin-optimiser DB + push_file 100 /opt/postgres/init/06-twin-optimiser.sql </dev/null @@ -933,7 +944,7 @@ ${build_out}" # PHASE 9 — HK PLANNER LXC 118 # ════════════════════════════════════════════════════════════════════════════ deploy_hk_planner() { - msg_step "9/9 HK Planner (LXC 118 · 10.10.10.118)" + msg_step "9/10 HK Planner (LXC 118 · 10.10.10.118)" if [[ -z "${HK_PLANNER_DB_PASS:-}" ]]; then HK_PLANNER_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) @@ -991,6 +1002,65 @@ ${build_out}" npm_add_location "/hk-planner/" "10.10.10.118" 3080 } +deploy_twin_optimiser() { + msg_step "10/10 Twin Optimiser (LXC 119 · 10.10.10.119)" + + if [[ -z "${TWIN_OPT_DB_PASS:-}" ]]; then + TWIN_OPT_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24) + printf '\nTWIN_OPT_DB_PASS=%s\n' "$TWIN_OPT_DB_PASS" >> "$CREDS_FILE" + msg_ok "Generated TWIN_OPT_DB_PASS → ${CREDS_FILE}" + fi + + msg_info "Creating LXC 119" + create_lxc 119 "10.10.10.119" "twin-optimiser" 1024 1 + msg_ok "LXC 119 created" + + msg_info "Installing Docker" + install_docker 119 + install_mgmt_key 119 + msg_ok "Docker + SSH ready" + + msg_info "Creating twin_optimiser database" + pct exec 100 -- bash -c " + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE USER twin_optimiser WITH PASSWORD '${TWIN_OPT_DB_PASS}';\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE DATABASE twin_optimiser_db OWNER twin_optimiser;\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -d twin_optimiser_db -c \ + \"GRANT ALL ON SCHEMA public TO twin_optimiser;\" 2>/dev/null || true + " &>/dev/null + msg_ok "Database twin_optimiser_db ready" + + msg_info "Deploying twin-optimiser" + deploy_service 119 "hk-twin-optimiser" "${REPO_ROOT}/hk-twin-optimiser" /opt/twin-optimiser + + push_file 119 /opt/twin-optimiser/.env <&1"); then + msg_error "docker compose build failed in LXC 119: +${build_out}" + fi + + msg_info "Waiting for twin-optimiser" + wait_healthy 119 "http://localhost:3080/twin-optimiser/health" \ + && msg_ok "Twin Optimiser running at 10.10.10.119:3080" \ + || msg_warn "Twin Optimiser may need extra time — check LXC 119" + + # Add /twin-optimiser/ location to NPM proxy host + npm_add_location "/twin-optimiser/" "10.10.10.119" 3080 +} + # ════════════════════════════════════════════════════════════════════════════ # NPM PROXY HOSTS (via API) # ════════════════════════════════════════════════════════════════════════════ @@ -1156,7 +1226,8 @@ configure_npm_proxy_hosts() { {"path":"/notices/","forward_scheme":"http","forward_host":"10.10.10.112","forward_port":3080,"advanced_config":""}, {"path":"/monitor/","forward_scheme":"http","forward_host":"10.10.10.105","forward_port":3002,"advanced_config":""}, {"path":"/cashup/","forward_scheme":"http","forward_host":"10.10.10.117","forward_port":3083,"advanced_config":""}, - {"path":"/hk-planner/","forward_scheme":"http","forward_host":"10.10.10.118","forward_port":3080,"advanced_config":""} + {"path":"/hk-planner/","forward_scheme":"http","forward_host":"10.10.10.118","forward_port":3080,"advanced_config":""}, + {"path":"/twin-optimiser/","forward_scheme":"http","forward_host":"10.10.10.119","forward_port":3080,"advanced_config":""} ]' local result; result=$(create_proxy_host "10.10.10.102" 3000 "$locations") @@ -1198,6 +1269,7 @@ SUMMARY 116 hotel-manage-settings 10.10.10.116 3080 /settings/api/ 117 hotel-manage-cashup 10.10.10.117 3083 /cashup/ 118 hotel-manage-hk-planner 10.10.10.118 3080 /hk-planner/ + 119 hotel-manage-twin-optimiser 10.10.10.119 3080 /twin-optimiser/ ── Credentials ─────────────────────────────────────────────── Admin login: ${ADMIN_EMAIL} @@ -1237,7 +1309,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" + VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser" [[ -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 @@ -1261,6 +1333,8 @@ if [[ "${1:-}" == "--only" ]]; then "$(openssl rand -hex 32)" [[ -z "${HK_PLANNER_DB_PASS:-}" ]] && _append_secret HK_PLANNER_DB_PASS \ "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" + [[ -z "${TWIN_OPT_DB_PASS:-}" ]] && _append_secret TWIN_OPT_DB_PASS \ + "$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)" USE_FORGEJO=true [[ -f /root/.ssh/hotel-manage_deploy.pub ]] \ @@ -1276,7 +1350,8 @@ if [[ "${1:-}" == "--only" ]]; then noticeboard) deploy_noticeboard ;; settings) deploy_settings ;; cashup) deploy_cashup ;; - hk-planner) deploy_hk_planner ;; + hk-planner) deploy_hk_planner ;; + twin-optimiser) deploy_twin_optimiser ;; esac exit 0 fi @@ -1296,5 +1371,6 @@ deploy_noticeboard deploy_settings deploy_cashup deploy_hk_planner +deploy_twin_optimiser configure_npm_proxy_hosts print_summary