Skip to content

fix(update): restart systemd-managed daemons via their supervisor (#82)#89

Merged
Rinse12 merged 1 commit into
masterfrom
fix/systemd-aware-update-master
Jun 9, 2026
Merged

fix(update): restart systemd-managed daemons via their supervisor (#82)#89
Rinse12 merged 1 commit into
masterfrom
fix/systemd-aware-update-master

Conversation

@Rinse12

@Rinse12 Rinse12 commented Jun 9, 2026

Copy link
Copy Markdown
Member

Why

The systemd-aware update install fix from #82/#83 was merged into chore/upgrade-kubo-0.42.0 rather than master, so it never reached a release. Published 0.19.70 (= master) does not contain it. On a systemd-supervised host, bitsocial update install therefore still:

  1. SIGINTs the running daemon → systemd (Restart=on-failure) respawns it, and
  2. the updater also spawns its own detached replacement,

so two daemons race for the RPC port; the updater's loses, dies after printing its flags, and leaves an orphan log that wedges bitsocial logs -f. Observed live on the new-plebbit prod host today.

What

Cherry-pick of the isolated fix commit (d995ebb) onto latest master — no version regression, no unrelated churn from the stale kubo branch. Makes update install supervisor-aware: a daemon running under systemd is restarted via systemctl restart <unit> instead of being killed and re-spawned by the updater (which competes with the supervisor for the RPC port).

Includes:

  • src/update/restart-orchestration.ts — partition daemons into supervised vs. updater-managed; route restarts accordingly.
  • src/update/systemctl.ts — thin systemctl restart wrapper.
  • src/common-utils/daemon-state.ts — record/resolve a daemon's supervisor (systemd unit via cgroup); record it at startup, fall back to live-cgroup inference for legacy daemons.
  • src/cli/commands/update/install.ts — wait for full process exit (not just RPC port free) before the swap, and restart supervised daemons through their supervisor.
  • Tests for orchestration, systemctl wrapper, supervisor detection, and the systemd-aware install path.

Verification

  • npm run build && npm run build:test pass against latest master.
  • Cherry-pick applied cleanly (no conflicts).
  • CI runs the full suite on this PR.

Supersedes the stale chore/upgrade-kubo-0.42.0 carrying #83 (that branch is behind master and would regress the version).

`update install` stopped every running daemon and re-spawned it detached,
escaping any external supervisor. On a systemd host the detached daemon
competed with systemd for the PKC RPC port, so systemd's own unit could
never bind and crash-looped on "PKC RPC port is already in use".

The daemon now records its supervisor at startup (systemd, via $INVOCATION_ID
+ /proc/self/cgroup) in its state file. `update install` partitions running
daemons: unsupervised ones keep the SIGINT + detached-respawn path, while
supervised ones are left running across the binary swap and restarted with
`systemctl restart <unit>`. Legacy daemons without the field fall back to
inferring the unit from /proc/<pid>/cgroup; non-Linux falls back to current
behavior.

Tests: cgroup parser, supervisor detection/resolution, restart routing
(pure, injectable lifecycle), the systemctl command, and an E2E proving a
supervised daemon survives `update install` and is never detached-spawned
(red against the old code, green after the fix).

Refs #82
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

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

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ 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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a0b7490-71fd-4b7f-ad95-5aea4f4e7155

📥 Commits

Reviewing files that changed from the base of the PR and between 67efae8 and 49a7026.

📒 Files selected for processing (9)
  • src/cli/commands/daemon.ts
  • src/cli/commands/update/install.ts
  • src/common-utils/daemon-state.ts
  • src/update/restart-orchestration.ts
  • src/update/systemctl.ts
  • test/cli/update-install-systemd-aware.test.ts
  • test/common-utils/daemon-supervisor.test.ts
  • test/update/restart-orchestration.test.ts
  • test/update/systemctl.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/systemd-aware-update-master

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 and usage tips.

@Rinse12 Rinse12 merged commit bab7288 into master Jun 9, 2026
3 of 4 checks passed
Rinse12 added a commit that referenced this pull request Jun 12, 2026
…stemd-managed (issue #92)

$INVOCATION_ID and a .service cgroup leaf are inherited by every
descendant of any systemd service — e.g. all processes inside a GitHub
Actions runner (hosted-compute-agent.service) — so unit membership
alone misidentified daemons as supervised and update install skipped
restarting them (failing master CI on ubuntu since PR #89).

detectSelfSupervisor and the legacy cgroup fallback in
resolveDaemonSupervisor now also require the unit's MainPID (via
systemctl show) to be the daemon itself or its direct parent (covering
ExecStart shell wrappers). When MainPID can't be read the daemon is
treated as unsupervised, restoring the pre-#82 direct-restart path.
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