<< All versions

Skill v1.0.0

currentLLM-judged scan90/100
jcrabapple/hermes-skills/systemd-service-crash-loop-fix
──Details
PublishedOctober 23, 2026 at 08:42 PM
Content Hashsha256:f9755568b905a9a5...
Git SHAd5ec4863cfa1
──Files
Files (1 file, 3.9 KB)
SKILL.md3.9 KBactive
SKILL.md · 121 lines · 3.9 KB

version: "1.0.0" name: systemd-service-crash-loop-fix description: > Diagnose and fix systemd user service crash loops where the service binary can't find its runtime (node, python, etc.) because systemd doesn't inherit the user's shell environment (nvm, pyenv, volta, brew). Use when a service shows status 127 or "No such file or directory" from env, or when journalctl shows repeated restarts every ~5-10s. trigger: > A systemd user service is crash-looping with exit code 127, or journalctl shows errors like "env: 'node': No such file or directory" or "No such file or directory" from a shebang script. The service was installed via nvm, pyenv, volta, or linuxbrew and works when run manually but not under systemd.


Fix Systemd User Service Crash Loops from Missing Runtime PATH

Diagnosis

1. Check service status and restart counter

bash
systemctl --user status <service>.service

Look for:

  • Result: exit-code with status 127 (command not found)
  • High restart counter (thousands = crash looping for hours/days)
  • activating (auto-restart) state

2. Check journal logs for the root cause

bash
journalctl --user -u <service>.service --since "1 hour ago" --no-pager | tail -20

Common errors:

  • env: 'node': No such file or directory — nvm-installed node not in PATH
  • env: 'python3': No such file or directory — pyenv-installed python not in PATH
  • No such file or directory on a script that exists — shebang interpreter missing from PATH

3. Verify the runtime exists but isn't in systemd's PATH

bash
# Check where the runtime actually is
which node python3 # from your shell (works)
# Check what PATH systemd sees
cat ~/.config/systemd/user/<service>.service | grep -i path
# Confirm the binary exists
ls -la ~/.nvm/versions/node/*/bin/node
ls -la ~/.pyenv/shims/python3
ls -la $(brew --prefix)/bin/*

Fix

Add explicit PATH to the service file

Edit the service file and add an Environment="PATH=..." line in the [Service] section:

bash
cat > ~/.config/systemd/user/<service>.service << 'EOF'
[Unit]
Description=<description>
After=network.target
[Service]
Type=simple
WorkingDirectory=<app-dir>
Environment="PATH=~/.nvm/versions/node/v22.21.1/bin:/usr/local/bin:/usr/bin:/bin"
ExecStart=<full-path-to-binary> <args>
Restart=on-failure
RestartSec=10
[Install]
WantedBy=default.target
EOF

Then reload and restart:

bash
systemctl --user daemon-reload
systemctl --user restart <service>.service
systemctl --user status <service>.service

Common PATH values by runtime manager

ManagerRuntimePATH entry
nvmnode~/.nvm/versions/node/vXX.XX.X/bin
pyenvpython~/.pyenv/shims:~/.pyenv/bin
voltanode/npm~/.volta/bin
linuxbrewany$(brew --prefix)/bin

Pitfalls

  • Restart counter in tens of thousands: A service restarting every 10s for 24+ hours accumulates 8,000+ restarts. Fix immediately — it wastes resources and clutters logs.
  • Don't just disable the service: If the user wants it running, fix the PATH. Only disable if the service is genuinely unused.
  • `serve` and other npx-installed tools: Tools installed via npm install -g or bunx use #!/usr/bin/env node shebangs. They break under systemd for the same reason — node isn't in PATH.
  • RestartSec=10 is aggressive: For services that legitimately crash-loop during startup (e.g., waiting for a dependency), consider increasing to 30-60s or adding a ExecStartPre health check.
  • Hardcoded node version: If the service file references a specific nvm node version (e.g., v22.21.1), it will break when node is upgraded. Consider using a symlink or volta instead.

Verification

bash
# Should show "active (running)"
systemctl --user is-active <service>.service
# Check logs for clean startup
journalctl --user -u <service>.service --since "1 min ago" --no-pager
# Verify the service is actually listening
curl -s http://localhost:<port> | head -5
All versions