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