daemonize(1) | User Manuals | daemonize(1) |
daemonize - run a program as a Unix daemon
daemonize [-a] [-c directory] [-e stderr] [-o stdout] [-p pidfile] [-l lockfile] [-u user] [-v] path [arg] ...
daemonize runs a command as a Unix daemon. As defined in W. Richard Stevens' 1990 book, Unix Network Programming (Addison-Wesley, 1990), a daemon is “a process that executes `in the background' (i.e., without an associated terminal or login shell) either waiting for some event to occur, or waiting to perform some specified task on a periodic basis.” Upon startup, a typical daemon program will:
Most programs that are designed to be run as daemons do that work for themselves. However, you'll occasionally run across one that does not. When you must run a daemon program that does not properly make itself into a true Unix daemon, you can use daemonize to force it to run as a true daemon.
Warning: Be careful where you redirect the output! The file system containing the open file cannot be unmounted as long as the file is open. For best results, make sure that this output file is on the same file system as the daemon's working directory. (See the -c option.)
Warning: Be careful where you redirect the output! The file system containing the open file cannot be unmounted as long as the file is open. For best results, make sure that this output file is on the same file system as the daemon's working directory. (See the -c option.)
It is possible to use the pidfile as the lock file (e.g., "-p /var/run/foo -l /var/run/foo"), though typical daemons use separate files.
NOTE: If the executed program decides to close all file descriptors, the single-instance locking will not work, since the lock depends on an open file descriptor. (The operating system kernel removes the lock once the process holding the lock closes the file or exits.) Normal processes that do not daemonize themselves do not usually close all file descriptors.
If the host operating system provides the daemon(3) library routine, daemonize will use it. Otherwise, daemonize uses its own version of daemon(3). This choice is made at compile time. (BSD 4.4-derived operating systems tend to provide their own daemon(3) routine.)
FreeBSD 5.0 introduced a daemon(1) command that is similar to, but less functional, than daemonize.
This program released under a BSD-style license. For more details, consult the LICENSE file accompanying the source distribution, or visit "http://software.clapper.org/daemonize/LICENSE".
daemon(3), setsid(2), flock(2)
daemonize Home Page: http://software.clapper.org/daemonize/
Brian M. Clapper, bmc <at> clapper <dot> org
Support for the -e and -o options is based on a patch submitted by Tim Starling (tstarling <at> wikimedia <dot> org).
Support for the -l option is based on a patch submitted by Yakov Lerner (iler.ml <at> gmail <dot> com).
August 2006 | Unix |