Skip to content

fix(installer): set PATH on systemd unit and launchd plist#45

Merged
chr1syy merged 1 commit into
mainfrom
fix/systemd-path-include-local-bin
Jun 5, 2026
Merged

fix(installer): set PATH on systemd unit and launchd plist#45
chr1syy merged 1 commit into
mainfrom
fix/systemd-path-include-local-bin

Conversation

@chr1syy
Copy link
Copy Markdown
Collaborator

@chr1syy chr1syy commented Jun 1, 2026

Summary

  • Service-managed maestro-relay (systemd user unit / launchd plist) inherits a minimal PATH that resolves maestro-cli to the older /usr/local/bin/maestro-cli shim (which calls bare node and fails with exit 127 when node isn't on PATH) instead of the newer ~/.local/bin/maestro-cli Electron-backed shim that has no node-on-PATH dependency.
  • Bake a sane PATH into both templates/maestro-relay.service and templates/sh.maestro.relay.plist with $HOME/.local/bin and the node bin directory ahead of system paths, so the user-mode Maestro CLI shim wins and the legacy shim's bare node call still resolves as a fallback.
  • install.sh now derives @HOME@ and @NODE_DIR@ from $HOME and dirname $(command -v node) and substitutes them in both templates.

Why

Reported in production: relay running under systemctl --user would emit [maestro-cli send] exit code: 127 | stderr: /usr/local/bin/maestro-cli: line 2: node: command not found on every message. Root cause is that the systemd unit had no Environment=PATH=…, so the relay's spawned maestro-cli resolved to the wrong shim. The newer Maestro desktop already ships a PATH-resilient shim to ~/.local/bin/maestro-cli; the relay just needs PATH to include that directory.

Rendered output (example)

# systemd unit
Environment=PATH=/home/<user>/.local/bin:/home/<user>/.nvm/versions/node/v22.22.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# launchd plist
export PATH="/Users/<user>/.local/bin:<node-dir>:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin${PATH:+:$PATH}"

Test plan

  • Re-run install.sh on a Linux box; confirm ~/.config/systemd/user/maestro-relay.service contains the new Environment=PATH=… line with the user's actual $HOME and node bin dir substituted in.
  • After systemctl --user daemon-reload && systemctl --user restart maestro-relay, inspect the running process env (tr '\0' '\n' < /proc/$(systemctl --user show maestro-relay -p MainPID --value)/environ | grep PATH) and confirm ~/.local/bin is first.
  • Verify maestro-cli --version resolves to ~/.local/bin/maestro-cli under that PATH (Electron-shim, no node: command not found).
  • Send a Discord mention to a connected agent and confirm the relay no longer logs [maestro-cli send] exit code: 127.
  • On macOS: re-run install.sh, reload the LaunchAgent, and confirm the plist now exports the augmented PATH and the relay can spawn maestro-cli cleanly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved installation process to reliably compute and apply Node.js executable paths during setup.
    • Enhanced service configuration for Linux and macOS to ensure proper binary discovery and execution.

Service-managed maestro-relay processes inherit systemd's minimal PATH,
so they resolve `maestro-cli` to the older /usr/local/bin shim (which
calls bare `node` and fails with exit 127 when node isn't on PATH)
instead of the newer ~/.local/bin Electron-backed shim that has no
node-on-PATH dependency.

Bake a sane PATH into both service templates with $HOME/.local/bin and
the node bin directory ahead of system paths, so the user-mode Maestro
CLI shim is found first and the legacy shim's bare `node` call still
resolves as a fallback. install.sh now derives @HOME@ and @NODE_DIR@
from $HOME and dirname \$(command -v node) and passes them through to
both templates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 59cc0a6e-3c04-488d-90a6-9f8e6212bce4

📥 Commits

Reviewing files that changed from the base of the PR and between 67e737c and ba0eb7e.

📒 Files selected for processing (3)
  • install.sh
  • templates/maestro-relay.service
  • templates/sh.maestro.relay.plist

📝 Walkthrough

Walkthrough

This PR refactors service installation scripts to compute Node.js's executable path once and propagate it consistently through template substitutions. Service templates are updated to explicitly configure PATH variables using the computed node directory for both systemd (Linux) and launchd (macOS) environments.

Changes

Service installation and runtime PATH configuration

Layer / File(s) Summary
Install script path computation refactoring
install.sh
Linux and macOS installation sections now compute node_bin and node_dir once via command -v node and dirname, then substitute both values into the respective service templates consistently.
Service template PATH environment setup
templates/maestro-relay.service, templates/sh.maestro.relay.plist
Systemd unit file adds explicit Environment=PATH with @HOME@/.local/bin and @NODE_DIR@, and macOS plist updates bash command to prepend both paths before executing the Node entrypoint.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A path through the forest, once winding and long,
Now traced but once, and both templates stay strong.
On Linux and Mac, the node shall be found,
With directories crafted and shared all around!

🚥 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 directly describes the main change: fixing PATH configuration in both the systemd unit and launchd plist templates to resolve node executable lookup issues.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/systemd-path-include-local-bin

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.

@chr1syy chr1syy merged commit a65880a into main Jun 5, 2026
3 checks passed
@chr1syy chr1syy deleted the fix/systemd-path-include-local-bin branch June 5, 2026 18:34
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