Documentation
¶
Overview ¶
Package daemonize wraps a cobra command with Unix daemon lifecycle controls — start, stop, and status — by re-execing the binary as a detached background process. The wrapped command runs in the foreground; the daemon manages backgrounding, a pid file, log streaming during startup and shutdown, and signal-based readiness, all without mutating the command.
The package is split into three pieces:
- daemonize (this package) — thin façade exposing NewDaemon and FromCobra. Stable surface for application code.
- github.com/cnuss/daemonize/v1 — the stable Daemon[T] interface and StatusResult type. Application code that wants to declare types against the interface imports this.
- github.com/cnuss/daemonize/v1alpha1 — the current implementation. Internals (DaemonImpl, helpers, cobra wiring) may change between alpha revisions; pin only if you need direct access to the struct.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package e2e builds each example binary and drives its lifecycle end-to-end, asserting the behavior that example demonstrates.
|
Package e2e builds each example binary and drives its lifecycle end-to-end, asserting the behavior that example demonstrates. |
|
examples
|
|
|
grouped
command
Command grouped sets a custom help group title for the lifecycle subcommands via WithGroup.
|
Command grouped sets a custom help group title for the lifecycle subcommands via WithGroup. |
|
hello
command
Command hello is the smallest daemonize example: wrap a worker, stream its startup via a readiness channel, and get start/stop/status.
|
Command hello is the smallest daemonize example: wrap a worker, stream its startup via a readiness channel, and get start/stop/status. |
|
named
command
Command named overrides the state-file base name with WithName, so the pid and log files are ".../<cache>/.serve/widget.{pid,log}" instead of being derived from the command path.
|
Command named overrides the state-file base name with WithName, so the pid and log files are ".../<cache>/.serve/widget.{pid,log}" instead of being derived from the command path. |
|
pid-cleanup
command
Command pid-cleanup is a degenerate worker: it never closes the readiness channel, sleeps for 5s, prints "hello world", and returns.
|
Command pid-cleanup is a degenerate worker: it never closes the readiness channel, sleeps for 5s, prints "hello world", and returns. |
|
shutdown-error
command
Command shutdown-error demonstrates a wrapped command that starts fine but errors during shutdown.
|
Command shutdown-error demonstrates a wrapped command that starts fine but errors during shutdown. |
|
slow-shutdown
command
Command slow-shutdown demonstrates a wrapped command with a slow, graceful shutdown.
|
Command slow-shutdown demonstrates a wrapped command with a slow, graceful shutdown. |
|
slow-start
command
Command slow-start demonstrates a wrapped command with a slow startup.
|
Command slow-start demonstrates a wrapped command with a slow startup. |
|
start-error
command
Command start-error demonstrates a wrapped command that fails during startup (before signaling readiness).
|
Command start-error demonstrates a wrapped command that fails during startup (before signaling readiness). |
|
stubborn
command
Command stubborn is a misbehaving worker that catches the graceful-shutdown signal and ignores it — only a hard kill stops it (SIGKILL on Unix, TerminateProcess on Windows).
|
Command stubborn is a misbehaving worker that catches the graceful-shutdown signal and ignores it — only a hard kill stops it (SIGKILL on Unix, TerminateProcess on Windows). |
|
subcommand
command
Command subcommand shows daemonize mounted under a larger cobra tree: the app has its own init/create/delete subcommands, and "subcommand run" is the daemonized entry point (so "subcommand run start", "subcommand run stop", "subcommand run serve", ...
|
Command subcommand shows daemonize mounted under a larger cobra tree: the app has its own init/create/delete subcommands, and "subcommand run" is the daemonized entry point (so "subcommand run start", "subcommand run stop", "subcommand run serve", ... |
|
ungrouped
command
Command ungrouped passes WithGroup(nil) so the lifecycle subcommands are not grouped — they appear under cobra's default "Additional Commands:".
|
Command ungrouped passes WithGroup(nil) so the lifecycle subcommands are not grouped — they appear under cobra's default "Additional Commands:". |
|
with-args
command
Command with-args shows that flags and positional args are forwarded verbatim to the wrapped command.
|
Command with-args shows that flags and positional args are forwarded verbatim to the wrapped command. |
Click to show internal directories.
Click to hide internal directories.