Skip to content

Fix emqx data dir and bump emqx version#164

Open
id wants to merge 5 commits into
hassio-addons:mainfrom
id:fix-emqx-data-dir-bump-version
Open

Fix emqx data dir and bump emqx version#164
id wants to merge 5 commits into
hassio-addons:mainfrom
id:fix-emqx-data-dir-bump-version

Conversation

@id

@id id commented Jun 23, 2026

Copy link
Copy Markdown

Proposed Changes

Related Issues

#161
#158

Summary by CodeRabbit

  • New Features

    • EMQX node name now persists across restarts and upgrades, ensuring consistent identity.
    • Enhanced hostname mapping to improve container connectivity.
  • Documentation

    • Updated documentation with node name persistence behavior and configuration guidance.
  • Chores

    • Upgraded EMQX to version 6.2.1.
    • Added upgrade scenario testing to CI pipeline.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@id, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 16 minutes and 28 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a664c72-31e2-4bd5-8e88-788ec67f1dd4

📥 Commits

Reviewing files that changed from the base of the PR and between 16d98fb and 573733e.

📒 Files selected for processing (5)
  • .github/scripts/emqx-upgrade-test.sh
  • .github/workflows/ci.yaml
  • README.md
  • emqx/DOCS.md
  • emqx/rootfs/etc/s6-overlay/s6-rc.d/emqx/run

Walkthrough

Adds node name persistence to the EMQX s6 run script: it reads a stored node.name file, falls back to Mnesia directory discovery with multi-directory handling, writes the chosen name back, and ensures /etc/hosts resolution. Adds a four-scenario upgrade test script and CI job. Bumps EMQX to v6.2.1 enterprise and updates documentation.

Changes

EMQX Node Name Persistence and Upgrade Testing

Layer / File(s) Summary
EMQX version and artifact name update
emqx/Dockerfile
Default EMQX_VERSION changes from v5.8.9 to 6.2.1 and the download tarball switches to the emqx-enterprise-${EMQX_VERSION} naming format.
Node name discovery, persistence, and host resolution
emqx/rootfs/etc/s6-overlay/s6-rc.d/emqx/run
Replaces static EMQX_HOST/EMQX_NODE__NAME initialization with a flow that reads /data/emqx/etc/node.name, falls back to Mnesia directory inspection (zero/one/multiple cases), writes the chosen name back, exports all derived env vars, and appends a 127.0.0.1 entry to /etc/hosts when the host is not resolvable.
Upgrade test harness
.github/scripts/emqx-upgrade-test.sh
New Bash test script that writes a mocked bashio runner inside a container, provides directory setup and assertion helpers, and runs four scenarios: new install, single legacy Mnesia directory, persisted node name override, and ambiguous Mnesia directories.
CI upgrade-test job
.github/workflows/ci.yaml
Adds an upgrade-test job that builds the EMQX image for linux/amd64 and runs the upgrade test script with IMAGE and PLATFORM env vars.
Documentation updates
README.md, emqx/DOCS.md
Expands EMQX description copy, adds node name persistence guidance (new vs. existing installs, multiple Mnesia directory scenario and remediation), and updates the env_vars docs URL to the latest EMQX configuration page.

Sequence Diagram(s)

sequenceDiagram
    participant HA as Home Assistant s6
    participant Run as emqx/run script
    participant FS as /data/emqx filesystem
    participant Hosts as /etc/hosts

    HA->>Run: start EMQX service
    Run->>FS: read /data/emqx/etc/node.name
    alt node.name exists
        FS-->>Run: return persisted node name
    else no node.name
        Run->>FS: list /data/emqx/data/mnesia subdirs
        alt 0 subdirs
            Run->>Run: use default node name
        else 1 subdir
            Run->>Run: use legacy directory node name
        else multiple subdirs
            Run->>Run: warn, use fallback/default node name
        end
    end
    Run->>FS: write chosen name to /data/emqx/etc/node.name
    Run->>Run: export EMQX_HOST, EMQX_NAME, EMQX_NODE__NAME, dirs
    Run->>Hosts: getent hosts EMQX_HOST
    alt host not resolvable
        Run->>Hosts: append 127.0.0.1 EMQX_HOST
    end
    Run->>HA: exec EMQX foreground with resolved node name
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 A rabbit once changed its burrow's name,
And lost all its carrots — such a shame!
Now node.name is saved to a file,
Mnesia dirs checked with care and style,
/etc/hosts patched if the host goes astray,
Upgrade scenarios all pass — hip hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix emqx data dir and bump emqx version' accurately describes the main changes: fixing the data directory issue (#161) and upgrading EMQX to 6.2.1.
Linked Issues check ✅ Passed The PR successfully addresses issue #161 by deriving node names from persisted data or Mnesia directories, handling hostname changes gracefully, documenting the behavior, and adding comprehensive CI tests for upgrade scenarios.
Out of Scope Changes check ✅ Passed All changes directly support the PR objectives: the Docker version bump and Dockerfile changes align with the version upgrade, documentation updates explain the node name persistence fix, and the new test script validates the upgrade scenarios.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
.github/workflows/ci.yaml (1)

