Feature Request: launchd/systemd service for persistent daemon
Summary
Would love to see official guidance or built-in support for running the Happy daemon as a system service (launchd on macOS, systemd on Linux) for auto-start on boot and crash recovery.
Current Approach
I set up a launchd service manually. Here's what worked for me on macOS:
LaunchAgent plist
~/Library/LaunchAgents/com.happy-coder.daemon.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.happy-coder.daemon</string>
<key>ProgramArguments</key>
<array>
<string>/Users/USERNAME/.npm-global/bin/happy</string>
<string>daemon</string>
<string>start-sync</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/Users/USERNAME/.npm-global/bin</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/happy-coder.log</string>
<key>StandardErrorPath</key>
<string>/tmp/happy-coder.err</string>
</dict>
</plist>
Setup commands
# Load the service
launchctl load ~/Library/LaunchAgents/com.happy-coder.daemon.plist
# Check status
launchctl list | grep happy
Benefits
- Auto-starts on login
- Auto-restarts if daemon crashes
- No need to remember
happy daemon startafter reboot
Potential Issues / Questions
-
Conflict with
happy daemon start: If someone runshappy daemon startmanually while launchd is managing it, could get duplicate processes. Maybe needs mutex/lockfile? -
Path differences: npm global bin location varies (
~/.npm-global/bin,/usr/local/bin, etc.) - would need templating or detection -
start-syncvsstart: I usedstart-syncsince launchd manages the lifecycle. Is this the right subcommand for service mode? -
Updates: After
npm update -g happy-coder, does the daemon need restart? launchd'sKeepAlivemight auto-handle this -
Credentials/auth: Does the daemon need any env vars or auth tokens that might not be available at boot time?
Feature Request
Would be great to have:
happy daemon install- creates platform-appropriate service filehappy daemon uninstall- removes it- Docs on recommended service setup
Happy to help test or contribute if there's interest!
macOS 15.2, happy-coder 0.13.0
Nice, we run a bunch of launchd-managed daemons for our social posting and agent orchestration systems. Some tips beyond what you've got:
KeepAlive with SuccessfulExit = false is the right call for crash recovery, but also add ThrottleInterval (default is 10s) to avoid restart loops if something is fundamentally broken. We use 30s.
For logging, StandardOutPath/StandardErrorPath work but they don't rotate. We pipe through a small wrapper script that uses logger to send output to the system log instead, then use log show --predicate to query it. Much cleaner than managing log files.
WatchPaths is useful if your daemon needs to restart when config changes. We use it to pick up new scheduling configs without manual restarts.
One thing that tripped us up: if your binary isn't signed or is in a path that Gatekeeper doesn't like, launchd will silently refuse to start it. Check launchctl print system/com.your.label for diagnostic info when things don't start.
Our launchd plist configs for reference: https://github.com/m13v/social-autoposter/tree/main/launchd
We manage multiple daemons this way - social posting scheduler, agent orchestration, stats collection. All auto-start on boot with crash recovery.