Documentation
¶
Overview ¶
Package process provides PID-file management, daemonize re-exec, and signal-handler installation primitives shared by the af governor start/stop/status subcommands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyRunning is returned when a process is already running. ErrAlreadyRunning = errors.New("process: already running") // ErrStalePID is returned when the PID file exists but the process is dead. ErrStalePID = errors.New("process: stale PID (process not running)") // ErrNotRunning is returned when no PID file is found. ErrNotRunning = errors.New("process: not running") // ErrUnsupported is returned on platforms where a feature is not supported. ErrUnsupported = errors.New("process: unsupported on this platform") )
Sentinel errors returned by this package.
Functions ¶
func Daemonize ¶
Daemonize re-execs the current process as a background daemon.
If the environment variable DONMAI_DAEMON=1 (legacy: AF_DAEMON=1) is set, Daemonize returns (true, 0, nil) — the current process is already the daemon child and the caller should continue its work.
Otherwise Daemonize re-execs os.Args[0] with os.Args[1:], appending DONMAI_DAEMON=1 to the environment, with Setsid set and stdin/stdout/stderr redirected to /dev/null. It returns (false, childPID, nil) — the caller should print a "started PID <childPID>" message and then call os.Exit(0).
func InstallSignalHandlers ¶
func InstallSignalHandlers(ctx context.Context, cancel context.CancelFunc)
InstallSignalHandlers starts a goroutine that listens for SIGINT and SIGTERM. On receipt of either signal, cancel is called. The goroutine stops cleanly when ctx is done and signal.Stop is called for cleanup.
InstallSignalHandlers does not block — it returns immediately after starting the background goroutine.
Types ¶
type PIDFile ¶
type PIDFile struct {
// contains filtered or unexported fields
}
PIDFile manages a PID file for tracking a running process.
func NewPIDFile ¶
NewPIDFile returns a PIDFile for the given process name. It prefers $XDG_RUNTIME_DIR/agentfactory/<name>.pid and falls back to os.TempDir()/agentfactory/<name>.pid.
func (*PIDFile) Read ¶
Read reads and validates the PID from the file. Returns ErrNotRunning if the file does not exist. Returns ErrStalePID if the recorded process is no longer alive.