Add hk-planner service (LXC 118) to installer and --only mode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b124abf8c4
commit
95b3741d23
1 changed files with 119 additions and 2 deletions
121
install-stack.sh
121
install-stack.sh
|
|
@ -251,6 +251,7 @@ gen_secrets() {
|
|||
NOTICES_DB_PASS=$(sed -n 's/^NOTICES_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)
|
||||
HK_PLANNER_DB_PASS=$(sed -n 's/^HK_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)
|
||||
|
|
@ -267,6 +268,7 @@ gen_secrets() {
|
|||
NOTICES_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)
|
||||
HK_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)
|
||||
|
|
@ -287,6 +289,7 @@ AUTH_DB_PASS=${AUTH_DB_PASS}
|
|||
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}
|
||||
CENTRAL_AUTH_SECRET=${CENTRAL_AUTH_SECRET}
|
||||
SETTINGS_SECRET=${SETTINGS_SECRET}
|
||||
WEBHOOK_SECRET=${WEBHOOK_SECRET}
|
||||
|
|
@ -599,6 +602,14 @@ CREATE USER cashup WITH PASSWORD '${CASHUP_DB_PASS}';
|
|||
CREATE DATABASE cashup_db OWNER cashup;
|
||||
\c cashup_db
|
||||
GRANT ALL ON SCHEMA public TO cashup;
|
||||
EOF
|
||||
|
||||
# Init SQL — hk-planner DB
|
||||
push_file 100 /opt/postgres/init/05-hk-planner.sql <<EOF
|
||||
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
|
||||
|
||||
pct exec 100 -- bash -c "cd /opt/postgres && docker compose up -d" &>/dev/null
|
||||
|
|
@ -964,6 +975,106 @@ print(json.dumps(locs))
|
|||
fi
|
||||
}
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
# PHASE 9 — HK PLANNER LXC 118
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
deploy_hk_planner() {
|
||||
msg_step "9/9 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)
|
||||
printf '\nHK_PLANNER_DB_PASS=%s\n' "$HK_PLANNER_DB_PASS" >> "$CREDS_FILE"
|
||||
msg_ok "Generated HK_PLANNER_DB_PASS → ${CREDS_FILE}"
|
||||
fi
|
||||
|
||||
msg_info "Creating LXC 118"
|
||||
create_lxc 118 "10.10.10.118" "hk-planner" 1024 1
|
||||
msg_ok "LXC 118 created"
|
||||
|
||||
msg_info "Installing Docker"
|
||||
install_docker 118
|
||||
install_mgmt_key 118
|
||||
msg_ok "Docker + SSH ready"
|
||||
|
||||
msg_info "Creating hk_planner database"
|
||||
pct exec 100 -- bash -c "
|
||||
docker exec hotel-manage-postgres psql -U postgres -c \
|
||||
\"CREATE USER hk_planner WITH PASSWORD '${HK_PLANNER_DB_PASS}';\" 2>/dev/null || true
|
||||
docker exec hotel-manage-postgres psql -U postgres -c \
|
||||
\"CREATE DATABASE hk_planner_db OWNER hk_planner;\" 2>/dev/null || true
|
||||
docker exec hotel-manage-postgres psql -U postgres -d hk_planner_db -c \
|
||||
\"GRANT ALL ON SCHEMA public TO hk_planner;\" 2>/dev/null || true
|
||||
" &>/dev/null
|
||||
msg_ok "Database hk_planner_db ready"
|
||||
|
||||
msg_info "Deploying hk-planner"
|
||||
deploy_service 118 "hk-planner" "${REPO_ROOT}/hk-planner" /opt/hk-planner
|
||||
|
||||
push_file 118 /opt/hk-planner/.env <<EOF
|
||||
NODE_ENV=production
|
||||
APP_SLUG=hk-planner
|
||||
DATABASE_URL=postgresql://hk_planner:${HK_PLANNER_DB_PASS}@10.10.10.100:5432/hk_planner_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 118 -- bash -c "cd /opt/hk-planner && docker compose up -d --build 2>&1"); then
|
||||
msg_error "docker compose build failed in LXC 118:
|
||||
${build_out}"
|
||||
fi
|
||||
|
||||
msg_info "Waiting for hk-planner"
|
||||
wait_healthy 118 "http://localhost:3080/hk-planner/health" \
|
||||
&& msg_ok "HK Planner running at 10.10.10.118:3080" \
|
||||
|| msg_warn "HK Planner may need extra time — check LXC 118"
|
||||
|
||||
# Add /hk-planner/ location to NPM proxy host
|
||||
msg_info "Adding /hk-planner/ to NPM proxy"
|
||||
local npm_token; npm_token=$(npm_get_token)
|
||||
local npm_ip="${NPM_LAN_IP:-10.10.10.103}"
|
||||
if [[ -n "$npm_token" ]]; then
|
||||
local host_id
|
||||
host_id=$(curl -sf "http://${npm_ip}:81/api/nginx/proxy-hosts" \
|
||||
-H "Authorization: Bearer ${npm_token}" 2>/dev/null \
|
||||
| grep -o '"id":[0-9]*,"domain_names":\["'"${DOMAIN}"'"\]' \
|
||||
| grep -o '"id":[0-9]*' | cut -d: -f2) || true
|
||||
if [[ -n "$host_id" ]]; then
|
||||
local existing
|
||||
existing=$(curl -sf "http://${npm_ip}:81/api/nginx/proxy-hosts/${host_id}" \
|
||||
-H "Authorization: Bearer ${npm_token}" 2>/dev/null) || true
|
||||
if [[ -n "$existing" ]] && ! echo "$existing" | grep -q '"/hk-planner/"'; then
|
||||
local merged_locations
|
||||
merged_locations=$(echo "$existing" | python3 -c "
|
||||
import sys, json
|
||||
d = json.load(sys.stdin)
|
||||
locs = d.get('locations') or []
|
||||
locs.append({'path':'/hk-planner/','forward_scheme':'http','forward_host':'10.10.10.118','forward_port':3080,'advanced_config':''})
|
||||
print(json.dumps(locs))
|
||||
" 2>/dev/null) || true
|
||||
if [[ -n "$merged_locations" ]]; then
|
||||
curl -sf -X PUT "http://${npm_ip}:81/api/nginx/proxy-hosts/${host_id}" \
|
||||
-H "Authorization: Bearer ${npm_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"locations\":${merged_locations}}" &>/dev/null \
|
||||
&& msg_ok "NPM location /hk-planner/ added" \
|
||||
|| msg_warn "NPM update failed — add /hk-planner/ → 10.10.10.118:3080 manually"
|
||||
fi
|
||||
else
|
||||
msg_ok "NPM location /hk-planner/ already present"
|
||||
fi
|
||||
else
|
||||
msg_warn "NPM proxy host for ${DOMAIN} not found — add /hk-planner/ → 10.10.10.118:3080 manually"
|
||||
fi
|
||||
else
|
||||
msg_warn "NPM API unavailable — add /hk-planner/ → 10.10.10.118:3080 manually in NPM admin"
|
||||
fi
|
||||
}
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
# NPM PROXY HOSTS (via API)
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
|
|
@ -1033,7 +1144,8 @@ configure_npm_proxy_hosts() {
|
|||
{"path":"/api/auth/","forward_scheme":"http","forward_host":"10.10.10.101","forward_port":3001,"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":"/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":""}
|
||||
]'
|
||||
|
||||
local result; result=$(create_proxy_host "10.10.10.102" 3000 "$locations")
|
||||
|
|
@ -1074,6 +1186,7 @@ SUMMARY
|
|||
112 hotel-manage-noticeboard 10.10.10.112 3080 /notices/
|
||||
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/
|
||||
|
||||
── Credentials ───────────────────────────────────────────────
|
||||
Admin login: ${ADMIN_EMAIL}
|
||||
|
|
@ -1113,7 +1226,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"
|
||||
VALID="postgres auth portal npm management noticeboard settings cashup hk-planner"
|
||||
[[ -z "$ONLY" ]] && msg_error "Usage: install-stack.sh --only <service> (one of: ${VALID})"
|
||||
grep -qw "$ONLY" <<< "$VALID" || msg_error "Unknown service '${ONLY}'. Valid: ${VALID}"
|
||||
CREDS_FILE=/root/hotel-manage-credentials.txt
|
||||
|
|
@ -1135,6 +1248,8 @@ if [[ "${1:-}" == "--only" ]]; then
|
|||
"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)"
|
||||
[[ -z "${SETTINGS_SECRET:-}" ]] && _append_secret SETTINGS_SECRET \
|
||||
"$(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)"
|
||||
|
||||
USE_FORGEJO=true
|
||||
[[ -f /root/.ssh/hotel-manage_deploy.pub ]] \
|
||||
|
|
@ -1150,6 +1265,7 @@ if [[ "${1:-}" == "--only" ]]; then
|
|||
noticeboard) deploy_noticeboard ;;
|
||||
settings) deploy_settings ;;
|
||||
cashup) deploy_cashup ;;
|
||||
hk-planner) deploy_hk_planner ;;
|
||||
esac
|
||||
exit 0
|
||||
fi
|
||||
|
|
@ -1168,5 +1284,6 @@ deploy_management
|
|||
deploy_noticeboard
|
||||
deploy_settings
|
||||
deploy_cashup
|
||||
deploy_hk_planner
|
||||
configure_npm_proxy_hosts
|
||||
print_summary
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue