1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="systemd-journald.service"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
10 <title>systemd-journald.service</title>
11 <productname>systemd</productname>
15 <refentrytitle>systemd-journald.service</refentrytitle>
16 <manvolnum>8</manvolnum>
20 <refname>systemd-journald.service</refname>
21 <refname>systemd-journald.socket</refname>
22 <refname>systemd-journald-dev-log.socket</refname>
23 <refname>systemd-journald-audit.socket</refname>
24 <refname>systemd-journald@.service</refname>
25 <refname>systemd-journald@.socket</refname>
26 <refname>systemd-journald-varlink@.socket</refname>
27 <refname>systemd-journald</refname>
28 <refpurpose>Journal service</refpurpose>
32 <para><filename>systemd-journald.service</filename></para>
33 <para><filename>systemd-journald.socket</filename></para>
34 <para><filename>systemd-journald-dev-log.socket</filename></para>
35 <para><filename>systemd-journald-audit.socket</filename></para>
36 <para><filename>systemd-journald@.service</filename></para>
37 <para><filename>systemd-journald@.socket</filename></para>
38 <para><filename>systemd-journald-varlink@.socket</filename></para>
39 <para><filename>/usr/lib/systemd/systemd-journald</filename></para>
43 <title>Description</title>
45 <para><filename>systemd-journald</filename> is a system service
46 that collects and stores logging data. It creates and maintains
47 structured, indexed journals based on logging information that is
48 received from a variety of sources:</para>
51 <listitem><para>Kernel log messages, via kmsg</para></listitem>
53 <listitem><para>Simple system log messages, via the <filename>libc</filename> <citerefentry
54 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
55 call</para></listitem>
57 <listitem><para>Structured system log messages via the native Journal API, see
58 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>
59 and <ulink url="https://systemd.io/JOURNAL_NATIVE_PROTOCOL">Native Journal
60 Protocol</ulink></para></listitem>
62 <listitem><para>Standard output and standard error of service units. For further details see
63 below.</para></listitem>
65 <listitem><para>Audit records, originating from the kernel audit subsystem</para></listitem>
68 <para>The daemon will implicitly collect numerous metadata fields
69 for each log messages in a secure and unfakeable way. See
70 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
71 for more information about the collected metadata.
74 <para>Log data collected by the journal is primarily text-based but can also include binary data where
75 necessary. Individual fields making up a log record stored in the journal may be up to 2⁶⁴-1 bytes in size.</para>
77 <para>The journal service stores log data either persistently below <filename>/var/log/journal</filename> or in a
78 volatile way below <filename>/run/log/journal/</filename> (in the latter case it is lost at reboot). By default, log
79 data is stored persistently if <filename>/var/log/journal/</filename> exists during boot, with an implicit fallback
80 to volatile storage otherwise. Use <varname>Storage=</varname> in
81 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> to configure
82 where log data is placed, independently of the existence of <filename>/var/log/journal/</filename>.</para>
84 <para>Note that journald will initially use volatile storage, until a call to
85 <command>journalctl --flush</command> (or sending <constant>SIGUSR1</constant> to journald) will cause
86 it to switch to persistent logging (under the conditions mentioned above). This is done automatically
87 on boot via <literal>systemd-journal-flush.service</literal>.</para>
89 <para>On systems where <filename>/var/log/journal/</filename> does not exist yet but where persistent logging is
90 desired (and the default <filename>journald.conf</filename> is used), it is sufficient to create the directory, and
91 ensure it has the correct access modes and ownership:</para>
93 <programlisting>mkdir -p /var/log/journal
94 systemd-tmpfiles --create --prefix /var/log/journal</programlisting>
97 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
98 for information about the configuration of this service.</para>
102 <title>Stream logging</title>
104 <para>The systemd service manager invokes all service processes with standard output and standard error connected
105 to the journal by default. This behaviour may be altered via the
106 <varname>StandardOutput=</varname>/<varname>StandardError=</varname> unit file settings, see
107 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details. The
108 journal converts the log byte stream received this way into individual log records, splitting the stream at newline
109 (<literal>\n</literal>, ASCII <constant>10</constant>) and <constant>NUL</constant> bytes.</para>
111 <para>If <filename>systemd-journald.service</filename> is stopped, the stream connections associated with all
112 services are terminated. Further writes to those streams by the service will result in <constant>EPIPE</constant>
113 errors. In order to react gracefully in this case it is recommended that programs logging to standard output/error
114 ignore such errors. If the <constant>SIGPIPE</constant> UNIX signal handler is not blocked or turned off, such
115 write attempts will also result in such process signals being generated, see
116 <citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
117 To mitigate this issue, systemd service manager explicitly turns off the <constant>SIGPIPE</constant>
118 signal for all invoked processes by default (this may be changed for each unit individually via the
119 <varname>IgnoreSIGPIPE=</varname> option, see
120 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
121 details). After the standard output/standard error streams have been terminated they may not be recovered
122 until the services they are associated with are restarted. Note that during normal operation,
123 <filename>systemd-journald.service</filename> stores copies of the file descriptors for those streams in
124 the service manager. If <filename>systemd-journald.service</filename> is restarted using
125 <command>systemctl restart</command> or equivalent operation instead of a pair of separate
126 <command>systemctl stop</command> and <command>systemctl start</command> commands (or equivalent
127 operations), these stream connections are not terminated and survive the restart. It is thus safe to
128 restart <filename>systemd-journald.service</filename>, but stopping it is not recommended.</para>
130 <para>Note that the log record metadata for records transferred via such standard output/error streams reflect the
131 metadata of the peer the stream was originally created for. If the stream connection is passed on to other
132 processes (such as further child processes forked off the main service process), the log records will not reflect
133 their metadata, but will continue to describe the original process. This is different from the other logging
134 transports listed above, which are inherently record based and where the metadata is always associated with the
135 individual record.</para>
137 <para>In addition to the implicit standard output/error logging of services, stream logging is also available
138 via the <citerefentry><refentrytitle>systemd-cat</refentrytitle><manvolnum>1</manvolnum></citerefentry> command
141 <para>Currently, the number of parallel log streams <filename>systemd-journald</filename> will accept is limited to
142 4096. When this limit is reached further log streams may be established but will receive
143 <constant>EPIPE</constant> right from the beginning.</para>
147 <title>Journal Namespaces</title>
149 <para>Journal 'namespaces' are both a mechanism for logically isolating the log stream of projects
150 consisting of one or more services from the rest of the system and a mechanism for improving
151 performance. Multiple journal namespaces may exist simultaneously, each defining its own, independent log
152 stream managed by its own instance of <command>systemd-journald</command>. Namespaces are independent of
153 each other, both in the data store and in the IPC interface. By default only a single 'default' namespace
154 exists, managed by <filename>systemd-journald.service</filename> (and its associated socket
155 units). Additional namespaces are created by starting an instance of the
156 <filename>systemd-journald@.service</filename> service template. The instance name is the namespace
157 identifier, which is a short string used for referencing the journal namespace. Service units may be
158 assigned to a specific journal namespace through the <varname>LogNamespace=</varname> unit file setting,
159 see <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
160 details. The <option>--namespace=</option> switch of
161 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> may be
162 used to view the log stream of a specific namespace. If the switch is not used the log stream of the
163 default namespace is shown, i.e. log data from other namespaces is not visible.</para>
165 <para>Services associated with a specific log namespace may log via syslog, the native logging protocol
166 of the journal and via stdout/stderr; the logging from all three transports is associated with the
169 <para>By default only the default namespace will collect kernel and audit log messages.</para>
171 <para>The <command>systemd-journald</command> instance of the default namespace is configured through
172 <filename>/etc/systemd/journald.conf</filename> (see below), while the other instances are configured
173 through <filename>/etc/systemd/journald@<replaceable>NAMESPACE</replaceable>.conf</filename>. The journal
174 log data for the default namespace is placed in
175 <filename>/var/log/journal/<replaceable>MACHINE_ID</replaceable></filename> (see below) while the data
176 for the other namespaces is located in
177 <filename>/var/log/journal/<replaceable>MACHINE_ID</replaceable>.<replaceable>NAMESPACE</replaceable></filename>.</para>
181 <title>Signals</title>
187 <listitem><para>Request that journal data from <filename>/run/</filename> is flushed to
188 <filename>/var/</filename> in order to make it persistent (if this is enabled). This must be used
189 after <filename>/var/</filename> is mounted, as otherwise log data from <filename>/run/</filename> is
190 never flushed to <filename>/var/</filename> regardless of the configuration. Use the
191 <command>journalctl --flush</command> command to request flushing of the journal files, and wait for
192 the operation to complete. See
193 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
196 <xi:include href="version-info.xml" xpointer="v186"/></listitem>
202 <listitem><para>Request immediate rotation of the journal files. Use the <command>journalctl
203 --rotate</command> command to request journal file rotation, and wait for the operation to
206 <xi:include href="version-info.xml" xpointer="v186"/></listitem>
210 <term>SIGRTMIN+1</term>
212 <listitem><para>Request that all unwritten log data is written to disk. Use the <command>journalctl
213 --sync</command> command to trigger journal synchronization, and wait for the operation to
216 <xi:include href="version-info.xml" xpointer="v228"/></listitem>
222 <title>Kernel Command Line</title>
224 <para>A few configuration parameters from
225 <filename>journald.conf</filename> may be overridden on the kernel
228 <variablelist class='kernel-commandline-options'>
230 <term><varname>systemd.journald.forward_to_syslog=</varname></term>
231 <term><varname>systemd.journald.forward_to_kmsg=</varname></term>
232 <term><varname>systemd.journald.forward_to_console=</varname></term>
233 <term><varname>systemd.journald.forward_to_wall=</varname></term>
235 <listitem><para>Enables/disables forwarding of collected log
236 messages to syslog, the kernel log buffer, the system console
241 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
242 for information about these settings.</para>
244 <xi:include href="version-info.xml" xpointer="v186"/>
250 <term><varname>systemd.journald.max_level_store=</varname></term>
251 <term><varname>systemd.journald.max_level_syslog=</varname></term>
252 <term><varname>systemd.journald.max_level_kmsg=</varname></term>
253 <term><varname>systemd.journald.max_level_console=</varname></term>
254 <term><varname>systemd.journald.max_level_wall=</varname></term>
255 <term><varname>systemd.journald.max_level_socket=</varname></term>
257 <listitem><para>Controls the maximum log level of messages that are stored in the journal, forwarded
258 to syslog, kmsg, the console, the wall, or a socket. This kernel command line options override the
259 settings of the same names in the
260 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
263 <xi:include href="version-info.xml" xpointer="v232"/>
268 <para>Note that these kernel command line options are only honoured by the default namespace, see
273 <title>Access Control</title>
275 <para>Journal files are, by default, owned and readable by the
276 <literal>systemd-journal</literal> system group but are not
277 writable. Adding a user to this group thus enables them to read
278 the journal files.</para>
280 <para>By default, each user, with a UID outside the range of system users,
281 dynamic service users, and the nobody user, will get their own set of
282 journal files in <filename>/var/log/journal/</filename>. See
283 <ulink url="https://systemd.io/UIDS-GIDS">Users, Groups, UIDs and GIDs on systemd systems</ulink>
284 for more details about UID ranges. These journal
285 files will not be owned by the user, however, in order to avoid
286 that the user can write to them directly. Instead, file system
287 ACLs are used to ensure the user gets read access only.</para>
289 <para>Additional users and groups may be granted access to journal
290 files via file system access control lists (ACL). Distributions
291 and administrators may choose to grant read access to all members
292 of the <literal>wheel</literal> and <literal>adm</literal> system
293 groups with a command such as the following:</para>
295 <programlisting># setfacl -Rnm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal/</programlisting>
297 <para>Note that this command will update the ACLs both for
298 existing journal files and for future journal files created in the
299 <filename>/var/log/journal/</filename> directory.</para>
307 <term><filename>/etc/systemd/journald.conf</filename></term>
309 <listitem><para>Configure <command>systemd-journald</command> behavior. See
310 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
313 <xi:include href="version-info.xml" xpointer="v206"/></listitem>
317 <term><filename>/run/log/journal/<replaceable>machine-id</replaceable>/*.journal</filename></term>
318 <term><filename>/run/log/journal/<replaceable>machine-id</replaceable>/*.journal~</filename></term>
319 <term><filename>/var/log/journal/<replaceable>machine-id</replaceable>/*.journal</filename></term>
320 <term><filename>/var/log/journal/<replaceable>machine-id</replaceable>/*.journal~</filename></term>
322 <listitem><para><command>systemd-journald</command> writes entries to files in
323 <filename>/run/log/journal/<replaceable>machine-id</replaceable>/</filename>
325 <filename>/var/log/journal/<replaceable>machine-id</replaceable>/</filename>
326 with the <literal>.journal</literal> suffix. If the daemon is
327 stopped uncleanly, or if the files are found to be corrupted,
328 they are renamed using the <literal>.journal~</literal>
329 suffix, and <command>systemd-journald</command> starts writing
330 to a new file. <filename>/run/</filename> is used when
331 <filename>/var/log/journal</filename> is not available, or
332 when <option>Storage=volatile</option> is set in the
333 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
334 configuration file.</para>
336 <para>When <filename>systemd-journald</filename> ceases writing to a journal file,
337 it will be renamed to <literal><replaceable>original-name</replaceable>@<replaceable>suffix.journal</replaceable></literal>
338 (or <literal><replaceable>original-name</replaceable>@<replaceable>suffix.journal~</replaceable></literal>).
339 Such files are "archived" and will not be written to any more.</para>
341 <para>In general, it is safe to read or copy any journal file (active or archived).
342 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
343 and the functions in the
344 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
345 library should be able to read all entries that have been fully written.</para>
347 <para><filename>systemd-journald</filename> will automatically remove the oldest
348 archived journal files to limit disk use. See <varname>SystemMaxUse=</varname>
349 and related settings in
350 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
353 <xi:include href="version-info.xml" xpointer="v206"/></listitem>
357 <term><filename>/dev/kmsg</filename></term>
358 <term><filename>/dev/log</filename></term>
359 <term><filename>/run/systemd/journal/dev-log</filename></term>
360 <term><filename>/run/systemd/journal/socket</filename></term>
361 <term><filename>/run/systemd/journal/stdout</filename></term>
363 <listitem><para>Sockets and other file node paths that <command>systemd-journald</command> will
364 listen on and are visible in the file system. In addition to these,
365 <command>systemd-journald</command> can listen for audit events using <citerefentry
366 project='man-pages'><refentrytitle>netlink</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
367 depending on whether <literal>systemd-journald-audit.socket</literal> is enabled or
370 <xi:include href="version-info.xml" xpointer="v228"/></listitem>
374 <para>If journal namespacing is used these paths are slightly altered to include a namespace identifier, see above.</para>
378 <title>See Also</title>
380 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
381 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
382 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
383 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
384 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
385 <citerefentry><refentrytitle>systemd-coredump</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
386 <citerefentry project='man-pages'><refentrytitle>setfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
387 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
388 <command>pydoc systemd.journal</command>