NAME

daemon - turns other processes into daemons


SYNOPSIS

 usage: daemon [options] cmd arg...
 options:

   -h, --help                     - Print a help message then exit
   -V, --version                  - Print a version message then exit
   -v, --verbose[=level]          - Set the verbosity level
   -d, --debug[=level]            - Set the debug level

   -n, --name=name                - Name the client exclusively
   -u, --user=user[.group]        - Run the client as user[.group]
   -R, --chroot=path              - Run the client with path as root
   -D, --chdir=path               - Run the client in directory path
   -m, --umask=umask              - Run the client with the given umask
   -r, --respawn                  - Respawn the client when it terminates
   -f, --force                    - Respawn the client even when it crashes
   -c, --core                     - Allow core file generation
   -s, --syslog=facility.priority - Send client's stdout/stderr to syslog
   -o, --outlog=facility.priority - Send client's stdout to syslog
   -e, --errlog=facility.priority - Send client's stderr to syslog
   -l, --log=facility.priority    - Send daemon's output to syslog
   -C, --config=path              - Specify the configuration file


DESCRIPTION

daemon(1) turns other processes into daemons. There are many tasks that need to be performed to correctly set up a daemon process. This can be tedious. daemon performs these tasks for other processes.

The preparatory tasks that daemon performs for other processes are:


OPTIONS

-h, --help

Display a help message and exit.

-V, --version

Display a version message and exit.

-v[level], --verbose[=level]

Set the message verbosity level to level (or 1 if level is not supplied). daemon does not have any verbose messages so this has no effect.

-d[level], --debug[=level]

Set the debug message level to level (or 1 if level is not supplied). Set to level 1 for a trace of all functions called. Set to level 2 for more detail. Debug messages are sent to the syslog(3) facility, daemon.debug.

-n=name, --name=name

Create and lock a pid file (/var/run/name.pid), ensuring that only one daemon with the given name is active at the same time.

-u=user[.group], --user=user[.group]

Run the client as a different user (and group). This only works for root. If the argument includes a .group specifier, daemon will assume the specified group and no other. Otherwise, daemon will assume all groups that the specified user is in.

-R=path, --chroot=path

Change the root directory to path before running the client. On some systems, only root can do this. Note that the path to the client program and to the configuration file (if any) must be relative to the new root path.

-D=path, --chdir=path

Change the directory to path before running the client.

-m=umask, --umask=umask

Change the umask to umask before running the client. umask must be a valid octal mode. The default umask is 022.

-r, --respawn

Respawn the client when it terminates successfully after at least 600 seconds.

-f, --force

Respawn the client even if it crashed or was killed by a signal after at least 600 seconds. Note that this option has no effect unless the --respawn option is also supplied.

-c, --core

Allow the client to create a core file. This should only be used for debugging as it could lead to security holes in daemons run by root.

-s=facility.priority --syslog=facility.priority

Capture the client's standard output and error and send it to the syslog destination specified by facility.priority.

-o=facility.priority --outlog=facility.priority

Capture the client's standard output and send it to the syslog destination specified by facility.priority.

-e=facility.priority --errlog=facility.priority

Capture the client's standard error and send it to the syslog destination specified by facility.priority.

-l=facility.priority --log=facility.priority

Send daemon's standard output and error to the syslog destination specified by facility.priority. By default, they are sent to daemon.err.

-C=path, --config=path

Specify the configuration file to use. By default, /etc/daemon.conf is the configuration file if it exists and is not group or world writable and does not exist in a group or world writable directory. The configuration file lets you predefine options that apply to all clients and to specifically named clients.


FILES

/etc/daemon.conf - define default options

Each line of the configuration file consists of a client name or '*', followed by whitespace, followed by a comma separated list of options. Blank lines and comments ('#' to end of the line) are ignored. Lines may be continued with a '\' character at the end of the line.

For example:

    *       log=daemon.err,syslog=local0.err,respawn
    test1   syslog=local0.debug,debug=9,verbose=9,core
    test2   syslog=local0.debug,debug=9,verbose=9,core

The command line options are processed first to look for a --config option. If no --config option was supplied, the default file, /etc/daemon.conf, is used. If the configuration file contains any generic ('*') entries, their options are applied in order of appearance. If the --name option was supplied and the configuration file contains any entries with the given name, their options are then applied in order of appearance. Finally, the command line options are applied again. This ensures that any generic options apply to all clients by default. Client specific options override generic options. Command line options override both.

Note that the configuration file is not opened and read until after any --chroot and/or --user command line options are processed. This means that the configuration file path and the client's file path must be relative to the --chroot argument. It also means that the configuration file and the client executable must be readable/executable by the user specified by the --user argument. It also means that neither the --chroot nor the --user options will have any effect if the appear in the configuration file. The command line options are parsed mainly to find --chroot, --user and --config. The --chroot and --user then take effect if they are present. Then the configuration file is parsed looking for extra options. Generic options are processed. Then named options are processed. Finally, the command line options are processed again to make sure that they override any generic or named options.


BUGS

If you specify (in the configuration file) that all clients allow core file generation, there is no way to countermand that for any client (without using an alternative configuration file). So don't do that. The same applies to respawning.

It is possible for the client process to obtain a controlling terminal under BSD (and even under SVR4 if SVR4 was not defined or NO_EXTRA_SVR4_FORK was defined when libslack(3) is compiled). If anything calls open(2) on a terminal device without the O_NOCTTY flag, the process doing so will obtain a controlling terminal and then be susceptible to unintended termination by a SIGHUP.


MAILING LISTS

The following mailing lists exist for daemon related discussion:

 daemon-announce@libslack.org - Announcements
 daemon-users@libslack.org    - User forum
 daemon-dev@libslack.org      - Development forum

To subscribe to any of these mailing lists, send a mail message to listname-request@libslack.org with subscribe as the message body. e.g.

 $ echo subscribe | mail daemon-announce-request@libslack.org
 $ echo subscribe | mail daemon-users-request@libslack.org
 $ echo subscribe | mail daemon-dev-request@libslack.org

Or you can send a mail message to majordomo@libslack.org with subscribe listname in the message body. This way, you can subscribe to multiple lists at the same time. e.g.

 $ mail majordomo@libslack.org
 subscribe daemon-announce
 subscribe daemon-users
 subscribe daemon-dev
 .

A digest version of each mailing list is also available. Subscribe to digests as above but append -digest to the listname.


SEE ALSO

libslack(3), daemon(3), init(8), inetd(8), fork(2), umask(2), setsid(2), chdir(2), chroot(2), setrlimit(2), setgid(2), setuid(2), setgroups(2), initgroups(3), syslog(3), kill(2)


AUTHOR

20011109 raf <raf@raf.org>