Documentation
¶
Overview ¶
Package daemon provides helpers for daemonizing the boid server process. It implements a self-re-exec pattern: the parent spawns a copy of itself with BOID_DAEMON_CHILD=1, waits for the UNIX socket to become ready, and then exits. The child redirects stdin/stdout/stderr to a log file, calls syscall.Setsid to detach from the terminal session, and runs the server.
Index ¶
- func IsChild() bool
- func IsSocketAlive(socketPath string, timeout time.Duration) bool
- func LogFilePath() string
- func RedirectToLog(logPath string) error
- func RedirectToLogRotating(logPath string) error
- func Spawn(args []string) (int, error)
- func WaitForSocket(socketPath string, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSocketAlive ¶
IsSocketAlive reports whether something is actively listening on socketPath. It returns true if a UNIX domain socket can be dialed within timeout, which distinguishes a running server from a stale socket file (ECONNREFUSED) or missing socket file (ENOENT).
func LogFilePath ¶
func LogFilePath() string
LogFilePath returns the path for the daemon log file. Uses $XDG_STATE_HOME/boid/boid.log, falling back to ~/.local/state/boid/boid.log.
func RedirectToLog ¶
RedirectToLog opens logPath (O_APPEND|O_CREATE|O_WRONLY, 0o644), creates the parent directory if necessary, and replaces file descriptors 0, 1, and 2:
- fd 0 (stdin) → /dev/null
- fd 1 (stdout) → logPath
- fd 2 (stderr) → logPath
func RedirectToLogRotating ¶
RedirectToLogRotating is the size-rotating variant of RedirectToLog. It creates an OS pipe, redirects stdin to /dev/null, and redirects stdout and stderr to the pipe write-end. A background goroutine copies from the pipe read-end into a logrotate.Writer so the log is rotated automatically when it grows past MaxSize.
The goroutine exits (and closes the writer) when all write-ends of the pipe are closed, which happens naturally when the process exits.
Types ¶
This section is empty.