]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd-run.xml
man: use same header for all files
[thirdparty/systemd.git] / man / systemd-run.xml
CommitLineData
514094f9 1<?xml version='1.0'?>
3a54a157
ZJS
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
f09114bc 5
dfdebb1b
ZJS
6<refentry id="systemd-run"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
f09114bc
ZJS
8
9 <refentryinfo>
10 <title>systemd-run</title>
11 <productname>systemd</productname>
f09114bc
ZJS
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>systemd-run</refentrytitle>
16 <manvolnum>1</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>systemd-run</refname>
624dd009 21 <refpurpose>Run programs in transient scope units, service units, or path-, socket-, or timer-triggered service units</refpurpose>
f09114bc
ZJS
22 </refnamediv>
23
24 <refsynopsisdiv>
25 <cmdsynopsis>
26 <command>systemd-run</command>
27 <arg choice="opt" rep="repeat">OPTIONS</arg>
28 <arg choice="plain"><replaceable>COMMAND</replaceable>
29 <arg choice="opt" rep="repeat">ARGS</arg>
30 </arg>
31 </cmdsynopsis>
624dd009
YW
32 <cmdsynopsis>
33 <command>systemd-run</command>
34 <arg choice="opt" rep="repeat">OPTIONS</arg>
35 <arg choice="opt" rep="repeat">PATH OPTIONS</arg>
36 <arg choice="req"><replaceable>COMMAND</replaceable></arg>
37 <arg choice="opt" rep="repeat">ARGS</arg>
38 </cmdsynopsis>
39 <cmdsynopsis>
40 <command>systemd-run</command>
41 <arg choice="opt" rep="repeat">OPTIONS</arg>
42 <arg choice="opt" rep="repeat">SOCKET OPTIONS</arg>
43 <arg choice="req"><replaceable>COMMAND</replaceable></arg>
44 <arg choice="opt" rep="repeat">ARGS</arg>
45 </cmdsynopsis>
4c213d6c
WC
46 <cmdsynopsis>
47 <command>systemd-run</command>
48 <arg choice="opt" rep="repeat">OPTIONS</arg>
49 <arg choice="opt" rep="repeat">TIMER OPTIONS</arg>
50 <arg choice="req"><replaceable>COMMAND</replaceable></arg>
51 <arg choice="opt" rep="repeat">ARGS</arg>
52 </cmdsynopsis>
f09114bc
ZJS
53 </refsynopsisdiv>
54
55 <refsect1>
56 <title>Description</title>
57
014c4c98
LP
58 <para><command>systemd-run</command> may be used to create and start a transient <filename>.service</filename> or
59 <filename>.scope</filename> unit and run the specified <replaceable>COMMAND</replaceable> in it. It may also be
624dd009
YW
60 used to create and start a transient <filename>.path</filename>, <filename>.socket</filename>, or
61 <filename>.timer</filename> unit, that activates a <filename>.service</filename> unit when elapsing.</para>
014c4c98
LP
62
63 <para>If a command is run as transient service unit, it will be started and managed by the service manager like any
64 other service, and thus shows up in the output of <command>systemctl list-units</command> like any other unit. It
65 will run in a clean and detached execution environment, with the service manager as its parent process. In this
66 mode, <command>systemd-run</command> will start the service asynchronously in the background and return after the
b03ec009 67 command has begun execution (unless <option>--no-block</option> or <option>--wait</option> are specified, see
014c4c98
LP
68 below).</para>
69
70 <para>If a command is run as transient scope unit, it will be executed by <command>systemd-run</command> itself as
71 parent process and will thus inherit the execution environment of the caller. However, the processes of the command
72 are managed by the service manager similar to normal services, and will show up in the output of <command>systemctl
73 list-units</command>. Execution in this case is synchronous, and will return only when the command finishes. This
74 mode is enabled via the <option>--scope</option> switch (see below). </para>
75
624dd009
YW
76 <para>If a command is run with path, socket, or timer options such as <option>--on-calendar=</option> (see below),
77 a transient path, socket, or timer unit is created alongside the service unit for the specified command. Only the
78 transient path, socket, or timer unit is started immediately, the transient service unit will be triggered by the
79 path, socket, or timer unit. If the <option>--unit=</option> option is specified, the
80 <replaceable>COMMAND</replaceable> may be omitted. In this case, <command>systemd-run</command> creates only a
81 <filename>.path</filename>, <filename>.socket</filename>, or <filename>.timer</filename> unit that triggers the
82 specified unit.</para>
79905a24
LP
83
84 <para>By default, services created with <command>systemd-run</command> default to the <option>simple</option> type,
85 see the description of <varname>Type=</varname> in
86 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
87 details. Note that when this type is used the service manager (and thus the <command>systemd-run</command> command)
88 considers service start-up successful as soon as the <function>fork()</function> for the main service process
89 succeeded, i.e. before the <function>execve()</function> is invoked, and thus even if the specified command cannot
90 be started. Consider using the <option>exec</option> service type (i.e. <option>--property=Type=exec</option>) to
91 ensure that <command>systemd-run</command> returns successfully only if the specified command line has been
92 successfully started.</para>
f09114bc
ZJS
93 </refsect1>
94
95 <refsect1>
96 <title>Options</title>
97
98 <para>The following options are understood:</para>
99
100 <variablelist>
8c7db2fb
EV
101 <varlistentry>
102 <term><option>--no-ask-password</option></term>
103
104 <listitem><para>Do not query the user for authentication for
105 privileged operations.</para></listitem>
106 </varlistentry>
107
f09114bc
ZJS
108 <varlistentry>
109 <term><option>--scope</option></term>
110
111 <listitem>
014c4c98
LP
112 <para>Create a transient <filename>.scope</filename> unit instead of the default transient
113 <filename>.service</filename> unit (see above).
f09114bc
ZJS
114 </para>
115 </listitem>
116 </varlistentry>
117
118 <varlistentry>
119 <term><option>--unit=</option></term>
120
121 <listitem><para>Use this unit name instead of an automatically
122 generated one.</para></listitem>
123 </varlistentry>
124
df31a6c0
LP
125 <varlistentry>
126 <term><option>--property=</option></term>
127 <term><option>-p</option></term>
128
014c4c98
LP
129 <listitem><para>Sets a property on the scope or service unit that is created. This option takes an assignment
130 in the same format as
df31a6c0
LP
131 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
132 <command>set-property</command> command.</para>
133 </listitem>
134 </varlistentry>
135
f09114bc
ZJS
136 <varlistentry>
137 <term><option>--description=</option></term>
138
624dd009
YW
139 <listitem><para>Provide a description for the service, scope, path, socket, or timer unit. If not specified,
140 the command itself will be used as a description. See <varname>Description=</varname> in
f09114bc
ZJS
141 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
142 </para></listitem>
143 </varlistentry>
144
145 <varlistentry>
146 <term><option>--slice=</option></term>
147
014c4c98
LP
148 <listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part of the
149 specified slice, instead of <filename>system.slice</filename>.</para>
f09114bc
ZJS
150 </listitem>
151 </varlistentry>
6577c7ce
LP
152
153 <varlistentry>
a953b31a 154 <term><option>-r</option></term>
6577c7ce
LP
155 <term><option>--remain-after-exit</option></term>
156
014c4c98
LP
157 <listitem><para>After the service process has terminated, keep the service around until it is explicitly
158 stopped. This is useful to collect runtime information about the service after it finished running. Also see
6577c7ce
LP
159 <varname>RemainAfterExit=</varname> in
160 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
161 </para>
162 </listitem>
163 </varlistentry>
a6c0353b
LP
164
165 <varlistentry>
166 <term><option>--send-sighup</option></term>
167
014c4c98
LP
168 <listitem><para>When terminating the scope or service unit, send a SIGHUP immediately after SIGTERM. This is
169 useful to indicate to shells and shell-like processes that the connection has been severed. Also see
981ee551 170 <varname>SendSIGHUP=</varname> in
a6c0353b
LP
171 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
172 </para>
173 </listitem>
174 </varlistentry>
dfdebb1b 175
981ee551
LP
176 <varlistentry>
177 <term><option>--service-type=</option></term>
178
179 <listitem><para>Sets the service type. Also see
180 <varname>Type=</varname> in
181 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
182 option has no effect in conjunction with
183 <option>--scope</option>. Defaults to
184 <constant>simple</constant>.</para>
185 </listitem>
186 </varlistentry>
187
188 <varlistentry>
189 <term><option>--uid=</option></term>
190 <term><option>--gid=</option></term>
191
014c4c98
LP
192 <listitem><para>Runs the service process under the specified UNIX user and group. Also see
193 <varname>User=</varname> and <varname>Group=</varname> in
4de33e7f 194 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
981ee551
LP
195 </listitem>
196 </varlistentry>
197
198 <varlistentry>
199 <term><option>--nice=</option></term>
200
201 <listitem><para>Runs the service process with the specified
202 nice level. Also see <varname>Nice=</varname> in
4de33e7f 203 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
981ee551 204 </listitem>
2d21165a
LP
205 </varlistentry>
206
207 <varlistentry>
208 <term><option>--working-directory=</option></term>
209
210 <listitem><para>Runs the service process with the specified working directory. Also see
211 <varname>WorkingDirectory=</varname> in
212 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
213 </listitem>
214 </varlistentry>
215
216 <varlistentry>
217 <term><option>--same-dir</option></term>
218 <term><option>-d</option></term>
219
220 <listitem><para>Similar to <option>--working-directory=</option> but uses the current working directory of the
221 caller for the service to execute.</para></listitem>
981ee551
LP
222 </varlistentry>
223
224 <varlistentry>
b5911366
ZJS
225 <term><option>-E <replaceable>NAME</replaceable>=<replaceable>VALUE</replaceable></option></term>
226 <term><option>--setenv=<replaceable>NAME</replaceable>=<replaceable>VALUE</replaceable></option></term>
981ee551 227
b5911366
ZJS
228 <listitem><para>Runs the service process with the specified environment variable set.
229 Also see <varname>Environment=</varname> in
4de33e7f 230 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
981ee551
LP
231 </listitem>
232 </varlistentry>
233
9b15b784
LP
234 <varlistentry>
235 <term><option>--pty</option></term>
236 <term><option>-t</option></term>
237
5dca7739
LP
238 <listitem><para>When invoking the command, the transient service connects its standard input, output and error
239 to the terminal <command>systemd-run</command> is invoked on, via a pseudo TTY device. This allows running
156d6036 240 programs that expect interactive user input/output as services, such as interactive command shells.</para>
7f129a1f
LP
241
242 <para>Note that
243 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
244 <command>shell</command> command is usually a better alternative for requesting a new, interactive login
5dca7739
LP
245 session on the local host or a local container.</para>
246
247 <para>See below for details on how this switch combines with <option>--pipe</option>.</para></listitem>
248 </varlistentry>
249
250 <varlistentry>
251 <term><option>--pipe</option></term>
252 <term><option>-P</option></term>
253
254 <listitem><para>If specified, standard input, output, and error of the transient service are inherited from the
156d6036
ZJS
255 <command>systemd-run</command> command itself. This allows <command>systemd-run</command>
256 to be used within shell pipelines.
257 Note that this mode is not suitable for interactive command shells and similar, as the
960d20e1 258 service process will not become a TTY controller when invoked on a terminal. Use <option>--pty</option> instead
5dca7739
LP
259 in that case.</para>
260
261 <para>When both <option>--pipe</option> and <option>--pty</option> are used in combination the more appropriate
262 option is automatically determined and used. Specifically, when invoked with standard input, output and error
b0e8cec2
LP
263 connected to a TTY <option>--pty</option> is used, and otherwise <option>--pipe</option>.</para>
264
265 <para>When this option is used the original file descriptors <command>systemd-run</command> receives are passed
266 to the service processes as-is. If the service runs with different privileges than
267 <command>systemd-run</command>, this means the service might not be able to re-open the passed file
268 descriptors, due to normal file descriptor access restrictions. If the invoked process is a shell script that
269 uses the <command>echo "hello" > /dev/stderr</command> construct for writing messages to stderr, this might
270 cause problems, as this only works if stderr can be re-opened. To mitigate this use the construct <command>echo
271 "hello" >&amp;2</command> instead, which is mostly equivalent and avoids this pitfall.</para></listitem>
9b15b784 272 </varlistentry>
88ae7333 273
badd28e1
LP
274 <varlistentry>
275 <term><option>--shell</option></term>
276 <term><option>-S</option></term>
277
278 <listitem><para>A shortcut for <literal>--pty --same-dir --wait --collect --service-type=exec $SHELL</literal>,
279 i.e. requests an interactive shell in the current working directory, running in service context, accessible
280 with a single switch.</para></listitem>
281 </varlistentry>
282
095dc596
LP
283 <varlistentry>
284 <term><option>--quiet</option></term>
285 <term><option>-q</option></term>
286
287 <listitem><para>Suppresses additional informational output
288 while running. This is particularly useful in combination with
289 <option>--pty</option> when it will suppress the initial
290 message explaining how to terminate the TTY connection.</para></listitem>
291 </varlistentry>
292
4c213d6c
WC
293 <varlistentry>
294 <term><option>--on-active=</option></term>
295 <term><option>--on-boot=</option></term>
296 <term><option>--on-startup=</option></term>
297 <term><option>--on-unit-active=</option></term>
298 <term><option>--on-unit-inactive=</option></term>
299
014c4c98
LP
300 <listitem><para>Defines a monotonic timer relative to different starting points for starting the specified
301 command. See <varname>OnActiveSec=</varname>, <varname>OnBootSec=</varname>, <varname>OnStartupSec=</varname>,
302 <varname>OnUnitActiveSec=</varname> and <varname>OnUnitInactiveSec=</varname> in
303 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
624dd009
YW
304 details. These options are shortcuts for <command>--timer-property=</command> with the relevant properties.
305 These options may not be combined with <option>--scope</option> or <option>--pty</option>.</para>
4c213d6c
WC
306 </listitem>
307 </varlistentry>
308
309 <varlistentry>
310 <term><option>--on-calendar=</option></term>
311
014c4c98
LP
312 <listitem><para>Defines a calendar timer for starting the specified command. See <varname>OnCalendar=</varname>
313 in <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
624dd009
YW
314 option is a shortcut for <command>--timer-property=OnCalendar=</command>. This option may not be combined with
315 <option>--scope</option> or <option>--pty</option>.</para>
4c213d6c
WC
316 </listitem>
317 </varlistentry>
318
319 <varlistentry>
624dd009
YW
320 <term><option>--path-property=</option></term>
321 <term><option>--socket-property=</option></term>
4c213d6c
WC
322 <term><option>--timer-property=</option></term>
323
624dd009
YW
324 <listitem><para>Sets a property on the path, socket, or timer unit that is created. This option is similar to
325 <option>--property=</option> but applies to the transient path, socket, or timer unit rather than the
326 transient service unit created. This option takes an assignment in the same format as
327 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
328 <command>set-property</command> command. These options may not be combined with
329 <option>--scope</option> or <option>--pty</option>.</para>
330 </listitem>
4c213d6c
WC
331 </varlistentry>
332
3d161f99
LP
333 <varlistentry>
334 <term><option>--no-block</option></term>
335
336 <listitem>
014c4c98
LP
337 <para>Do not synchronously wait for the unit start operation to finish. If this option is not specified, the
338 start request for the transient unit will be verified, enqueued and <command>systemd-run</command> will wait
339 until the unit's start-up is completed. By passing this argument, it is only verified and enqueued. This
340 option may not be combined with <option>--wait</option>.</para>
3d161f99
LP
341 </listitem>
342 </varlistentry>
343
014c4c98
LP
344 <varlistentry>
345 <term><option>--wait</option></term>
346
347 <listitem><para>Synchronously wait for the transient service to terminate. If this option is specified, the
348 start request for the transient unit is verified, enqueued, and waited for. Subsequently the invoked unit is
349 monitored, and it is waited until it is deactivated again (most likely because the specified command
350 completed). On exit, terse information about the unit's runtime is shown, including total runtime (as well as
351 CPU usage, if <option>--property=CPUAccounting=1</option> was set) and the exit code and status of the main
352 process. This output may be suppressed with <option>--quiet</option>. This option may not be combined with
624dd009 353 <option>--no-block</option>, <option>--scope</option> or the various path, socket, or timer options.</para></listitem>
014c4c98
LP
354 </varlistentry>
355
fe9d0be9
LP
356 <varlistentry>
357 <term><option>-G</option></term>
358 <term><option>--collect</option></term>
359
360 <listitem><para>Unload the transient unit after it completed, even if it failed. Normally, without this option,
361 all units that ran and failed are kept in memory until the user explicitly resets their failure state with
362 <command>systemctl reset-failed</command> or an equivalent command. On the other hand, units that ran
363 successfully are unloaded immediately. If this option is turned on the "garbage collection" of units is more
364 aggressive, and unloads units regardless if they exited successfully or failed. This option is a shortcut for
365 <command>--property=CollectMode=inactive-or-failed</command>, see the explanation for
366 <varname>CollectMode=</varname> in
367 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for further
368 information.</para></listitem>
369 </varlistentry>
370
9b15b784
LP
371 <xi:include href="user-system-options.xml" xpointer="user" />
372 <xi:include href="user-system-options.xml" xpointer="system" />
373 <xi:include href="user-system-options.xml" xpointer="host" />
374 <xi:include href="user-system-options.xml" xpointer="machine" />
375
dfdebb1b
ZJS
376 <xi:include href="standard-options.xml" xpointer="help" />
377 <xi:include href="standard-options.xml" xpointer="version" />
f09114bc
ZJS
378 </variablelist>
379
81c7dd89 380 <para>All command line arguments after the first non-option
3f85ef0f 381 argument become part of the command line of the launched
3f2d1365
AJ
382 process. If a command is run as service unit, the first argument
383 needs to be an absolute program path.</para>
f09114bc
ZJS
384 </refsect1>
385
386 <refsect1>
387 <title>Exit status</title>
388
389 <para>On success, 0 is returned, a non-zero failure
390 code otherwise.</para>
391 </refsect1>
392
c9d954b2 393 <refsect1>
df31a6c0 394 <title>Examples</title>
c9d954b2 395
4eac7f5c
ZJS
396 <example>
397 <title>Logging environment variables provided by systemd to services</title>
c9d954b2 398
4eac7f5c 399 <programlisting># systemd-run env
f3ea87af 400Running as unit: run-19945.service
c9d954b2
ZJS
401# journalctl -u run-19945.service
402Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env...
403Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env.
404Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
405Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8
9fccdb0f 406Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting>
4eac7f5c 407 </example>
df31a6c0 408
4eac7f5c
ZJS
409 <example>
410 <title>Limiting resources available to a command</title>
df31a6c0 411
4eac7f5c 412 <programlisting># systemd-run -p BlockIOWeight=10 updatedb</programlisting>
4c213d6c 413
4eac7f5c
ZJS
414 <para>This command invokes the
415 <citerefentry project='man-pages'><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry>
416 tool, but lowers the block I/O weight for it to 10. See
417 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
418 for more information on the <varname>BlockIOWeight=</varname>
419 property.</para>
420 </example>
4c213d6c 421
4eac7f5c
ZJS
422 <example>
423 <title>Running commands at a specified time</title>
424
425 <para>The following command will touch a file after 30 seconds.</para>
426
427 <programlisting># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo
4c213d6c 428Mon Dec 8 20:44:24 KST 2014
f3ea87af
ILG
429Running as unit: run-71.timer
430Will run service as unit: run-71.service
85fb8031 431# journalctl -b -u run-71.timer
4c213d6c
WC
432-- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
433Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo.
434Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo.
85fb8031 435# journalctl -b -u run-71.service
4c213d6c
WC
436-- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
437Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo...
438Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</programlisting>
4eac7f5c 439 </example>
9b15b784 440
4eac7f5c
ZJS
441 <example>
442 <title>Allowing access to the tty</title>
9b15b784 443
4eac7f5c
ZJS
444 <para>The following command invokes <filename>/bin/bash</filename> as a service
445 passing its standard input, output and error to the calling TTY.</para>
9b15b784 446
4eac7f5c
ZJS
447 <programlisting># systemd-run -t --send-sighup /bin/bash</programlisting>
448 </example>
65eb37f8
ZJS
449
450 <example>
451 <title>Start <command>screen</command> as a user service</title>
452
453 <programlisting>$ systemd-run --scope --user screen
454Running scope as unit run-r14b0047ab6df45bfb45e7786cc839e76.scope.
455
456$ screen -ls
457There is a screen on:
458 492..laptop (Detached)
4591 Socket in /var/run/screen/S-fatima.
460</programlisting>
461
462 <para>This starts the <command>screen</command> process as a child of the
463 <command>systemd --user</command> process that was started by
464 <filename>user@.service</filename>, in a scope unit. A
465 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>
466 unit is used instead of a
467 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
468 unit, because <command>screen</command> will exit when detaching from the terminal,
469 and a service unit would be terminated. Running <command>screen</command>
470 as a user unit has the advantage that it is not part of the session scope.
471 If <varname>KillUserProcesses=yes</varname> is configured in
472 <citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
473 the default, the session scope will be terminated when the user logs
474 out of that session.</para>
475
476 <para>The <filename>user@.service</filename> is started automatically
477 when the user first logs in, and stays around as long as at least one
478 login session is open. After the user logs out of the last session,
479 <filename>user@.service</filename> and all services underneath it
2dd67817 480 are terminated. This behavior is the default, when "lingering" is
65eb37f8
ZJS
481 not enabled for that user. Enabling lingering means that
482 <filename>user@.service</filename> is started automatically during
483 boot, even if the user is not logged in, and that the service is
484 not terminated when the user logs out.</para>
485
486 <para>Enabling lingering allows the user to run processes without being logged in,
487 for example to allow <command>screen</command> to persist after the user logs out,
488 even if the session scope is terminated. In the default configuration, users can
489 enable lingering for themselves:</para>
490
491 <programlisting>$ loginctl enable-linger</programlisting>
492 </example>
c9d954b2
ZJS
493 </refsect1>
494
f09114bc
ZJS
495 <refsect1>
496 <title>See Also</title>
497 <para>
498 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
3803cde4 499 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
f09114bc
ZJS
500 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
501 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
502 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
d21ed1ea 503 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
df31a6c0
LP
504 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
505 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
4c213d6c 506 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
450442cf 507 <citerefentry><refentrytitle>systemd-mount</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
d21ed1ea 508 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
f09114bc
ZJS
509 </para>
510 </refsect1>
511
512</refentry>