Skip to content

fix(avahi): start stopped daemon on update#2661

Merged
limetech merged 1 commit into
masterfrom
codex/avahi-update-start-stopped
Jun 10, 2026
Merged

fix(avahi): start stopped daemon on update#2661
limetech merged 1 commit into
masterfrom
codex/avahi-update-start-stopped

Conversation

@elibosley

@elibosley elibosley commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Make rc.avahidaemon update recover Avahi when the daemon is stopped and the computed bind list differs from the current Avahi configuration.

What Changed

  • avahid_update still starts with the existing check and allow-interfaces comparison.
  • If bindings changed and Avahi is running, it uses the existing restart path.
  • If bindings changed and Avahi is stopped, it calls avahid_start.

Why

If Avahi restarts while no suitable network interface is available, it can exit and remain stopped. In the observed failure, the early restart happened while the active interface list had shrunk; when networking later recovered, the computed bind list differed from the saved Avahi allow-interfaces value, but the old update path could not recover because it was guarded by avahid_running.

This alternate fix keeps the patch minimal and focuses on recovery: when a later service update sees the bind list needs to change, it can start Avahi instead of doing nothing.

Relationship To Other PR

Alternative to #2660.

  • This PR fixes recovery after Avahi is stopped and bindings need to be refreshed.
  • fix(avahi): avoid restart on transient iface loss #2660 tries to prevent the early restart during transient interface loss.
  • This PR is smaller and lower-risk, but it does not prevent the initial failed restart.

Verification

  • bash -n etc/rc.d/rc.avahidaemon
  • git diff --check

Review Notes

  • No UI surfaces changed.
  • This keeps existing bind-mismatch restart behavior intact when Avahi is already running.
  • The submitted sketch had a shell typo; the PR uses if avahid_running; then.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Avahi daemon configuration handling to properly manage state transitions when network interfaces change. The service now correctly restarts on configuration updates and automatically starts if previously stopped due to unavailable interfaces, improving reliability in dynamic network environments.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.06.09.1655
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2661/webgui-pr-2661.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates
  • Post-merge behavior: This preview stays available after merge until preview storage expires or it is manually cleaned up

📝 Modified Files:

Click to expand file list
etc/rc.d/rc.avahidaemon

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2661, or run:

plugin remove webgui-pr-2661

🤖 This comment is automatically generated and will be updated with each new push to this PR.

Purpose of the change:
- Let rc.avahidaemon update recover Avahi when the daemon exited during a network transition.

Before this change:
- The update action only did work when Avahi was already running.
- If Avahi failed to restart while no suitable network interface was available, later update calls could not start it again.

Why that was a problem:
- A transient network outage could leave Avahi stopped even after networking recovered.
- Manual restart worked, but the normal service update path could not recover the daemon.

What the new change accomplishes:
- When computed bindings differ from the current Avahi configuration, update restarts Avahi if it is running or starts it if it is stopped.
- Existing restart-on-bind-mismatch behavior remains intact when Avahi is running.

How it works:
- avahid_update runs the existing check and bind mismatch comparison first.
- If the bind list changed and Avahi is running, it uses the existing restart path.
- If the bind list changed and Avahi is stopped, it delegates to avahid_start.
@elibosley elibosley force-pushed the codex/avahi-update-start-stopped branch from dd85954 to de8897b Compare June 9, 2026 16:54
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The avahid_update function now performs conditional config updates when check is enabled and allow-interfaces differs from the running BIND value. It dispatches based on daemon state: restarting if running, or calling avahid_start if stopped, resolving cases where the daemon previously exited due to no suitable interfaces.

Changes

Avahi Daemon Update Logic

Layer / File(s) Summary
Daemon state handling in avahid_update
etc/rc.d/rc.avahidaemon
avahid_update now triggers updates when check is enabled and allow-interfaces differs, then restarts the daemon if running or calls avahid_start if stopped, replacing prior logic that skipped updates when the daemon was inactive.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A daemon once vanished with nary a peep,
When no interfaces suited its keep.
Now avahid_update, precise and aware,
Will start it anew with devoted care—
Happy hopping, dear Avahi, sleep tight! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the Avahi daemon to start when stopped during an update operation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/avahi-update-start-stopped

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

@elibosley elibosley requested a review from limetech June 9, 2026 16:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@etc/rc.d/rc.avahidaemon`:
- Around line 123-129: The current guard (if check && [[ "$(this
allow-interfaces)" != "$BIND" ]]) prevents avahid_start from running when the
daemon is stopped but the allow-interfaces list equals BIND; change the logic so
the outer check only validates "check" (and any BIND sanity you need) and move
the allow-interfaces != BIND test to only gate the avahid_restart path: call
avahid_restart when avahid_running and allow-interfaces differs from BIND, and
call avahid_start when avahid_running is false (regardless of the
allow-interfaces == BIND condition) so stopped-daemon recovery is attempted
independently; reference avahid_running, avahid_restart, avahid_start, check,
BIND and this allow-interfaces in your changes.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8ee16fe6-91db-473a-815b-84b1facc8799

📥 Commits

Reviewing files that changed from the base of the PR and between 982b3c2 and de8897b.

📒 Files selected for processing (1)
  • etc/rc.d/rc.avahidaemon

Comment thread etc/rc.d/rc.avahidaemon
Comment on lines +123 to +129
if check && [[ "$(this allow-interfaces)" != "$BIND" ]]; then
if avahid_running; then
log "Updating $DAEMON..."
avahid_restart # note we need restart here, not reload in order to update interfaces
else
avahid_start # handle case where avahi-daemon exited because no suitable interfaces
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Stopped-daemon recovery is still blocked when bind list matches config.

At Line 123, both restart and start paths are gated by allow-interfaces != BIND. If Avahi is stopped and interfaces recover to the same bind list (common after transient loss), update remains a no-op and Avahi stays down. The mismatch check should gate only the running restart path; the stopped recovery path should be independent (with check/BIND validation).

Suggested fix
 avahid_update(){
-  if check && [[ "$(this allow-interfaces)" != "$BIND" ]]; then
-    if avahid_running; then
-      log "Updating $DAEMON..."
-      avahid_restart # note we need restart here, not reload in order to update interfaces
-    else
-      avahid_start # handle case where avahi-daemon exited because no suitable interfaces
-    fi
-  fi
+  if avahid_running; then
+    if check && [[ "$(this allow-interfaces)" != "$BIND" ]]; then
+      log "Updating $DAEMON..."
+      avahid_restart # note we need restart here, not reload in order to update interfaces
+    fi
+  else
+    # recover daemon when network is back, even if config already matches computed bind list
+    if check && [[ -n $BIND ]]; then
+      log "Recovering $DAEMON..."
+      avahid_start
+    fi
+  fi
 }
🤖 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 `@etc/rc.d/rc.avahidaemon` around lines 123 - 129, The current guard (if check
&& [[ "$(this allow-interfaces)" != "$BIND" ]]) prevents avahid_start from
running when the daemon is stopped but the allow-interfaces list equals BIND;
change the logic so the outer check only validates "check" (and any BIND sanity
you need) and move the allow-interfaces != BIND test to only gate the
avahid_restart path: call avahid_restart when avahid_running and
allow-interfaces differs from BIND, and call avahid_start when avahid_running is
false (regardless of the allow-interfaces == BIND condition) so stopped-daemon
recovery is attempted independently; reference avahid_running, avahid_restart,
avahid_start, check, BIND and this allow-interfaces in your changes.

@elibosley elibosley added the 7.3 label Jun 9, 2026
@limetech limetech merged commit d9c5bbc into master Jun 10, 2026
5 checks passed
@limetech limetech deleted the codex/avahi-update-start-stopped branch June 10, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants