Add twin-optimiser service (LXC 119) to installer and --only mode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
70ffd218a1
commit
4219a801bf
1 changed files with 80 additions and 4 deletions
|
|
@ -252,6 +252,7 @@ gen_secrets() {
|
||||||
SETTINGS_DB_PASS=$(sed -n 's/^SETTINGS_DB_PASS=//p' "$CREDS_FILE" | head -1)
|
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)
|
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)
|
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)
|
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)
|
SETTINGS_SECRET=$(sed -n 's/^SETTINGS_SECRET=//p' "$CREDS_FILE" | head -1)
|
||||||
WEBHOOK_SECRET=$(sed -n 's/^WEBHOOK_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)
|
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)
|
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)
|
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)
|
CENTRAL_AUTH_SECRET=$(openssl rand -hex 32)
|
||||||
SETTINGS_SECRET=$(openssl rand -hex 32)
|
SETTINGS_SECRET=$(openssl rand -hex 32)
|
||||||
WEBHOOK_SECRET=$(openssl rand -hex 24)
|
WEBHOOK_SECRET=$(openssl rand -hex 24)
|
||||||
|
|
@ -290,6 +292,7 @@ NOTICES_DB_PASS=${NOTICES_DB_PASS}
|
||||||
SETTINGS_DB_PASS=${SETTINGS_DB_PASS}
|
SETTINGS_DB_PASS=${SETTINGS_DB_PASS}
|
||||||
CASHUP_DB_PASS=${CASHUP_DB_PASS}
|
CASHUP_DB_PASS=${CASHUP_DB_PASS}
|
||||||
HK_PLANNER_DB_PASS=${HK_PLANNER_DB_PASS}
|
HK_PLANNER_DB_PASS=${HK_PLANNER_DB_PASS}
|
||||||
|
TWIN_OPT_DB_PASS=${TWIN_OPT_DB_PASS}
|
||||||
CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET}
|
CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET}
|
||||||
SETTINGS_SECRET=${SETTINGS_SECRET}
|
SETTINGS_SECRET=${SETTINGS_SECRET}
|
||||||
WEBHOOK_SECRET=${WEBHOOK_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;
|
CREATE DATABASE hk_planner_db OWNER hk_planner;
|
||||||
\c hk_planner_db
|
\c hk_planner_db
|
||||||
GRANT ALL ON SCHEMA public TO hk_planner;
|
GRANT ALL ON SCHEMA public TO hk_planner;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Init SQL — twin-optimiser DB
|
||||||
|
push_file 100 /opt/postgres/init/06-twin-optimiser.sql <<EOF
|
||||||
|
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
|
EOF
|
||||||
|
|
||||||
pct exec 100 -- bash -c "cd /opt/postgres && docker compose up -d" &>/dev/null
|
pct exec 100 -- bash -c "cd /opt/postgres && docker compose up -d" &>/dev/null
|
||||||
|
|
@ -933,7 +944,7 @@ ${build_out}"
|
||||||
# PHASE 9 — HK PLANNER LXC 118
|
# PHASE 9 — HK PLANNER LXC 118
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
# ════════════════════════════════════════════════════════════════════════════
|
||||||
deploy_hk_planner() {
|
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
|
if [[ -z "${HK_PLANNER_DB_PASS:-}" ]]; then
|
||||||
HK_PLANNER_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)
|
||||||
|
|
@ -991,6 +1002,65 @@ ${build_out}"
|
||||||
npm_add_location "/hk-planner/" "10.10.10.118" 3080
|
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 <<EOF
|
||||||
|
NODE_ENV=production
|
||||||
|
APP_SLUG=twin-optimiser
|
||||||
|
DATABASE_URL=postgresql://twin_optimiser:${TWIN_OPT_DB_PASS}@10.10.10.100:5432/twin_optimiser_db
|
||||||
|
CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET}
|
||||||
|
SETTINGS_URL=http://10.10.10.116:3080
|
||||||
|
SETTINGS_SECRET=${SETTINGS_SECRET}
|
||||||
|
OFFICE_IP_CHECK=${OFFICE_IP_CHECK:-${OFFICE_IP:-disabled}}
|
||||||
|
VITE_HOTEL_NAME=${SITE_NAME}
|
||||||
|
FRONTEND_PORT=3080
|
||||||
|
EOF
|
||||||
|
|
||||||
|
local build_out
|
||||||
|
if ! build_out=$(pct exec 119 -- bash -c "cd /opt/twin-optimiser && docker compose up -d --build 2>&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)
|
# 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":"/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":"/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":"/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")
|
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/
|
116 hotel-manage-settings 10.10.10.116 3080 /settings/api/
|
||||||
117 hotel-manage-cashup 10.10.10.117 3083 /cashup/
|
117 hotel-manage-cashup 10.10.10.117 3083 /cashup/
|
||||||
118 hotel-manage-hk-planner 10.10.10.118 3080 /hk-planner/
|
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 ───────────────────────────────────────────────
|
── Credentials ───────────────────────────────────────────────
|
||||||
Admin login: ${ADMIN_EMAIL}
|
Admin login: ${ADMIN_EMAIL}
|
||||||
|
|
@ -1237,7 +1309,7 @@ SUMMARY
|
||||||
# Sources existing credentials and redeploys just the named service.
|
# Sources existing credentials and redeploys just the named service.
|
||||||
if [[ "${1:-}" == "--only" ]]; then
|
if [[ "${1:-}" == "--only" ]]; then
|
||||||
ONLY="${2:-}"
|
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 <service> (one of: ${VALID})"
|
[[ -z "$ONLY" ]] && msg_error "Usage: install-stack.sh --only <service> (one of: ${VALID})"
|
||||||
grep -qw "$ONLY" <<< "$VALID" || msg_error "Unknown service '${ONLY}'. Valid: ${VALID}"
|
grep -qw "$ONLY" <<< "$VALID" || msg_error "Unknown service '${ONLY}'. Valid: ${VALID}"
|
||||||
CREDS_FILE=/root/hotel-manage-credentials.txt
|
CREDS_FILE=/root/hotel-manage-credentials.txt
|
||||||
|
|
@ -1261,6 +1333,8 @@ if [[ "${1:-}" == "--only" ]]; then
|
||||||
"$(openssl rand -hex 32)"
|
"$(openssl rand -hex 32)"
|
||||||
[[ -z "${HK_PLANNER_DB_PASS:-}" ]] && _append_secret HK_PLANNER_DB_PASS \
|
[[ -z "${HK_PLANNER_DB_PASS:-}" ]] && _append_secret HK_PLANNER_DB_PASS \
|
||||||
"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)"
|
"$(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
|
USE_FORGEJO=true
|
||||||
[[ -f /root/.ssh/hotel-manage_deploy.pub ]] \
|
[[ -f /root/.ssh/hotel-manage_deploy.pub ]] \
|
||||||
|
|
@ -1276,7 +1350,8 @@ if [[ "${1:-}" == "--only" ]]; then
|
||||||
noticeboard) deploy_noticeboard ;;
|
noticeboard) deploy_noticeboard ;;
|
||||||
settings) deploy_settings ;;
|
settings) deploy_settings ;;
|
||||||
cashup) deploy_cashup ;;
|
cashup) deploy_cashup ;;
|
||||||
hk-planner) deploy_hk_planner ;;
|
hk-planner) deploy_hk_planner ;;
|
||||||
|
twin-optimiser) deploy_twin_optimiser ;;
|
||||||
esac
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
@ -1296,5 +1371,6 @@ deploy_noticeboard
|
||||||
deploy_settings
|
deploy_settings
|
||||||
deploy_cashup
|
deploy_cashup
|
||||||
deploy_hk_planner
|
deploy_hk_planner
|
||||||
|
deploy_twin_optimiser
|
||||||
configure_npm_proxy_hosts
|
configure_npm_proxy_hosts
|
||||||
print_summary
|
print_summary
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue