Skip to content

Add setup script for one-command bootstrap#60

Open
amalbet wants to merge 5 commits intolocal-deploymentfrom
feature/setup-script
Open

Add setup script for one-command bootstrap#60
amalbet wants to merge 5 commits intolocal-deploymentfrom
feature/setup-script

Conversation

@amalbet
Copy link

@amalbet amalbet commented Mar 9, 2026

Summary

  • Add setup.sh that automates full environment bootstrap from scratch
  • Handles: image build, Odoo DB creation + password sync, OpenEMS module install, edge device verification, service healthchecks
  • Idempotent — safe to re-run on an existing setup (skips completed steps)
  • Tested with 4x full destroy + restore cycles

Closes #58

Usage

# Full setup from scratch (build + init + verify)
./setup.sh

# Skip docker compose build (images already exist)
./setup.sh --skip-build

What it does step by step

Step What happens Time
1. Build docker compose build — builds all 6 images ~5s (cached)
2. Start infra Starts db + influxdb first, waits for Postgres ready ~10s
3. Init Odoo Creates openems database, installs OpenEMS module, loads demo data (edge device) ~2-4 min
3b. Sync passwords Sets Odoo UID 1 + admin passwords to match backend config (Icui4cyou) ~5s
4. Verify edge Checks openems_device table for edge0 with correct apikey. Creates or fixes if needed ~1s
5. Start stack docker compose up -d + restart edge for clean backend connection ~20s
6. Verify Polls backend/edge logs every 10s for up to 2 min until all 4 checks pass ~50s

Total: ~4-7 minutes (mostly Odoo module installation)

Default credentials after setup

Service Username Password
OpenEMS UI (localhost:4200) admin Icui4cyou
Odoo (localhost:10016) admin Icui4cyou
Odoo DB manager openemspassword

Troubleshooting

Odoo init takes longer than expected

The odoo -d openems -i openems --stop-after-init step installs Odoo + all dependencies (CRM, Stock, Mail, etc.). On first run with no cache this can take 3-5 minutes. This is normal.

"Authentication failed" in OpenEMS UI

The backend authenticates UI users via Odoo XML-RPC. The setup script syncs passwords automatically, but if you changed the Odoo admin password manually, it must match odooPassword in openems-backend/config.d/Metadata/Odoo.config. Fix:

# Check current backend config
grep odooPassword openems-backend/config.d/Metadata/Odoo.config

# Reset Odoo admin password via Postgres
docker compose exec db psql -U odoo -d openems -c \
  "UPDATE res_users SET password='' WHERE login='admin';"
# Then log into Odoo at localhost:10016 to set a new password

Edge shows "offline" in the UI

The edge may have started before the backend was ready. Restart it:

docker compose restart openems-edge

Verification checks fail

The script polls for 2 minutes. If checks still fail:

# Check if containers are running
docker compose ps

# Check backend logs for errors
docker compose logs --tail=100 openems-backend

# Check edge logs
docker compose logs --tail=100 openems-edge

"Edge device not found" warning

This means Odoo's demo data didn't load the edge device. The script auto-creates it via SQL insert. If you see this warning but the script continues, it's handled.

Edge authentication failed (COMMON_AUTHENTICATION_FAILED)

The edge config apikey must match the openems_device.apikey in Postgres. Verify:

# Check what's in the database
docker compose exec db psql -U odoo -d openems \
  -c "SELECT name, apikey FROM openems_device;"

# Check what's in the edge config
grep apikey openems-edge/config.d/Controller/Api/Backend/*.config

Both values must match. The setup script handles this automatically.

Ports already in use

lsof -i :4200   # UI
lsof -i :8080   # Felix console
lsof -i :8086   # InfluxDB
lsof -i :10016  # Odoo

Starting over completely

docker compose down -v    # removes containers + named volumes
rm -rf postgresql/        # removes Postgres bind mount data
./setup.sh                # rebuild from scratch

Issues found and fixed during testing

Issue Root cause Fix
Verification always failed pipefail + grep -q causes SIGPIPE on docker compose logs pipe Capture logs to variable first, then grep
UI login "auth failed" Fresh Odoo DB has password admin, backend expects Icui4cyou Script sets Odoo passwords via XML-RPC after init
Edge shows offline Edge starts before backend, doesn't auto-reconnect Script restarts edge after full stack start

🤖 Generated with Claude Code

Automates full stack restoration after destroying containers/images:
- Builds images, starts infra services first (db, influxdb)
- Creates Odoo database and installs OpenEMS module via CLI
- Verifies edge device registration and fixes apikey if needed
- Starts remaining services and runs health checks
- Idempotent: skips steps already completed

Closes #58

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@amalbet
Copy link
Author

amalbet commented Mar 9, 2026

Closing — script hasn't been tested yet. Branch feature/setup-script preserved for when we're ready to validate with a full destroy + restore.

@amalbet amalbet closed this Mar 9, 2026
docker compose logs piped to grep -q causes SIGPIPE when grep exits
early, which fails under set -eo pipefail. Fix by capturing logs to a
variable first, then grepping.

Also increased retry window from fixed 20s to 12x10s polling loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@amalbet amalbet reopened this Mar 9, 2026
- After Odoo DB init, set UID 1 and UID 2 passwords to match the
  backend's Metadata/Odoo.config (odooPassword). Without this, the
  backend can't authenticate XML-RPC calls and all UI logins fail.
- Restart edge after full stack start to ensure it connects to the
  backend (edge doesn't auto-reconnect quickly if it starts first).
- Update displayed credentials to reflect the actual password.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant