1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"systemd-journald.service">
12 <title>systemd-journald.service
</title>
13 <productname>systemd
</productname>
17 <refentrytitle>systemd-journald.service
</refentrytitle>
18 <manvolnum>8</manvolnum>
22 <refname>systemd-journald.service
</refname>
23 <refname>systemd-journald.socket
</refname>
24 <refname>systemd-journald-dev-log.socket
</refname>
25 <refname>systemd-journald-audit.socket
</refname>
26 <refname>systemd-journald
</refname>
27 <refpurpose>Journal service
</refpurpose>
31 <para><filename>systemd-journald.service
</filename></para>
32 <para><filename>systemd-journald.socket
</filename></para>
33 <para><filename>systemd-journald-dev-log.socket
</filename></para>
34 <para><filename>systemd-journald-audit.socket
</filename></para>
35 <para><filename>/usr/lib/systemd/systemd-journald
</filename></para>
39 <title>Description
</title>
41 <para><filename>systemd-journald
</filename> is a system service
42 that collects and stores logging data. It creates and maintains
43 structured, indexed journals based on logging information that is
44 received from a variety of sources:
</para>
47 <listitem><para>Kernel log messages, via kmsg
</para></listitem>
49 <listitem><para>Simple system log messages, via the
<filename>libc
</filename> <citerefentry
50 project='man-pages'
><refentrytitle>syslog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
51 call
</para></listitem>
53 <listitem><para>Structured system log messages via the native
55 <citerefentry><refentrytitle>sd_journal_print
</refentrytitle><manvolnum>3</manvolnum></citerefentry></para></listitem>
57 <listitem><para>Standard output and standard error of service units. For further details see
58 below.
</para></listitem>
60 <listitem><para>Audit records, originating from the kernel audit subsystem
</para></listitem>
63 <para>The daemon will implicitly collect numerous metadata fields
64 for each log messages in a secure and unfakeable way. See
65 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>
66 for more information about the collected metadata.
69 <para>Log data collected by the journal is primarily text-based but can also include binary data where
70 necessary. Individual fields making up a log record stored in the journal may be up to
2^
64-
1 bytes in size.
</para>
72 <para>The journal service stores log data either persistently below
<filename>/var/log/journal
</filename> or in a
73 volatile way below
<filename>/run/log/journal/
</filename> (in the latter case it is lost at reboot). By default, log
74 data is stored persistently if
<filename>/var/log/journal/
</filename> exists during boot, with an implicit fallback
75 to volatile storage otherwise. Use
<varname>Storage=
</varname> in
76 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry> to configure
77 where log data is placed, independently of the existence of
<filename>/var/log/journal/
</filename>.
</para>
79 <para>On systems where
<filename>/var/log/journal/
</filename> does not exist yet but where persistent logging is
80 desired (and the default
<filename>journald.conf
</filename> is used), it is sufficient to create the directory, and
81 ensure it has the correct access modes and ownership:
</para>
83 <programlisting>mkdir -p /var/log/journal
84 systemd-tmpfiles --create --prefix /var/log/journal
</programlisting>
87 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
88 for information about the configuration of this service.
</para>
92 <title>Stream logging
</title>
94 <para>The systemd service manager invokes all service processes with standard output and standard error connected
95 to the journal by default. This behaviour may be altered via the
96 <varname>StandardOutput=
</varname>/
<varname>StandardError=
</varname> unit file settings, see
97 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details. The
98 journal converts the log byte stream received this way into individual log records, splitting the stream at newline
99 (
<literal>\n
</literal>, ASCII
<constant>10</constant>) and
<constant>NUL
</constant> bytes.
</para>
101 <para>If
<filename>systemd-journald.service
</filename> is stopped, the stream connections associated with all
102 services are terminated. Further writes to those streams by the service will result in
<constant>EPIPE
</constant>
103 errors. In order to react gracefully in this case it is recommended that programs logging to standard output/error
104 ignore such errors. If the
<constant>SIGPIPE
</constant> UNIX signal handler is not blocked or turned off, such
105 write attempts will also result in such process signals being generated, see
106 <citerefentry><refentrytitle>signal
</refentrytitle><manvolnum>7</manvolnum></citerefentry>. To mitigate this issue,
107 systemd service manager explicitly turns off the
<constant>SIGPIPE
</constant> signal for all invoked processes by
108 default (this may be changed for each unit individually via the
<varname>IgnoreSIGPIPE=
</varname> option, see
109 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
110 details). After the standard output/standard error streams have been terminated they may not be recovered until the
111 services they are associated with are restarted. Note that during normal operation,
112 <filename>systemd-journald.service
</filename> stores copies of the file descriptors for those streams in the
113 service manager. If
<filename>systemd-journald.service
</filename> is restarted using
<command>systemctl
114 restart
</command> or equivalent operation instead of a pair of separate
<command>systemctl stop
</command> and
115 <command>systemctl start
</command> commands (or equivalent operations), these stream connections are not terminated
116 and survive the restart. It is thus safe to restart
<filename>systemd-journald.service
</filename>, but stopping it
117 is not recommended.
</para>
119 <para>Note that the log record metadata for records transferred via such standard output/error streams reflect the
120 metadata of the peer the stream was originally created for. If the stream connection is passed on to other
121 processes (such as further child processes forked off the main service process), the log records will not reflect
122 their metadata, but will continue to describe the original process. This is different from the other logging
123 transports listed above, which are inherently record based and where the metadata is always associated with the
124 individual record.
</para>
126 <para>In addition to the implicit standard output/error logging of services, stream logging is also available
127 via the
<citerefentry><refentrytitle>systemd-cat
</refentrytitle><manvolnum>1</manvolnum></citerefentry> command
130 <para>Currently, the number of parallel log streams
<filename>systemd-journald
</filename> will accept is limited to
131 4096. When this limit is reached further log streams may be established but will receive
132 <constant>EPIPE
</constant> right from the beginning.
</para>
136 <title>Signals
</title>
142 <listitem><para>Request that journal data from
143 <filename>/run/
</filename> is flushed to
144 <filename>/var/
</filename> in order to make it persistent (if
145 this is enabled). This must be used after
146 <filename>/var/
</filename> is mounted, as otherwise log data
147 from
<filename>/run
</filename> is never flushed to
148 <filename>/var
</filename> regardless of the configuration. The
149 <command>journalctl --flush
</command> command uses this signal
150 to request flushing of the journal files, and then waits for
151 the operation to complete. See
152 <citerefentry><refentrytitle>journalctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
153 for details.
</para></listitem>
159 <listitem><para>Request immediate rotation of the journal
160 files. The
<command>journalctl --rotate
</command> command uses
161 this signal to request journal file
162 rotation.
</para></listitem>
166 <term>SIGRTMIN+
1</term>
168 <listitem><para>Request that all unwritten log data is written
169 to disk. The
<command>journalctl --sync
</command> command uses
170 this signal to trigger journal synchronization, and then waits
171 for the operation to complete.
</para></listitem>
177 <title>Kernel Command Line
</title>
179 <para>A few configuration parameters from
180 <filename>journald.conf
</filename> may be overridden on the kernel
183 <variablelist class='kernel-commandline-options'
>
185 <term><varname>systemd.journald.forward_to_syslog=
</varname></term>
186 <term><varname>systemd.journald.forward_to_kmsg=
</varname></term>
187 <term><varname>systemd.journald.forward_to_console=
</varname></term>
188 <term><varname>systemd.journald.forward_to_wall=
</varname></term>
190 <listitem><para>Enables/disables forwarding of collected log
191 messages to syslog, the kernel log buffer, the system console
196 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
197 for information about these settings.
</para>
205 <title>Access Control
</title>
207 <para>Journal files are, by default, owned and readable by the
208 <literal>systemd-journal
</literal> system group but are not
209 writable. Adding a user to this group thus enables them to read
210 the journal files.
</para>
212 <para>By default, each logged in user will get their own set of
213 journal files in
<filename>/var/log/journal/
</filename>. These
214 files will not be owned by the user, however, in order to avoid
215 that the user can write to them directly. Instead, file system
216 ACLs are used to ensure the user gets read access only.
</para>
218 <para>Additional users and groups may be granted access to journal
219 files via file system access control lists (ACL). Distributions
220 and administrators may choose to grant read access to all members
221 of the
<literal>wheel
</literal> and
<literal>adm
</literal> system
222 groups with a command such as the following:
</para>
224 <programlisting># setfacl -Rnm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal/
</programlisting>
226 <para>Note that this command will update the ACLs both for
227 existing journal files and for future journal files created in the
228 <filename>/var/log/journal/
</filename> directory.
</para>
236 <term><filename>/etc/systemd/journald.conf
</filename></term>
238 <listitem><para>Configure
<command>systemd-journald
</command> behavior. See
239 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
244 <term><filename>/run/log/journal/
<replaceable>machine-id
</replaceable>/*.journal
</filename></term>
245 <term><filename>/run/log/journal/
<replaceable>machine-id
</replaceable>/*.journal~
</filename></term>
246 <term><filename>/var/log/journal/
<replaceable>machine-id
</replaceable>/*.journal
</filename></term>
247 <term><filename>/var/log/journal/
<replaceable>machine-id
</replaceable>/*.journal~
</filename></term>
249 <listitem><para><command>systemd-journald
</command> writes entries to files in
250 <filename>/run/log/journal/
<replaceable>machine-id
</replaceable>/
</filename>
252 <filename>/var/log/journal/
<replaceable>machine-id
</replaceable>/
</filename>
253 with the
<literal>.journal
</literal> suffix. If the daemon is
254 stopped uncleanly, or if the files are found to be corrupted,
255 they are renamed using the
<literal>.journal~
</literal>
256 suffix, and
<command>systemd-journald
</command> starts writing
257 to a new file.
<filename>/run
</filename> is used when
258 <filename>/var/log/journal
</filename> is not available, or
259 when
<option>Storage=volatile
</option> is set in the
260 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
261 configuration file.
</para>
263 <para>When
<filename>systemd-journald
</filename> ceases writing to a journal file,
264 it will be renamed to
<literal><replaceable>original-name
</replaceable>@
<replaceable>suffix.journal
</replaceable></literal>
265 (or
<literal><replaceable>original-name
</replaceable>@
<replaceable>suffix.journal~
</replaceable></literal>).
266 Such files are
"archived" and will not be written to any more.
</para>
268 <para>In general, it is safe to read or copy any journal file (active or archived).
269 <citerefentry><refentrytitle>journalctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
270 and the functions in the
271 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
272 library should be able to read all entries that have been fully written.
</para>
274 <para><filename>systemd-journald
</filename> will automatically remove the oldest
275 archived journal files to limit disk use. See
<varname>SystemMaxUse=
</varname>
276 and related settings in
277 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
282 <term><filename>/dev/kmsg
</filename></term>
283 <term><filename>/dev/log
</filename></term>
284 <term><filename>/run/systemd/journal/dev-log
</filename></term>
285 <term><filename>/run/systemd/journal/socket
</filename></term>
286 <term><filename>/run/systemd/journal/stdout
</filename></term>
288 <listitem><para>Sockets and other paths that
289 <command>systemd-journald
</command> will listen on that are
290 visible in the file system. In addition to these, journald can
291 listen for audit events using netlink.
</para></listitem>
297 <title>See Also
</title>
299 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
300 <citerefentry><refentrytitle>journalctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
301 <citerefentry><refentrytitle>journald.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
302 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
303 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
304 <citerefentry><refentrytitle>systemd-coredump
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
305 <citerefentry project='die-net'
><refentrytitle>setfacl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
306 <citerefentry><refentrytitle>sd_journal_print
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
307 <command>pydoc systemd.journal
</command>