daemon - turns other processes into daemons
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, --respawn - Respawn the client -c, --core - Allow core file generation -s, --syslog=facility.priority - Send client's output to syslog -l, --log=facility.priority - Send daemon's output to syslog -C, --config=path - Specify the configuration file
Daemon 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:
Disable core file generation to prevent security holes in daemons run by
root (unless the --core
option is supplied).
If daemon was not invoked by init(8) or inetd(8):
Background the process to lose process group leadership.
Start a new process session.
Under SVR4, background the process again to lose process session leadership. This
prevents the process from ever gaining a controlling terminal. This only
happens when SVR4
is defined and
NO_EXTRA_SVR4_FORK
is not defined when libslack is compiled.
Change to the root directory so as not to hamper umounts.
Clear the umask to enable explicit file creation modes.
Close all open file descriptors. If daemon was invoked by inetd(8),
stdin
, stdout
and stderr
are left open since they are open to a socket.
Open stdin
, stdout
and stderr
to /dev/null
in case something requires them to be open. Of course, this is not done if daemon was invoked by inetd(8).
If the --name
option is supplied, create and lock a file containing the process id of the daemon process. The presence of this locked file prevents two instances of a
daemon with the same name from running at the same time. The default
location of the pidfile is /var/run
on Linux and
/etc
on Solaris for root or /tmp for ordinary users.
Daemon then spawns the client command specified on its command line and waits for
it to terminate. If the --user
option is supplied, daemon
changes the user id and group id of the client process. Only root can use
this option. If the --syslog
option is supplied, the client's standard output and error are captured by daemon and sent to the syslog
destination specified in the --syslog
option.
When the client terminates, daemon respawns it if the --respawn
option is supplied and the client terminated successfully after at least
600 seconds. Otherwise daemon terminates.
If daemon receives a SIGTERM
signal, it propagates the signal to the client and then terminates.
Note: For security reasons, never install daemon with setuid or setgid privileges. It is unnecessary. If you do, daemon will revert to the real user and group for safety before doing anything else.
-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.
-r
, --respawn
Respawn the client when it terminates successfully after at least 600 seconds.
-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.priorityCapture the client's standard output and 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.
/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 is 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 is 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.
You can't specify one syslog destination for the client's standard output and a different one for its standard error.
You can't use spaces in client names in the configuration file.
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 but that shouldn't be problem.
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 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 termination by a SIGHUP
.
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.
libslack(3), daemon(3), init(8), inetd(8)
20010215 raf <raf@raf.org>