feat(cli): worker start -d|--daemon to detach as a background daemon - #11
Merged
Conversation
Add `c0mpute worker start -d|--daemon` which forks into the background, redirects stdout/stderr to ~/.local/share/c0mpute/worker.log, and writes an flock'd PID file at ~/.local/share/c0mpute/worker.pid. The fork happens in a plain sync `main` before the Tokio runtime is built (forking after the multi-threaded runtime spawns worker threads is unsafe), then the runtime is built manually and drives the rest via run_app(). Wire up the previously-stubbed lifecycle commands: - `worker stop` -> SIGTERM the PID from the pid file; clears stale PIDs - `worker status` -> reports running/not-running/stale plus the config Unix-only bits are cfg-gated with clear errors on other platforms. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Add a ready-to-use systemd *user* unit for running the worker as a managed background service. Runs `worker start` in the foreground (Type=simple, no --daemon) so systemd owns the lifecycle, restarts on crash, and captures output to journald. Targets the per-user ~/.c0mpute/bin install layout via %h, with PATH set so the coinpay/infernet peer CLIs resolve. Document both paths in the README: the self-managed `worker start -d` daemon and the systemd unit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ralyodio
added a commit
that referenced
this pull request
Jul 19, 2026
Adds background-worker lifecycle from #11 and #12: - worker start -d|--daemon detach and run as a daemon (PID file + log) - worker start -a|--attach stream the log, Ctrl-D/Ctrl-C to detach - worker stop / worker status now functional (were stubs) Ships the systemd user unit at scripts/systemd/c0mpute-worker.service. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Adds
c0mpute worker start -d|--daemonto run the worker detached as a background daemon, and wires up the previously-stubbedworker stop/worker statuscommands.Why
worker startonly ran in the foreground and blocked forever;worker stopwas a stub ([stub] no running worker to stop) andstatusonly dumped the config. There was no way to run the worker as a daemon short ofnohup/systemd.How
-d/--daemonflag onworker start. When set, the process forks into the background, redirects stdout/stderr to~/.local/share/c0mpute/worker.log, and writes an flock'd PID file at~/.local/share/c0mpute/worker.pid.mainis no longer#[tokio::main]. It parses args and daemonizes while still single-threaded (forking after the multi-threaded Tokio runtime spawns worker threads is unsafe), then builds the runtime manually and drives everything viarun_app().worker stop→ reads the PID file and sendsSIGTERM; clears stale PID files.worker status→ reportsrunning (pid N)/not running/stale pid, then the config.#[cfg(unix)]gated with clear errors on other platforms (addsdaemonize+libcascfg(unix)deps).Testing
Verified end-to-end on Linux:
worker start -dreturns immediately; process reparents to PID 1 (detached), PID + log files written.worker status→running (pid N); supervisor tracing confirmed landing inworker.log.worker stop→ SIGTERM, process terminates.statusand cleared bystop.cargo build(debug) andcargo build --releasepass clean.Note
After a live
stop,statusreportsstale piduntil the nextstart/stop— thedaemonizecrate holds the pidfile flock and doesn't unlink on exit. Left intentionally: the flock is what prevents a double-start race, so unlinking on stop would open a brief two-worker window.🤖 Generated with Claude Code