LinuxCommandLibrary

daemonize

run commands as Unix daemons

TLDR

Run a command as a daemon

$ daemonize [command] [arguments]
copy
Write PID to specified file
$ daemonize -p [path/to/pidfile] [command] [arguments]
copy
Use a lock file for single instance
$ daemonize -l [path/to/lockfile] [command] [arguments]
copy
Run as a specific user
$ sudo daemonize -u [user] [command] [arguments]
copy

SYNOPSIS

daemonize [options] command [arguments]

DESCRIPTION

daemonize runs a command as a Unix daemon. It handles the standard daemonization process: forking twice, creating a new session, changing to root directory, and closing standard file descriptors.
Useful for programs that don't daemonize themselves but need to run as background services.

PARAMETERS

-p pidfile

Write daemon PID to file
-l lockfile
Use lock file for single instance
-u user
Run as specified user
-c directory
Change to directory before running
-o file
Redirect stdout to file
-e file
Redirect stderr to file

CAVEATS

The command must be specified with an absolute path. For modern systems, systemd services are often preferred. Lock files prevent multiple instances but require cleanup on crashes.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community