daemonize

run commands as Unix daemons

TLDR

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

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

INSTALL

sudo apt install daemonize
sudo dnf install daemonize
sudo zypper install daemonize
brew install daemonize
nix profile install nixpkgs#daemonize

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

daemon(1), nohup(1)