Privileged daemon and autostart subcommands for a single binary installation - #8
Merged
Conversation
…inary distribution
There was a problem hiding this comment.
Pull request overview
This PR adds first-class launchd and autoconnect subcommands to manage a privileged on-demand daemon and a per-user LaunchAgent from the tunmux binary itself, reducing Makefile duplication and improving resilience around userspace tunnel state.
Changes:
- Add
tunmux launchd install|restart|uninstallwith plist templating, binary-location validation, and setup of group/dirs/plist/bootstrapping. - Add
tunmux autoconnect install|list|reload|uninstallwith plist templating, atomic writes, and GUI-domainlaunchctlmanagement. - Harden userspace liveness probing and add “adopt live wgconf0 without saved state” recovery for desync scenarios; update
statusoutput formatting.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wireguard/userspace.rs | Adds retrying userspace interface liveness probe via privileged daemon. |
| src/wgconf/handlers.rs | Re-adopts a live wgconf0 interface by recreating missing saved state. |
| src/main.rs | Adds top-level dispatch for new subcommands; improves status rendering and attempts to reconcile live wgconf0. |
| src/lib.rs | Exposes new autoconnect, launchctl, and launchd modules from the library crate. |
| src/launchd.rs | Implements privileged daemon launchd installer/uninstaller with template rendering and safety checks. |
| src/launchctl.rs | Shared helpers for running launchctl, atomic file removal, and XML escaping. |
| src/cli.rs | Adds launchd and autoconnect subcommands and parsing tests. |
| src/autoconnect.rs | Implements per-user autoconnect LaunchAgent installer/list/reload/uninstall. |
| Makefile | Delegates privileged/autostart install/reload/uninstall flows to the tunmux binary. |
| etc/me.pansen.tunmux.privileged.plist | Switches to install-time placeholders for binary path and socket group. |
| etc/me.pansen.tunmux.autoconnect.plist | Switches to install-time placeholders for binary path, HOME, and connect source. |
| doc/launchd-socket-activation.md | Updates documentation to reflect Makefile delegation to tunmux launchd. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves the last two pieces of daemon/agent lifecycle management out of the Makefile and into the
tunmuxbinary itself, so a single-binary distribution (e.g. a Homebrew bottle) no longer depends on shell scripting for install/uninstall. Also fixes a few liveness/status consistency issues surfaced along the way.New commands
tunmux launchd install|restart|uninstallRegisters, restarts, and unregisters the privileged system daemon (
me.pansen.tunmux.privileged) as a macOS LaunchDaemon.install(run viasudo) creates thetunmuxgroup, sets up the socket/log directories, renders and installs the daemon's plist, and bootstraps it into thesystemdomain.restartkickstarts the running daemon;uninstallboots it out and removes the plist while leaving the binary, group, and logs in place.tunmux autoconnect install|reload|uninstall|list(aliasls)Registers, reloads, unregisters, and lists the per-user autoconnect LaunchAgent (
me.pansen.tunmux.autoconnect), which keeps a chosen WireGuard profile connected at login. Runs unprivileged (never viasudo) in the user's GUI domain.install --file <path>orinstall --profile <name>renders and installs the agent's plist, then bootstraps and kicks it. Fails if an agent is already installed, unless--forceis given, in which case it overwrites the plist and reloads unconditionally — protecting an existing autoconnect profile from being silently clobbered.reloadkickstarts the currently installed agent.uninstallboots it out and removes its plist.list/lsshows every installed agent with its load state (🟢 active / 🔘 inactive) and the profile it connects.tunmux statusReworked to show connections from the privileged daemon, with liveness now checked consistently across all backends (not just userspace) so stale entries from a reboot/crash aren't reported as active.
Other fixes
status's direct-tunnel check now goes through the same cold-start-aware probe used elsewhere, instead of a raw client call, so a briefly-idle-exited daemon doesn't make a live tunnel look down.