Skip to content

Feature Request: launchd/systemd service for persistent daemon #103

@BTForIT

Description

@BTForIT

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 start after reboot

Potential Issues / Questions

  1. Conflict with happy daemon start: If someone runs happy daemon start manually while launchd is managing it, could get duplicate processes. Maybe needs mutex/lockfile?

  2. Path differences: npm global bin location varies (~/.npm-global/bin, /usr/local/bin, etc.) - would need templating or detection

  3. start-sync vs start: I used start-sync since launchd manages the lifecycle. Is this the right subcommand for service mode?

  4. Updates: After npm update -g happy-coder, does the daemon need restart? launchd's KeepAlive might auto-handle this

  5. 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 file
  • happy 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions