summaryrefslogtreecommitdiffstats
path: root/upstream/opensuse-tumbleweed/man7/daemon.7
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 10:52:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 10:52:03 +0000
commit932e4432596447eb9331cc2a2bb74a26a35b4efc (patch)
tree95161711ea07fd64f0c82d6e7943024c033dd5a8 /upstream/opensuse-tumbleweed/man7/daemon.7
parentAdding debian version 4.22.0-1. (diff)
downloadmanpages-l10n-932e4432596447eb9331cc2a2bb74a26a35b4efc.tar.xz
manpages-l10n-932e4432596447eb9331cc2a2bb74a26a35b4efc.zip
Merging upstream version 4.23.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'upstream/opensuse-tumbleweed/man7/daemon.7')
-rw-r--r--upstream/opensuse-tumbleweed/man7/daemon.796
1 files changed, 62 insertions, 34 deletions
diff --git a/upstream/opensuse-tumbleweed/man7/daemon.7 b/upstream/opensuse-tumbleweed/man7/daemon.7
index e55bdbf6..2e0aaf20 100644
--- a/upstream/opensuse-tumbleweed/man7/daemon.7
+++ b/upstream/opensuse-tumbleweed/man7/daemon.7
@@ -1,5 +1,5 @@
'\" t
-.TH "DAEMON" "7" "" "systemd 254" "daemon"
+.TH "DAEMON" "7" "" "systemd 255" "daemon"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -116,7 +116,7 @@ to detach from any terminal and create an independent session\&.
.\}
In the child, call
\fBfork()\fR
-again, to ensure that the daemon can never re\-acquire a terminal again\&. (This relevant if the program \(em and all its dependencies \(em does not carefully specify `O_NOCTTY` on each and every single `open()` call that might potentially open a TTY device node\&.)
+again, to ensure that the daemon can never re\-acquire a terminal again\&. (This is relevant if the program \(em and all its dependencies \(em does not carefully specify `O_NOCTTY` on each and every single `open()` call that might potentially open a TTY device node\&.)
.RE
.sp
.RS 4
@@ -232,7 +232,7 @@ A daemon that needs to provide compatibility with SysV systems should implement
.PP
Modern services for Linux should be implemented as new\-style daemons\&. This makes it easier to supervise and control them at runtime and simplifies their implementation\&.
.PP
-For developing a new\-style daemon, none of the initialization steps recommended for SysV daemons need to be implemented\&. New\-style init systems such as systemd make all of them redundant\&. Moreover, since some of these steps interfere with process monitoring, file descriptor passing and other functionality of the init system, it is recommended not to execute them when run as new\-style service\&.
+For developing a new\-style daemon, none of the initialization steps recommended for SysV daemons need to be implemented\&. New\-style init systems such as systemd make all of them redundant\&. Moreover, since some of these steps interfere with process monitoring, file descriptor passing, and other functionality of the service manager, it is recommended not to execute them when run as new\-style service\&.
.PP
Note that new\-style init systems guarantee execution of daemon processes in a clean process context: it is guaranteed that the environment block is sanitized, that the signal handlers and mask is reset and that no left\-over file descriptors are passed\&. Daemons will be executed in their own session, with standard input connected to
/dev/null
@@ -250,9 +250,12 @@ It is recommended for new\-style daemons to implement the following:
.sp -1
.IP " 1." 4.2
.\}
-If
-\fBSIGTERM\fR
-is received, shut down the daemon and exit cleanly\&.
+If applicable, the daemon should notify the service manager about startup completion or status updates via the
+\fBsd_notify\fR(3)
+interface, in particular
+\fIREADY=1\fR
+and
+\fISTATUS=\&...\fR\&.
.RE
.sp
.RS 4
@@ -264,8 +267,11 @@ is received, shut down the daemon and exit cleanly\&.
.IP " 2." 4.2
.\}
If
-\fBSIGHUP\fR
-is received, reload the configuration files, if this applies\&.
+\fBSIGTERM\fR
+is received, shut down the daemon and exit cleanly\&. A
+\fISTOPPING=1\fR
+notification should be sent via
+\fBsd_notify\fR(3)\&.
.RE
.sp
.RS 4
@@ -276,8 +282,13 @@ is received, reload the configuration files, if this applies\&.
.sp -1
.IP " 3." 4.2
.\}
-Provide a correct exit code from the main daemon process, as this is used by the init system to detect service errors and problems\&. It is recommended to follow the exit code scheme as defined in the
-\m[blue]\fBLSB recommendations for SysV init scripts\fR\m[]\&\s-2\u[1]\d\s+2\&.
+If
+\fBSIGHUP\fR
+is received, reload the configuration files, if this applies\&. This should be combined with notifications via
+\fBsd_notify\fR(3):
+\fIRELOADING=1\fR
+and
+\fIREADY=1\fR\&.
.RE
.sp
.RS 4
@@ -288,7 +299,8 @@ Provide a correct exit code from the main daemon process, as this is used by the
.sp -1
.IP " 4." 4.2
.\}
-If possible and applicable, expose the daemon\*(Aqs control interface via the D\-Bus IPC system and grab a bus name as last step of initialization\&.
+Provide a correct exit code from the main daemon process, as this is used by the service manager to detect service errors and problems\&. It is recommended to follow the exit code scheme as defined in the
+\m[blue]\fBLSB recommendations for SysV init scripts\fR\m[]\&\s-2\u[1]\d\s+2\&.
.RE
.sp
.RS 4
@@ -299,11 +311,7 @@ If possible and applicable, expose the daemon\*(Aqs control interface via the D\
.sp -1
.IP " 5." 4.2
.\}
-For integration in systemd, provide a
-\&.service
-unit file that carries information about starting, stopping and otherwise maintaining the daemon\&. See
-\fBsystemd.service\fR(5)
-for details\&.
+If possible and applicable, expose the daemon\*(Aqs control interface via the D\-Bus IPC system and grab a bus name as last step of initialization\&.
.RE
.sp
.RS 4
@@ -314,9 +322,11 @@ for details\&.
.sp -1
.IP " 6." 4.2
.\}
-As much as possible, rely on the init system\*(Aqs functionality to limit the access of the daemon to files, services and other resources, i\&.e\&. in the case of systemd, rely on systemd\*(Aqs resource limit control instead of implementing your own, rely on systemd\*(Aqs privilege dropping code instead of implementing it in the daemon, and similar\&. See
-\fBsystemd.exec\fR(5)
-for the available controls\&.
+For integration in systemd, provide a
+\&.service
+unit file that carries information about starting, stopping and otherwise maintaining the daemon\&. See
+\fBsystemd.service\fR(5)
+for details\&.
.RE
.sp
.RS 4
@@ -327,7 +337,9 @@ for the available controls\&.
.sp -1
.IP " 7." 4.2
.\}
-If D\-Bus is used, make your daemon bus\-activatable by supplying a D\-Bus service activation configuration file\&. This has multiple advantages: your daemon may be started lazily on\-demand; it may be started in parallel to other daemons requiring it \(em which maximizes parallelization and boot\-up speed; your daemon can be restarted on failure without losing any bus requests, as the bus queues requests for activatable services\&. See below for details\&.
+As much as possible, rely on the service manager\*(Aqs functionality to limit the access of the daemon to files, services, and other resources, i\&.e\&. in the case of systemd, rely on systemd\*(Aqs resource limit control instead of implementing your own, rely on systemd\*(Aqs privilege dropping code instead of implementing it in the daemon, and so on\&. See
+\fBsystemd.exec\fR(5)
+for the available controls\&.
.RE
.sp
.RS 4
@@ -338,7 +350,7 @@ If D\-Bus is used, make your daemon bus\-activatable by supplying a D\-Bus servi
.sp -1
.IP " 8." 4.2
.\}
-If your daemon provides services to other local processes or remote clients via a socket, it should be made socket\-activatable following the scheme pointed out below\&. Like D\-Bus activation, this enables on\-demand starting of services as well as it allows improved parallelization of service start\-up\&. Also, for state\-less protocols (such as syslog, DNS), a daemon implementing socket\-based activation can be restarted without losing a single request\&. See below for details\&.
+If D\-Bus is used, make your daemon bus\-activatable by supplying a D\-Bus service activation configuration file\&. This has multiple advantages: your daemon may be started lazily on\-demand; it may be started in parallel to other daemons requiring it \(em which maximizes parallelization and boot\-up speed; your daemon can be restarted on failure without losing any bus requests, as the bus queues requests for activatable services\&. See below for details\&.
.RE
.sp
.RS 4
@@ -349,9 +361,7 @@ If your daemon provides services to other local processes or remote clients via
.sp -1
.IP " 9." 4.2
.\}
-If applicable, a daemon should notify the init system about startup completion or status updates via the
-\fBsd_notify\fR(3)
-interface\&.
+If your daemon provides services to other local processes or remote clients via a socket, it should be made socket\-activatable following the scheme pointed out below\&. Like D\-Bus activation, this enables on\-demand starting of services as well as it allows improved parallelization of service start\-up\&. Also, for state\-less protocols (such as syslog, DNS), a daemon implementing socket\-based activation can be restarted without losing a single request\&. See below for details\&.
.RE
.sp
.RS 4
@@ -362,10 +372,24 @@ interface\&.
.sp -1
.IP "10." 4.2
.\}
+If the service opens sockets or other files on it own, and those file descriptors shall survive a restart, the daemon should store them in the service manager via
+\fBsd_notify\fR(3)
+with
+\fIFDSTORE=1\fR\&.
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'11.\h'+01'\c
+.\}
+.el \{\
+.sp -1
+.IP "11." 4.2
+.\}
Instead of using the
\fBsyslog()\fR
call to log directly to the system syslog service, a new\-style daemon may choose to simply log to standard error via
-\fBfprintf()\fR, which is then forwarded to syslog by the init system\&. If log levels are necessary, these can be encoded by prefixing individual log lines with strings like
+\fBfprintf()\fR, which is then forwarded to syslog\&. If log levels are necessary, these can be encoded by prefixing individual log lines with strings like
"<4>"
(for log level 4 "WARNING" in the syslog priority scheme), following a similar style as the Linux kernel\*(Aqs
\fBprintk()\fR
@@ -377,13 +401,17 @@ and
.sp
.RS 4
.ie n \{\
-\h'-04'11.\h'+01'\c
+\h'-04'12.\h'+01'\c
.\}
.el \{\
.sp -1
-.IP "11." 4.2
+.IP "12." 4.2
.\}
-As new\-style daemons are invoked without a controlling TTY (but as their own session leaders) care should be taken to always specify `O_NOCTTY` on `open()` calls that possibly reference a TTY device node, so that no controlling TTY is accidentally acquired\&.
+As new\-style daemons are invoked without a controlling TTY (but as their own session leaders) care should be taken to always specify
+\fBO_NOCTTY\fR
+on
+\fBopen\fR(2)
+calls that possibly reference a TTY device node, so that no controlling TTY is accidentally acquired\&.
.RE
.PP
These recommendations are similar but not identical to the
@@ -396,7 +424,7 @@ might get activated either when Bluetooth hardware is plugged in, or when an app
.SS "Activation on Boot"
.PP
Old\-style daemons are usually activated exclusively on boot (and manually by the administrator) via SysV init scripts, as detailed in the
-\m[blue]\fBLSB Linux Standard Base Core Specification\fR\m[]\&\s-2\u[1]\d\s+2\&. This method of activation is supported ubiquitously on Linux init systems, both old\-style and new\-style systems\&. Among other issues, SysV init scripts have the disadvantage of involving shell scripts in the boot process\&. New\-style init systems generally employ updated versions of activation, both during boot\-up and during runtime and using more minimal service description files\&.
+\m[blue]\fBLSB Linux Standard Base Core Specification\fR\m[]\&\s-2\u[1]\d\s+2\&. This method of activation is supported ubiquitously on Linux init systems, both old\-style and new\-style systems\&. Among other issues, SysV init scripts have the disadvantage of involving shell scripts in the boot process\&. New\-style init systems generally use updated versions of activation, both during boot\-up and during runtime and using more minimal service description files\&.
.PP
In systemd, if the developer or administrator wants to make sure that a service or other unit is activated automatically on boot, it is recommended to place a symlink to the unit file in the
\&.wants/
@@ -412,9 +440,9 @@ directories, and
for details about the two boot targets\&.
.SS "Socket\-Based Activation"
.PP
-In order to maximize the possible parallelization and robustness and simplify configuration and development, it is recommended for all new\-style daemons that communicate via listening sockets to employ socket\-based activation\&. In a socket\-based activation scheme, the creation and binding of the listening socket as primary communication channel of daemons to local (and sometimes remote) clients is moved out of the daemon code and into the init system\&. Based on per\-daemon configuration, the init system installs the sockets and then hands them off to the spawned process as soon as the respective daemon is to be started\&. Optionally, activation of the service can be delayed until the first inbound traffic arrives at the socket to implement on\-demand activation of daemons\&. However, the primary advantage of this scheme is that all providers and all consumers of the sockets can be started in parallel as soon as all sockets are established\&. In addition to that, daemons can be restarted with losing only a minimal number of client transactions, or even any client request at all (the latter is particularly true for state\-less protocols, such as DNS or syslog), because the socket stays bound and accessible during the restart, and all requests are queued while the daemon cannot process them\&.
+In order to maximize the possible parallelization and robustness and simplify configuration and development, it is recommended for all new\-style daemons that communicate via listening sockets to use socket\-based activation\&. In a socket\-based activation scheme, the creation and binding of the listening socket as primary communication channel of daemons to local (and sometimes remote) clients is moved out of the daemon code and into the service manager\&. Based on per\-daemon configuration, the service manager installs the sockets and then hands them off to the spawned process as soon as the respective daemon is to be started\&. Optionally, activation of the service can be delayed until the first inbound traffic arrives at the socket to implement on\-demand activation of daemons\&. However, the primary advantage of this scheme is that all providers and all consumers of the sockets can be started in parallel as soon as all sockets are established\&. In addition to that, daemons can be restarted with losing only a minimal number of client transactions, or even any client request at all (the latter is particularly true for state\-less protocols, such as DNS or syslog), because the socket stays bound and accessible during the restart, and all requests are queued while the daemon cannot process them\&.
.PP
-New\-style daemons which support socket activation must be able to receive their sockets from the init system instead of creating and binding them themselves\&. For details about the programming interfaces for this scheme provided by systemd, see
+New\-style daemons which support socket activation must be able to receive their sockets from the service manager instead of creating and binding them themselves\&. For details about the programming interfaces for this scheme provided by systemd, see
\fBsd_listen_fds\fR(3)
and
\fBsd-daemon\fR(3)\&. For details about porting existing daemons to socket\-based activation, see below\&. With minimal effort, it is possible to implement socket\-based activation in addition to traditional internal socket creation in the same codebase in order to support both new\-style and old\-style init systems from the same daemon binary\&.
@@ -435,7 +463,7 @@ or suchlike) when one is installed in
sockets\&.target\&.
.SS "Bus\-Based Activation"
.PP
-When the D\-Bus IPC system is used for communication with clients, new\-style daemons should employ bus activation so that they are automatically activated when a client application accesses their IPC interfaces\&. This is configured in D\-Bus service files (not to be confused with systemd service unit files!)\&. To ensure that D\-Bus uses systemd to start\-up and maintain the daemon, use the
+When the D\-Bus IPC system is used for communication with clients, new\-style daemons should use bus activation so that they are automatically activated when a client application accesses their IPC interfaces\&. This is configured in D\-Bus service files (not to be confused with systemd service unit files!)\&. To ensure that D\-Bus uses systemd to start\-up and maintain the daemon, use the
\fISystemdService=\fR
directive in these service files to configure the matching systemd service for a D\-Bus service\&. e\&.g\&.: For a D\-Bus service whose D\-Bus activation file is named
org\&.freedesktop\&.RealtimeKit\&.service, make sure to set
@@ -484,7 +512,7 @@ socket option, as accessible via
\fIFreeBind=yes\fR
in systemd socket files (see
\fBsystemd.socket\fR(5)
-for details)\&. This option, when enabled, allows sockets to be bound to a non\-local, not configured IP address, and hence allows bindings to a particular IP address before it actually becomes available, making such an explicit dependency to the configured address redundant\&. Another often suggested trigger for service activation is low system load\&. However, here too, a more convincing approach might be to make proper use of features of the operating system, in particular, the CPU or I/O scheduler of Linux\&. Instead of scheduling jobs from userspace based on monitoring the OS scheduler, it is advisable to leave the scheduling of processes to the OS scheduler itself\&. systemd provides fine\-grained access to the CPU and I/O schedulers\&. If a process executed by the init system shall not negatively impact the amount of CPU or I/O bandwidth available to other processes, it should be configured with
+for details)\&. This option, when enabled, allows sockets to be bound to a non\-local, not configured IP address, and hence allows bindings to a particular IP address before it actually becomes available, making such an explicit dependency to the configured address redundant\&. Another often suggested trigger for service activation is low system load\&. However, here too, a more convincing approach might be to make proper use of features of the operating system, in particular, the CPU or I/O scheduler of Linux\&. Instead of scheduling jobs from userspace based on monitoring the OS scheduler, it is advisable to leave the scheduling of processes to the OS scheduler itself\&. systemd provides fine\-grained access to the CPU and I/O schedulers\&. If a process executed by the service manager shall not negatively impact the amount of CPU or I/O bandwidth available to other processes, it should be configured with
\fICPUSchedulingPolicy=idle\fR
and/or
\fIIOSchedulingClass=idle\fR\&. Optionally, this may be combined with timer\-based activation to schedule background jobs during runtime and with minimal impact on the system, and remove it from the boot phase itself\&.
@@ -773,7 +801,7 @@ is checked for already passed sockets first\&. If sockets are passed (i\&.e\&. w
\fBsd_listen_fds()\fR
returns a positive value), skip the socket creation step and use the passed sockets\&. Secondly, ensure that the file system socket nodes for local
\fBAF_UNIX\fR
-sockets used in the socket\-based activation are not removed when the daemon shuts down, if sockets have been passed\&. Third, if the daemon normally closes all remaining open file descriptors as part of its initialization, the sockets passed from the init system must be spared\&. Since new\-style init systems guarantee that no left\-over file descriptors are passed to executed processes, it might be a good choice to simply skip the closing of all remaining open file descriptors if sockets are passed\&.
+sockets used in the socket\-based activation are not removed when the daemon shuts down, if sockets have been passed\&. Third, if the daemon normally closes all remaining open file descriptors as part of its initialization, the sockets passed from the service manager must be spared\&. Since new\-style init systems guarantee that no left\-over file descriptors are passed to executed processes, it might be a good choice to simply skip the closing of all remaining open file descriptors if sockets are passed\&.
.RE
.sp
.RS 4