@@ -31,111 +31,125 @@ Change the process `uid` and `gid` if the `--user` option was supplied. Only
3131* root* can use this option. Note that the ` uid ` of * daemon* itself is changed,
3232rather than just changing the ` uid ` of the client process.
3333
34- Read the configuration file (` /etc/daemon.conf ` by default, or specified
35- by the ` --config ` option). Note: The root directory and the user must be
36- set before access to the configuration file can be attempted so neither
37- ` --chroot ` nor ` --user ` options may appear in the configuration file.
34+ Read the system configuration file(s) (` /etc/daemon.conf ` and
35+ ` /etc/daemon.conf.d/* ` by default, or specified by the ` --config ` option)
36+ unless the C<--noconfig> option was supplied. Then read the user's personal
37+ configuration file(s) (` ~/.daemonrc ` and ` ~/.daemonrc.d/* ` ), if any. Note:
38+ The root directory and the user must be set before access to the
39+ configuration file(s) can be attempted so neither ` --chroot ` nor ` --user `
40+ options may appear in the configuration file.
3841
39- Disable core file generation to prevent leaking information in daemons run
40- by * root* (unless the ` --core ` option is supplied).
42+ On * BSD* systems (except * macOS* ), the system configuration file(s) are
43+ ` /usr/local/etc/daemon.conf ` and ` /usr/local/etc/daemon.conf.d/* ` by
44+ default.
45+
46+ On * macOS* , when installed via * macports* , the system configuration file(s)
47+ are ` /opt/local/etc/daemon.conf ` and ` /opt/local/etc/daemon.conf.d/* ` .
48+
49+ Disable core file generation to prevent leaking potentially sensitive
50+ information in daemons that are run by * root* (unless the ` --core ` option
51+ was supplied).
4152
4253Become a daemon process:
4354
4455 * If * daemon* was not invoked by * init(8)* (i.e. pid 1) or * inetd(8)* :
4556
4657 * Ignore ` SIGHUP ` signals in case the current process session leader
47- terminates while attached to a controlling terminal causing us to
58+ terminates while attached to a controlling terminal, causing us to
4859 receive a ` SIGHUP ` signal before we start our own process session below.
4960 This can happen when * daemon* was invoked interactively via the shell
5061 builtin ` exec ` . When this initial process terminates below, the terminal
51- emulator that invoked the shell also terminates.
62+ emulator that invoked the shell also terminates, do * daemon* needs to
63+ protect itself from that.
5264
5365 * Background the process to lose process group leadership.
5466
5567 * Start a new process session.
5668
57- * Background the process again to lose process session leadership. Under
58- SVR4 this prevents the process from ever gaining a controlling terminal.
59- This is only necessary under SVR4 but is always done for simplicity. Note
60- that ignoring ` SIGHUP ` signals earlier means that when the newly created
61- process session leader terminates, then even if it has a controlling
62- terminal open, the newly backgrounded process won't receive the
63- corresponding ` SIGHUP ` signal that is sent to all processes in the process
64- session's foreground process group because it inherited signal dispositions
65- from the initial process.
69+ * Background the process again to lose process session leadership. Under
70+ * SVR4* this prevents the process from ever gaining a controlling
71+ terminal. This is only necessary under * SVR4*, but is always done for
72+ simplicity. Note that ignoring `SIGHUP` signals earlier means that
73+ when the newly created process session leader terminates, then even if
74+ it has a controlling terminal open, the newly backgrounded process
75+ won't receive the corresponding `SIGHUP` signal that is sent to all
76+ processes in the process session's foreground process group, because
77+ it inherited signal dispositions from the initial process.
6678
67- * Change directory to the root directory so as not to hamper umounts.
79+ * Change the current directory to the root directory so as not to hamper
80+ umounts.
6881
69- * Clear the umask to enable explicit file creation modes.
82+ * Clear the * umask* to enable explicit file creation modes.
7083
7184 * Close all open file descriptors. If * daemon* was invoked by * inetd(8)* ,
72- ` stdin ` , ` stdout ` and ` stderr ` are left open since they are open to a
73- socket.
85+ `stdin`, `stdout` and `stderr` are left open, because they are open to a
86+ socket.
7487
75- * Open ` stdin ` , ` stdout ` and ` stderr ` to ` /dev/null ` in case something
88+ * Open ` stdin ` , ` stdout ` and ` stderr ` to ` /dev/null ` , in case something
7689 requires them to be open. Of course, this is not done if * daemon* was
7790 invoked by * inetd(8)* .
7891
7992 * If the ` --name ` option was supplied, create and lock a file containing the
80- process id of the * daemon* process. The presence of this locked file
81- prevents two instances of a daemon with the same name from running at the
82- same time. The standard location of the pidfile is ` /var/run ` for * root*
83- (` /etc ` on * Solaris* ) and ` /tmp ` for normal users. If the ` --pidfiles `
84- option was supplied, its argument specifies the directory in which the
85- pidfile will be placed. If the ` --pidfile ` option was supplied, its
86- argument specifies the name of the pidfile and the directory in which it
87- will be placed.
88-
89- If the ` --umask ` option was supplied, set the umask to its argument.
90- Otherwise, set the umask to ` 022 ` to prevent accidentally creating group or
91- world writable files.
93+ process id of the *daemon* process. The presence of this locked file
94+ prevents two instances of a daemon with the same name from running at
95+ the same time. The default location of the pidfile is `/var/run` for
96+ *root* (`/etc` on *Solaris*, `/opt/local/var/run` on *macOS* when
97+ installed via *macports*), and `/tmp` for normal users. If the
98+ `--pidfiles` option was supplied, its argument specifies the directory
99+ in which the pidfile will be placed. If the `--pidfile` option was
100+ supplied, its argument specifies the name of the pidfile and the
101+ directory in which it will be placed.
102+
103+ If the ` --umask ` option was supplied, set the * umask* to its argument, which
104+ must be a valid three-digit octal mode. Otherwise, set the * umask* to ` 022 ` ,
105+ to prevent accidentally creating group- or world-writable files.
92106
93107Set the current directory if the ` --chdir ` option was supplied.
94108
95109Spawn the client command and wait for it to terminate. The client command
96- may be specified as command line arguments or as the argument of the
110+ can be specified as command line arguments, or as the argument of the
97111` --command ` option. If both the ` --command ` option and command line
98112arguments are present, the client command is the result of appending the
99113command line arguments to the argument of the ` --command ` option.
100114
101115If the ` --output ` , ` --stdout ` and/or ` --stderr ` option were supplied, the client's
102- standard output and/or standard error are captured by * daemon* and sent to the
116+ standard output and/or standard error are captured by * daemon* , and sent to the
103117respective * syslog* destinations.
104118
105119When the client terminates, * daemon* respawns it if the ` --respawn ` option
106- was supplied. If the client ran for less than 300 seconds (or the value of
107- the ` --acceptable ` option), then * daemon* sees this as an error . It will
120+ was supplied. If the client ran for less than ` 300 ` seconds (or the value of
121+ the ` --acceptable ` option), then * daemon* sees this as a failure . It will
108122attempt to restart the client up to five times (or the value of the
109- ` --attempts ` option) before waiting for 300 seconds (or the value of the
110- ` --delay ` option). This gives the administrator the chance to correct
111- whatever is preventing the client from running without overloading system
112- resources. If the ` --limit ` option was supplied, * daemon* terminates after
113- the specified number of spawn attempt bursts. The default is zero which
114- means never give up, never surrender.
123+ ` --attempts ` option), before waiting for ` 300 ` seconds (or the value of the
124+ ` --delay ` option). This gives the system administrator the chance to correct
125+ whatever is preventing the client from running successfully without
126+ overloading system resources. If the ` --limit ` option was supplied, * daemon*
127+ terminates after the specified number of respawn attempt bursts. The default
128+ is zero, which means never give up, never surrender.
115129
116- When the client terminates and the ` --respawn ` option wasn't supplied,
117- * daemon* terminates.
130+ When the client terminates, and the ` --respawn ` option wasn't supplied,
131+ * daemon* terminates as well .
118132
119- If * daemon* receives a ` SIGTERM ` signal (e.g. from another invocation of
120- * daemon* supplied with the ` --stop ` option), it propagates the signal to the
121- client and then terminates.
133+ If * daemon* receives a ` SIGTERM ` signal (e.g. from a separate invocation of
134+ * daemon* with the ` --stop ` option), it propagates the signal to the client
135+ and then terminates.
122136
123- If * daemon* receives a ` SIGUSR1 ` signal (from another invocation of
124- * daemon* supplied with the ` --restart ` option), it sends a ` SIGTERM `
125- signal to the client. If started with the ` --respawn ` option, the client
126- process will be restarted after it is killed by the ` SIGTERM ` signal.
137+ If * daemon* receives a ` SIGUSR1 ` signal (from a separate invocation of
138+ * daemon* with the ` --restart ` option), it sends a ` SIGTERM ` signal to the
139+ client. If it was started with the ` --respawn ` option, the client process
140+ will be restarted after it is terminated by the ` SIGTERM ` signal.
127141
128142If the ` --foreground ` option was supplied, the client process is run as a
129- foreground process and is not turned into a daemon. If * daemon* is
130- connected to a terminal, so will the client process. If * daemon * is not
131- connected to a terminal but the client needs to be connected to a terminal,
132- use the ` --pty ` option.
143+ foreground process, and is not turned into a daemon at all . If * daemon* is
144+ connected to a terminal, then the client process will also be connected to
145+ it. If * daemon * is not connected to a terminal, but the client needs to be
146+ connected to a terminal, use the ` --pty ` option.
133147
134148--------------------------------------------------------------------------------
135149
136150 URL: http://libslack.org/daemon
137151 URL: http://raf.org/daemon
138152 GIT: https://github.com/raforg/daemon
139- Date: 20201111
153+ Date: 20210220
140154 Author: raf <raf@raf.org>
141155
0 commit comments