Documentation
¶
Overview ¶
Package daemon implements a mechanism to run a long running process in background.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Daemonize ¶
func Daemonize(ctx context.Context, envKey, envValue string, check ReadyFunc) (foreground bool, err error)
Daemonize starts another instance of the current program (aka foreground process) in the background as a daemon. It must be called in both foreground and background processes. It should be invoked early during the program startup, before performing any other significant work, like opening databases, opening network connections, etc.
Background process is started with the same command-line arguments as the foreground process, but with an additional `envKey` environment variable -- which *must* be empty in the foreground processes' environment. Note that background process is started with a limited environment: PATH, USER, HOME and the envKey.
The input `envKey` name must be application-specific, unique and non-empty. Users are free to choose any non-empty value for the environment variable as they see fit (eg: an URL to report ready status).
In addition to the limited environment, standard input and outputs of the background process are replaced with `/dev/null`. Standard library's log output is redirected to the io.Discard backend. Current working directory of the background process is changed to the root directory.
If check parameter is non-nil, parent process will use it to wait for the background process to initialize or die.
When successful, Daemonize returns nil to both foreground and background processes. When unsuccessful or if the input context expires, Daemonize returns a non-nil error to the foreground process and may kill the child process if it has started.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package initstatus implements helper functions to listen-for and send successful or unsuccessful initialization status notification from a child process.
|
Package initstatus implements helper functions to listen-for and send successful or unsuccessful initialization status notification from a child process. |
|
Package monitor implements a self-monitoring auto-restart mechanism.
|
Package monitor implements a self-monitoring auto-restart mechanism. |