18-39: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a timeout for the upgrade-test job.

This Docker-heavy job can hang indefinitely on runner/network edge cases; add timeout-minutes at the job level to fail fast and keep CI unblocked.

Suggested change
   upgrade-test:
     name: EMQX Upgrade Test
     runs-on: ubuntu-latest
+    timeout-minutes: 20
     permissions:
       contents: read
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yaml around lines 18 - 39, The upgrade-test job lacks a
timeout mechanism and can hang indefinitely due to runner or network edge cases.
Add a timeout-minutes property at the job level (positioned after the job name
and before the runs-on field) to specify an appropriate timeout threshold that
will fail the job quickly if it exceeds the time limit, keeping the CI pipeline
unblocked.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@emqx/DOCS.md`:
- Around line 3-12: The markdown links in DOCS.md use invalid syntax with square
brackets around the URL. Fix both malformed links by changing the syntax from
[text][https://url] to [text](url) using parentheses instead of square brackets.
Locate the two links for "EMQX" and "EMQX MQTT broker" that reference
https://www.emqx.com/en/products/emqx and update them to use proper inline link
syntax with parentheses.

In `@emqx/rootfs/etc/s6-overlay/s6-rc.d/emqx/run`:
- Around line 21-39: The node_name variable read from the persisted
node_name_file at the beginning of the conditional block is used without
validation, which could lead to malformed values poisoning environment variables
like EMQX_HOST and /etc/hosts entries. Add validation logic after the node_name
is determined (after the first if-elif-else chain that sets node_name) to ensure
it contains only valid characters for a hostname or node identifier before it is
written back to the node_name_file. Additionally, validate node_name at the
locations referenced in lines 61-64 where it is used for environment setup and
/etc/hosts configuration to prevent invalid entries from being written.

In `@README.md`:
- Around line 27-36: The README.md file contains malformed markdown link syntax
using the format [text][https://url] on two occasions where EMQX is referenced.
Replace these with the correct inline link syntax [text](url) using parentheses
instead of square brackets for the URL. Specifically, fix the EMQX links that
currently use square brackets around the full URL to use parentheses instead,
which is the proper markdown format for inline links.

---

Nitpick comments:
In @.github/workflows/ci.yaml:
- Around line 18-39: The upgrade-test job lacks a timeout mechanism and can hang
indefinitely due to runner or network edge cases. Add a timeout-minutes property
at the job level (positioned after the job name and before the runs-on field) to
specify an appropriate timeout threshold that will fail the job quickly if it
exceeds the time limit, keeping the CI pipeline unblocked.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0998c30e-96b4-4959-a352-5ca79c1c4446

📥 Commits

Reviewing files that changed from the base of the PR and between 11bc911 and 16d98fb.

📒 Files selected for processing (6)
  • .github/scripts/emqx-upgrade-test.sh
  • .github/workflows/ci.yaml
  • README.md
  • emqx/DOCS.md
  • emqx/Dockerfile
  • emqx/rootfs/etc/s6-overlay/s6-rc.d/emqx/run

Comment thread emqx/DOCS.md Outdated
Comment thread emqx/rootfs/etc/s6-overlay/s6-rc.d/emqx/run
Comment thread README.md Outdated
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.

Changing Home Assistant hostname leads to soft "data loss" in EMQX

1 participant