daemon

package
v1.261203.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MPL-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Daemonize

func Daemonize(overrideArgs ...string) error

Daemonize detaches the process from the terminal and runs it in the background by re-executing the current command as a detached child (session leader on Unix, detached process on Windows) and exiting the parent.

Callers that want to know whether the child actually came up should use Spawn instead and keep the parent alive until it has.

overrideArgs pins flags the parent resolved (e.g. "--port", "9000") so the detached child binds exactly what the parent decided instead of re-resolving its own command line. See buildDaemonArgs.

func IsDaemonProcess

func IsDaemonProcess() bool

IsDaemonProcess checks if the current process is running as a daemon

func NewLogger

func NewLogger(cfg *LogRotationConfig) *lumberjack.Logger

NewLogger creates a new lumberjack logger with the given configuration

func Spawn added in v1.261116.0

func Spawn(overrideArgs ...string) (<-chan error, error)

Spawn re-executes the current command as a detached daemon child and returns without exiting the parent. The returned channel yields the child's exit status (nil for a clean exit) once it ends, so the parent can tell a child that came up from one that died on startup. The child outlives the parent: it is its own session leader and its stdio is detached.

Types

type Child added in v1.261203.0

type Child struct {
	// PID is the child's process id, for messages and logs. It is not used to
	// decide readiness — the health handshake is.
	PID int
	// Exited yields the child's exit status once it ends.
	Exited <-chan error
}

Child is a detached daemon child returned by SpawnProcess.

func SpawnProcess added in v1.261203.0

func SpawnProcess(extraEnv []string, overrideArgs ...string) (*Child, error)

SpawnProcess is Spawn with extra environment entries for the child and the child's PID. extraEnv is appended to the parent's environment, so it can carry per-launch values such as a readiness instance token.

type LogRotationConfig

type LogRotationConfig struct {
	Filename   string // Log file path
	MaxSize    int    // Maximum size in megabytes
	MaxBackups int    // Maximum number of old log files to retain
	MaxAge     int    // Maximum number of days to retain old log files
	Compress   bool   // Compress old log files
}

LogRotationConfig holds configuration for log rotation

func DefaultLogRotationConfig

func DefaultLogRotationConfig(logFile string) *LogRotationConfig

DefaultLogRotationConfig returns default log rotation settings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL