]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-journald.service.xml
journalctl: make libqrencode a weak dependency
[thirdparty/systemd.git] / man / systemd-journald.service.xml
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+ -->
5
6 <refentry id="systemd-journald.service">
7
8 <refentryinfo>
9 <title>systemd-journald.service</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>systemd-journald.service</refentrytitle>
15 <manvolnum>8</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>systemd-journald.service</refname>
20 <refname>systemd-journald.socket</refname>
21 <refname>systemd-journald-dev-log.socket</refname>
22 <refname>systemd-journald-audit.socket</refname>
23 <refname>systemd-journald@.service</refname>
24 <refname>systemd-journald@.socket</refname>
25 <refname>systemd-journald-varlink@.socket</refname>
26 <refname>systemd-journald</refname>
27 <refpurpose>Journal service</refpurpose>
28 </refnamediv>
29
30 <refsynopsisdiv>
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>systemd-journald@.service</filename></para>
36 <para><filename>systemd-journald@.socket</filename></para>
37 <para><filename>systemd-journald-varlink@.socket</filename></para>
38 <para><filename>/usr/lib/systemd/systemd-journald</filename></para>
39 </refsynopsisdiv>
40
41 <refsect1>
42 <title>Description</title>
43
44 <para><filename>systemd-journald</filename> is a system service
45 that collects and stores logging data. It creates and maintains
46 structured, indexed journals based on logging information that is
47 received from a variety of sources:</para>
48
49 <itemizedlist>
50 <listitem><para>Kernel log messages, via kmsg</para></listitem>
51
52 <listitem><para>Simple system log messages, via the <filename>libc</filename> <citerefentry
53 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
54 call</para></listitem>
55
56 <listitem><para>Structured system log messages via the native
57 Journal API, see
58 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry></para></listitem>
59
60 <listitem><para>Standard output and standard error of service units. For further details see
61 below.</para></listitem>
62
63 <listitem><para>Audit records, originating from the kernel audit subsystem</para></listitem>
64 </itemizedlist>
65
66 <para>The daemon will implicitly collect numerous metadata fields
67 for each log messages in a secure and unfakeable way. See
68 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
69 for more information about the collected metadata.
70 </para>
71
72 <para>Log data collected by the journal is primarily text-based but can also include binary data where
73 necessary. Individual fields making up a log record stored in the journal may be up to 2^64-1 bytes in size.</para>
74
75 <para>The journal service stores log data either persistently below <filename>/var/log/journal</filename> or in a
76 volatile way below <filename>/run/log/journal/</filename> (in the latter case it is lost at reboot). By default, log
77 data is stored persistently if <filename>/var/log/journal/</filename> exists during boot, with an implicit fallback
78 to volatile storage otherwise. Use <varname>Storage=</varname> in
79 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> to configure
80 where log data is placed, independently of the existence of <filename>/var/log/journal/</filename>.</para>
81
82 <para>On systems where <filename>/var/log/journal/</filename> does not exist yet but where persistent logging is
83 desired (and the default <filename>journald.conf</filename> is used), it is sufficient to create the directory, and
84 ensure it has the correct access modes and ownership:</para>
85
86 <programlisting>mkdir -p /var/log/journal
87 systemd-tmpfiles --create --prefix /var/log/journal</programlisting>
88
89 <para>See
90 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
91 for information about the configuration of this service.</para>
92 </refsect1>
93
94 <refsect1>
95 <title>Stream logging</title>
96
97 <para>The systemd service manager invokes all service processes with standard output and standard error connected
98 to the journal by default. This behaviour may be altered via the
99 <varname>StandardOutput=</varname>/<varname>StandardError=</varname> unit file settings, see
100 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details. The
101 journal converts the log byte stream received this way into individual log records, splitting the stream at newline
102 (<literal>\n</literal>, ASCII <constant>10</constant>) and <constant>NUL</constant> bytes.</para>
103
104 <para>If <filename>systemd-journald.service</filename> is stopped, the stream connections associated with all
105 services are terminated. Further writes to those streams by the service will result in <constant>EPIPE</constant>
106 errors. In order to react gracefully in this case it is recommended that programs logging to standard output/error
107 ignore such errors. If the <constant>SIGPIPE</constant> UNIX signal handler is not blocked or turned off, such
108 write attempts will also result in such process signals being generated, see
109 <citerefentry><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>. To mitigate this issue,
110 systemd service manager explicitly turns off the <constant>SIGPIPE</constant> signal for all invoked processes by
111 default (this may be changed for each unit individually via the <varname>IgnoreSIGPIPE=</varname> option, see
112 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
113 details). After the standard output/standard error streams have been terminated they may not be recovered until the
114 services they are associated with are restarted. Note that during normal operation,
115 <filename>systemd-journald.service</filename> stores copies of the file descriptors for those streams in the
116 service manager. If <filename>systemd-journald.service</filename> is restarted using <command>systemctl
117 restart</command> or equivalent operation instead of a pair of separate <command>systemctl stop</command> and
118 <command>systemctl start</command> commands (or equivalent operations), these stream connections are not terminated
119 and survive the restart. It is thus safe to restart <filename>systemd-journald.service</filename>, but stopping it
120 is not recommended.</para>
121
122 <para>Note that the log record metadata for records transferred via such standard output/error streams reflect the
123 metadata of the peer the stream was originally created for. If the stream connection is passed on to other
124 processes (such as further child processes forked off the main service process), the log records will not reflect
125 their metadata, but will continue to describe the original process. This is different from the other logging
126 transports listed above, which are inherently record based and where the metadata is always associated with the
127 individual record.</para>
128
129 <para>In addition to the implicit standard output/error logging of services, stream logging is also available
130 via the <citerefentry><refentrytitle>systemd-cat</refentrytitle><manvolnum>1</manvolnum></citerefentry> command
131 line tool.</para>
132
133 <para>Currently, the number of parallel log streams <filename>systemd-journald</filename> will accept is limited to
134 4096. When this limit is reached further log streams may be established but will receive
135 <constant>EPIPE</constant> right from the beginning.</para>
136 </refsect1>
137
138 <refsect1>
139 <title>Journal Namespaces</title>
140
141 <para>Journal 'namespaces' are both a mechanism for logically isolating the log stream of projects
142 consisting of one or more services from the rest of the system and a mechanism for improving
143 performance. Multiple journal namespaces may exist simultaneously, each defining its own, independent log
144 stream managed by its own instance of <command>systemd-journald</command>. Namespaces are independent of
145 each other, both in the data store and in the IPC interface. By default only a single 'default' namespace
146 exists, managed by <filename>systemd-journald.service</filename> (and its associated socket
147 units). Additional namespaces are created by starting an instance of the
148 <filename>systemd-journald@.service</filename> service template. The instance name is the namespace
149 identifier, which is a short string used for referencing the journal namespace. Service units may be
150 assigned to a specific journal namespace through the <varname>LogNamespace=</varname> unit file setting,
151 see <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
152 details. The <option>--namespace=</option> switch of
153 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> may be
154 used to view the log stream of a specific namespace. If the switch is not used the log stream of the
155 default namespace is shown, i.e. log data from other namespaces is not visible.</para>
156
157 <para>Services associated with a specific log namespace may log via syslog, the native logging protocol
158 of the journal and via stdout/stderr; the logging from all three transports is associated with the
159 namespace.</para>
160
161 <para>By default only the default namespace will collect kernel and audit log messages.</para>
162
163 <para>The <command>systemd-journald</command> instance of the default namespace is configured through
164 <filename>/etc/systemd/journald.conf</filename> (see below), while the other instances are configured
165 through <filename>/etc/systemd/journald@<replaceable>NAMESPACE</replaceable>.conf</filename>. The journal
166 log data for the default namespace is placed in
167 <filename>/var/log/journal/<replaceable>MACHINE_ID</replaceable></filename> (see below) while the data
168 for the other namespaces is located in
169 <filename>/var/log/journal/<replaceable>MACHINE_ID</replaceable>.<replaceable>NAMESPACE</replaceable></filename>.</para>
170 </refsect1>
171
172 <refsect1>
173 <title>Signals</title>
174
175 <variablelist>
176 <varlistentry>
177 <term>SIGUSR1</term>
178
179 <listitem><para>Request that journal data from <filename>/run/</filename> is flushed to
180 <filename>/var/</filename> in order to make it persistent (if this is enabled). This must be used
181 after <filename>/var/</filename> is mounted, as otherwise log data from <filename>/run</filename> is
182 never flushed to <filename>/var</filename> regardless of the configuration. Use the
183 <command>journalctl --flush</command> command to request flushing of the journal files, and wait for
184 the operation to complete. See
185 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
186 details.</para></listitem>
187 </varlistentry>
188
189 <varlistentry>
190 <term>SIGUSR2</term>
191
192 <listitem><para>Request immediate rotation of the journal files. Use the <command>journalctl
193 --rotate</command> command to request journal file rotation, and wait for the operation to
194 complete.</para></listitem>
195 </varlistentry>
196
197 <varlistentry>
198 <term>SIGRTMIN+1</term>
199
200 <listitem><para>Request that all unwritten log data is written to disk. Use the <command>journalctl
201 --sync</command> command to trigger journal synchronization, and wait for the operation to
202 complete.</para></listitem>
203 </varlistentry>
204 </variablelist>
205 </refsect1>
206
207 <refsect1>
208 <title>Kernel Command Line</title>
209
210 <para>A few configuration parameters from
211 <filename>journald.conf</filename> may be overridden on the kernel
212 command line:</para>
213
214 <variablelist class='kernel-commandline-options'>
215 <varlistentry>
216 <term><varname>systemd.journald.forward_to_syslog=</varname></term>
217 <term><varname>systemd.journald.forward_to_kmsg=</varname></term>
218 <term><varname>systemd.journald.forward_to_console=</varname></term>
219 <term><varname>systemd.journald.forward_to_wall=</varname></term>
220
221 <listitem><para>Enables/disables forwarding of collected log
222 messages to syslog, the kernel log buffer, the system console
223 or wall.
224 </para>
225
226 <para>See
227 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
228 for information about these settings.</para>
229 </listitem>
230
231 </varlistentry>
232 </variablelist>
233
234 <para>Note that these kernel command line options are only honoured by the default namespace, see
235 above.</para>
236 </refsect1>
237
238 <refsect1>
239 <title>Access Control</title>
240
241 <para>Journal files are, by default, owned and readable by the
242 <literal>systemd-journal</literal> system group but are not
243 writable. Adding a user to this group thus enables them to read
244 the journal files.</para>
245
246 <para>By default, each user, with a UID outside the range of system users,
247 dynamic service users, and the nobody user, will get their own set of
248 journal files in <filename>/var/log/journal/</filename>. See
249 <ulink url="https://systemd.io/UIDS-GIDS">Users, Groups, UIDs and GIDs on systemd systems</ulink>
250 for more details about UID ranges. These journal
251 files will not be owned by the user, however, in order to avoid
252 that the user can write to them directly. Instead, file system
253 ACLs are used to ensure the user gets read access only.</para>
254
255 <para>Additional users and groups may be granted access to journal
256 files via file system access control lists (ACL). Distributions
257 and administrators may choose to grant read access to all members
258 of the <literal>wheel</literal> and <literal>adm</literal> system
259 groups with a command such as the following:</para>
260
261 <programlisting># setfacl -Rnm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal/</programlisting>
262
263 <para>Note that this command will update the ACLs both for
264 existing journal files and for future journal files created in the
265 <filename>/var/log/journal/</filename> directory.</para>
266 </refsect1>
267
268 <refsect1>
269 <title>Files</title>
270
271 <variablelist>
272 <varlistentry>
273 <term><filename>/etc/systemd/journald.conf</filename></term>
274
275 <listitem><para>Configure <command>systemd-journald</command> behavior. See
276 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
277 </para></listitem>
278 </varlistentry>
279
280 <varlistentry>
281 <term><filename>/run/log/journal/<replaceable>machine-id</replaceable>/*.journal</filename></term>
282 <term><filename>/run/log/journal/<replaceable>machine-id</replaceable>/*.journal~</filename></term>
283 <term><filename>/var/log/journal/<replaceable>machine-id</replaceable>/*.journal</filename></term>
284 <term><filename>/var/log/journal/<replaceable>machine-id</replaceable>/*.journal~</filename></term>
285
286 <listitem><para><command>systemd-journald</command> writes entries to files in
287 <filename>/run/log/journal/<replaceable>machine-id</replaceable>/</filename>
288 or
289 <filename>/var/log/journal/<replaceable>machine-id</replaceable>/</filename>
290 with the <literal>.journal</literal> suffix. If the daemon is
291 stopped uncleanly, or if the files are found to be corrupted,
292 they are renamed using the <literal>.journal~</literal>
293 suffix, and <command>systemd-journald</command> starts writing
294 to a new file. <filename>/run</filename> is used when
295 <filename>/var/log/journal</filename> is not available, or
296 when <option>Storage=volatile</option> is set in the
297 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
298 configuration file.</para>
299
300 <para>When <filename>systemd-journald</filename> ceases writing to a journal file,
301 it will be renamed to <literal><replaceable>original-name</replaceable>@<replaceable>suffix.journal</replaceable></literal>
302 (or <literal><replaceable>original-name</replaceable>@<replaceable>suffix.journal~</replaceable></literal>).
303 Such files are "archived" and will not be written to any more.</para>
304
305 <para>In general, it is safe to read or copy any journal file (active or archived).
306 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
307 and the functions in the
308 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
309 library should be able to read all entries that have been fully written.</para>
310
311 <para><filename>systemd-journald</filename> will automatically remove the oldest
312 archived journal files to limit disk use. See <varname>SystemMaxUse=</varname>
313 and related settings in
314 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
315 </para></listitem>
316 </varlistentry>
317
318 <varlistentry>
319 <term><filename>/dev/kmsg</filename></term>
320 <term><filename>/dev/log</filename></term>
321 <term><filename>/run/systemd/journal/dev-log</filename></term>
322 <term><filename>/run/systemd/journal/socket</filename></term>
323 <term><filename>/run/systemd/journal/stdout</filename></term>
324
325 <listitem><para>Sockets and other file node paths that <command>systemd-journald</command> will
326 listen on and are visible in the file system. In addition to these,
327 <command>systemd-journald</command> can listen for audit events using <citerefentry
328 project='man-pages'><refentrytitle>netlink</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para></listitem>
329 </varlistentry>
330 </variablelist>
331
332 <para>If journal namespacing is used these paths are slightly altered to include a namespace identifier, see above.</para>
333 </refsect1>
334
335 <refsect1>
336 <title>See Also</title>
337 <para>
338 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
339 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
340 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
341 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
342 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
343 <citerefentry><refentrytitle>systemd-coredump</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
344 <citerefentry project='man-pages'><refentrytitle>setfacl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
345 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
346 <command>pydoc systemd.journal</command>
347 </para>
348 </refsect1>
349
350 </refentry>