Add deploy_plant() for the new plant-room monitoring app

LXC 123, no admin-VLAN NIC needed (plant only talks to the shared
MQTT broker over the internal network). Wired into --only dispatch
and the main deploy sequence after deploy_calendar.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-28 22:05:00 +00:00
parent c6c67be8af
commit 046d74ad82

View file

@ -2000,6 +2000,92 @@ ${build_out}"
npm_add_location "/calendar/" "10.10.10.126" 3080 npm_add_location "/calendar/" "10.10.10.126" 3080
} }
# Plant-room equipment monitoring — read-only MQTT telemetry (boilers, water
# softener, calorifiers, pumps). No admin-VLAN NIC needed (unlike hvac): plant
# only subscribes to the shared MQTT broker over the internal network, it never
# talks to devices directly. Depends on deploy_mqtt_broker having already run
# (see the ordering note above deploy_mqtt_broker in the main flow below).
deploy_plant() {
msg_step "Plant Room (LXC 123 · 10.10.10.123)"
if [[ -z "${PLANT_DB_PASS:-}" ]]; then
PLANT_DB_PASS=$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 24)
printf '\nPLANT_DB_PASS=%s\n' "$PLANT_DB_PASS" >> "$CREDS_FILE"
msg_ok "Generated PLANT_DB_PASS → ${CREDS_FILE}"
fi
msg_info "Creating LXC 123"
create_lxc 123 "10.10.10.123" "plant" 1024 1
msg_ok "LXC 123 created"
msg_info "Installing Docker"
install_docker 123
install_mgmt_key 123
msg_ok "Docker + SSH ready"
msg_info "Creating plant database"
pct exec 100 -- bash -c "
docker exec hotel-manage-postgres psql -U postgres -c \
\"CREATE USER plant WITH PASSWORD '${PLANT_DB_PASS}';\" 2>/dev/null || true
docker exec hotel-manage-postgres psql -U postgres -c \
\"CREATE DATABASE plant_db OWNER plant;\" 2>/dev/null || true
docker exec hotel-manage-postgres psql -U postgres -d plant_db -c \
\"GRANT ALL ON SCHEMA public TO plant;\" 2>/dev/null || true
" &>/dev/null
msg_ok "Database plant_db ready"
msg_info "Deploying plant"
deploy_service 123 "plant" "${REPO_ROOT}/plant" /opt/plant
push_file 123 /opt/plant/.env <<EOF
NODE_ENV=production
APP_SLUG=plant
DATABASE_URL=postgresql://plant:${PLANT_DB_PASS}@10.10.10.100:5432/plant_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 123 -- bash -c "cd /opt/plant && docker compose up -d --build 2>&1"); then
msg_error "docker compose build failed in LXC 123:
${build_out}"
fi
msg_info "Waiting for plant"
wait_healthy 123 "http://localhost:3080/plant/health" \
&& msg_ok "Plant Room running at 10.10.10.123:3080" \
|| msg_warn "Plant Room may need extra time — check LXC 123"
msg_info "Seeding plant 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 ('plant', 'Plant Room', 'Plant-room equipment monitoring and alerting — boilers, water softener, calorifiers and pumps via MQTT telemetry', '/plant', 'Gauge', '#0e7490', 'Operations', '10.10.10.123', 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','View the plant-room dashboard and alert list',1),
('manage_assets','Manage Assets','Create/edit assets, alert rules and asset photos',2),
('acknowledge_alerts','Acknowledge Alerts','Acknowledge and resolve triggered alerts',3),
('settings','Settings','Configure plant app settings',4)
) AS c(slug, name, description, sort_order)
WHERE a.slug = 'plant'
ON CONFLICT (app_id, slug) DO NOTHING;
" &>/dev/null \
&& msg_ok "plant seeded into auth DB" \
|| msg_warn "Seed failed — run plant/seed-app.js manually"
npm_add_location "/plant/" "10.10.10.123" 3080
msg_warn "plant deployed but the shared MQTT broker (LXC 104) is separate infra — telemetry ingestion will retry/backoff until it's reachable and the water-softener (or any other) asset is created with its mqtt_topic_prefix set on the Assets page."
}
deploy_kitchen() { deploy_kitchen() {
msg_step "Kitchen (LXC 110 · 10.10.10.110)" msg_step "Kitchen (LXC 110 · 10.10.10.110)"
@ -2482,6 +2568,7 @@ if [[ "${1:-}" == "--only" ]]; then
mqtt-broker) deploy_mqtt_broker ;; mqtt-broker) deploy_mqtt_broker ;;
hvac) deploy_hvac ;; hvac) deploy_hvac ;;
calendar) deploy_calendar ;; calendar) deploy_calendar ;;
plant) deploy_plant ;;
esac esac
exit 0 exit 0
fi fi
@ -2516,5 +2603,6 @@ deploy_kds
deploy_wages deploy_wages
deploy_hvac deploy_hvac
deploy_calendar deploy_calendar
deploy_plant
configure_npm_proxy_hosts configure_npm_proxy_hosts
print_summary print_summary