Add deploy_maintenance (LXC 121 · 10.10.10.121) + --only dispatch
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
7e317e9d4e
commit
b3af8d8849
1 changed files with 90 additions and 1 deletions
|
|
@ -1160,6 +1160,93 @@ ${build_out}"
|
||||||
npm_add_location "/room-planner/" "10.10.10.120" 3080
|
npm_add_location "/room-planner/" "10.10.10.120" 3080
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deploy_maintenance() {
|
||||||
|
msg_step "12/12 Maintenance (LXC 121 · 10.10.10.121)"
|
||||||
|
|
||||||
|
if [[ -z "${MAINTENANCE_DB_PASS:-}" ]]; then
|
||||||
|
MAINTENANCE_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)
|
||||||
|
printf '\nMAINTENANCE_DB_PASS=%s\n' "$MAINTENANCE_DB_PASS" >> "$CREDS_FILE"
|
||||||
|
msg_ok "Generated MAINTENANCE_DB_PASS → ${CREDS_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg_info "Creating LXC 121"
|
||||||
|
create_lxc 121 "10.10.10.121" "maintenance" 1024 1
|
||||||
|
msg_ok "LXC 121 created"
|
||||||
|
|
||||||
|
msg_info "Installing Docker"
|
||||||
|
install_docker 121
|
||||||
|
install_mgmt_key 121
|
||||||
|
msg_ok "Docker + SSH ready"
|
||||||
|
|
||||||
|
msg_info "Creating maintenance database"
|
||||||
|
pct exec 100 -- bash -c "
|
||||||
|
docker exec hotel-manage-postgres psql -U postgres -c \
|
||||||
|
\"CREATE USER maintenance WITH PASSWORD '${MAINTENANCE_DB_PASS}';\" 2>/dev/null || true
|
||||||
|
docker exec hotel-manage-postgres psql -U postgres -c \
|
||||||
|
\"CREATE DATABASE maintenance_db OWNER maintenance;\" 2>/dev/null || true
|
||||||
|
docker exec hotel-manage-postgres psql -U postgres -d maintenance_db -c \
|
||||||
|
\"GRANT ALL ON SCHEMA public TO maintenance;\" 2>/dev/null || true
|
||||||
|
" &>/dev/null
|
||||||
|
msg_ok "Database maintenance_db ready"
|
||||||
|
|
||||||
|
msg_info "Deploying maintenance"
|
||||||
|
deploy_service 121 "maintenance" "${REPO_ROOT}/maintenance" /opt/maintenance
|
||||||
|
|
||||||
|
push_file 121 /opt/maintenance/.env <<EOF
|
||||||
|
NODE_ENV=production
|
||||||
|
APP_SLUG=maintenance
|
||||||
|
DATABASE_URL=postgresql://maintenance:${MAINTENANCE_DB_PASS}@10.10.10.100:5432/maintenance_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}}
|
||||||
|
FRONTEND_PORT=3080
|
||||||
|
EOF
|
||||||
|
|
||||||
|
local build_out
|
||||||
|
if ! build_out=$(pct exec 121 -- bash -c "cd /opt/maintenance && docker compose up -d --build 2>&1"); then
|
||||||
|
msg_error "docker compose build failed in LXC 121:
|
||||||
|
${build_out}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg_info "Waiting for maintenance"
|
||||||
|
wait_healthy 121 "http://localhost:3080/maintenance/health" \
|
||||||
|
&& msg_ok "Maintenance running at 10.10.10.121:3080" \
|
||||||
|
|| msg_warn "Maintenance may need extra time — check LXC 121"
|
||||||
|
|
||||||
|
# Seed app + capabilities into auth DB (psql on LXC 100 — same pattern as add-app.sh)
|
||||||
|
msg_info "Seeding maintenance 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 ('maintenance', 'Maintenance', 'Maintenance log book — faults, recurring tasks, assets and contractors', '/maintenance', 'Wrench', '#b45309', 'Operations', '10.10.10.121', 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','View Tasks','View the maintenance log and history',1),
|
||||||
|
('report','Report Faults','Create tasks, add photos and comments',2),
|
||||||
|
('update','Update Tasks','Change task state, reassign, edit details',3),
|
||||||
|
('resolve','Resolve Tasks','Mark tasks temporary fixed or fixed',4),
|
||||||
|
('costs','View Costs','See and enter repair cost values',5),
|
||||||
|
('manage_locations','Manage Locations','Manage locations, categories and NewBook sync',6),
|
||||||
|
('manage_assets','Manage Assets','Create and edit the asset register',7),
|
||||||
|
('manage_contractors','Manage Contractors','Manage contractors and their documents',8),
|
||||||
|
('manage_templates','Manage Recurring','Create and edit recurring task templates',9),
|
||||||
|
('settings','Settings','Configure maintenance app settings',10)
|
||||||
|
) AS c(slug, name, description, sort_order)
|
||||||
|
WHERE a.slug = 'maintenance'
|
||||||
|
ON CONFLICT (app_id, slug) DO NOTHING;
|
||||||
|
" &>/dev/null \
|
||||||
|
&& msg_ok "maintenance seeded into auth DB" \
|
||||||
|
|| msg_warn "Seed failed — run maintenance/seed-app.js manually via psql on LXC 100"
|
||||||
|
|
||||||
|
# Add /maintenance/ location to NPM proxy host
|
||||||
|
npm_add_location "/maintenance/" "10.10.10.121" 3080
|
||||||
|
}
|
||||||
|
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
# ════════════════════════════════════════════════════════════════════════════
|
||||||
# NPM PROXY HOSTS (via API)
|
# NPM PROXY HOSTS (via API)
|
||||||
# ════════════════════════════════════════════════════════════════════════════
|
# ════════════════════════════════════════════════════════════════════════════
|
||||||
|
|
@ -1408,7 +1495,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 twin-optimiser room-planner"
|
VALID="postgres auth portal npm management noticeboard settings cashup hk-planner twin-optimiser room-planner maintenance"
|
||||||
[[ -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
|
||||||
|
|
@ -1452,6 +1539,7 @@ if [[ "${1:-}" == "--only" ]]; then
|
||||||
hk-planner) deploy_hk_planner ;;
|
hk-planner) deploy_hk_planner ;;
|
||||||
twin-optimiser) deploy_twin_optimiser ;;
|
twin-optimiser) deploy_twin_optimiser ;;
|
||||||
room-planner) deploy_room_planner ;;
|
room-planner) deploy_room_planner ;;
|
||||||
|
maintenance) deploy_maintenance ;;
|
||||||
esac
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
@ -1473,5 +1561,6 @@ deploy_cashup
|
||||||
deploy_hk_planner
|
deploy_hk_planner
|
||||||
deploy_twin_optimiser
|
deploy_twin_optimiser
|
||||||
deploy_room_planner
|
deploy_room_planner
|
||||||
|
deploy_maintenance
|
||||||
configure_npm_proxy_hosts
|
configure_npm_proxy_hosts
|
||||||
print_summary
|
print_summary
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue