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