]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-run.xml
Merge pull request #28999 from keszybz/two-man-ukify-fixe
[thirdparty/systemd.git] / man / systemd-run.xml
1 <?xml version='1.0'?>
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-run"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>systemd-run</title>
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>systemd-run</refentrytitle>
16 <manvolnum>1</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>systemd-run</refname>
21 <refpurpose>Run programs in transient scope units, service units, or path-, socket-, or timer-triggered service units</refpurpose>
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>
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>
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>
53 </refsynopsisdiv>
54
55 <refsect1>
56 <title>Description</title>
57
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
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>
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
67 command has begun execution (unless <option>--no-block</option> or <option>--wait</option> are specified, see
68 below).</para>
69
70 <para>If a command is run as transient scope unit, it will be executed by <command>systemd-run</command>
71 itself as parent process and will thus inherit the execution environment of the caller. However, the
72 processes of the command are managed by the service manager similarly to normal services, and will show
73 up in the output of <command>systemctl list-units</command>. Execution in this case is synchronous, and
74 will return only when the command finishes. This mode is enabled via the <option>--scope</option> switch
75 (see below).</para>
76
77 <para>If a command is run with path, socket, or timer options such as <option>--on-calendar=</option> (see below),
78 a transient path, socket, or timer unit is created alongside the service unit for the specified command. Only the
79 transient path, socket, or timer unit is started immediately, the transient service unit will be triggered by the
80 path, socket, or timer unit. If the <option>--unit=</option> option is specified, the
81 <replaceable>COMMAND</replaceable> may be omitted. In this case, <command>systemd-run</command> creates only a
82 <filename>.path</filename>, <filename>.socket</filename>, or <filename>.timer</filename> unit that triggers the
83 specified unit.</para>
84
85 <para>By default, services created with <command>systemd-run</command> default to the
86 <option>simple</option> type, see the description of <varname>Type=</varname> in
87 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
88 details. Note that when this type is used, the service manager (and thus the
89 <command>systemd-run</command> command) considers service start-up successful as soon as the
90 <function>fork()</function> for the main service process succeeded, i.e. before the
91 <function>execve()</function> is invoked, and thus even if the specified command cannot be started.
92 Consider using the <option>exec</option> service type (i.e. <option>--property=Type=exec</option>) to
93 ensure that <command>systemd-run</command> returns successfully only if the specified command line has
94 been successfully started.</para>
95
96 <para>After <command>systemd-run</command> passes the command to the service manager, the manager
97 performs variable expansion. This means that dollar characters (<literal>$</literal>) which should not be
98 expanded need to be escaped as <literal>$$</literal>. Expansion can also be disabled using
99 <varname>--expand-environment=no</varname>.</para>
100 </refsect1>
101
102 <refsect1>
103 <title>Options</title>
104
105 <para>The following options are understood:</para>
106
107 <variablelist>
108 <varlistentry>
109 <term><option>--no-ask-password</option></term>
110
111 <listitem><para>Do not query the user for authentication for
112 privileged operations.</para>
113
114 <xi:include href="version-info.xml" xpointer="v226"/></listitem>
115 </varlistentry>
116
117 <varlistentry>
118 <term><option>--scope</option></term>
119
120 <listitem>
121 <para>Create a transient <filename>.scope</filename> unit instead of the default transient
122 <filename>.service</filename> unit (see above).
123 </para>
124
125 <xi:include href="version-info.xml" xpointer="v206"/>
126 </listitem>
127 </varlistentry>
128
129 <varlistentry>
130 <term><option>--unit=</option></term>
131 <term><option>-u</option></term>
132
133 <listitem><para>Use this unit name instead of an automatically
134 generated one.</para></listitem>
135 </varlistentry>
136
137 <varlistentry>
138 <term><option>--property=</option></term>
139 <term><option>-p</option></term>
140
141 <listitem><para>Sets a property on the scope or service unit that is created. This option takes an assignment
142 in the same format as
143 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
144 <command>set-property</command> command.</para>
145
146 <xi:include href="version-info.xml" xpointer="v211"/>
147 </listitem>
148 </varlistentry>
149
150 <varlistentry>
151 <term><option>--description=</option></term>
152
153 <listitem><para>Provide a description for the service, scope, path, socket, or timer unit. If not specified,
154 the command itself will be used as a description. See <varname>Description=</varname> in
155 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
156 </para>
157
158 <xi:include href="version-info.xml" xpointer="v206"/></listitem>
159 </varlistentry>
160
161 <varlistentry>
162 <term><option>--slice=</option></term>
163
164 <listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part
165 of the specified slice, instead of <filename>system.slice</filename> (when running in
166 <option>--system</option> mode) or the root slice (when running in <option>--user</option>
167 mode).</para>
168
169 <xi:include href="version-info.xml" xpointer="v206"/>
170 </listitem>
171 </varlistentry>
172
173 <varlistentry>
174 <term><option>--slice-inherit</option></term>
175
176 <listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part
177 of the inherited slice. This option can be combined with <option>--slice=</option>.</para>
178
179 <para>An inherited slice is located within <command>systemd-run</command> slice. Example: if
180 <command>systemd-run</command> slice is <filename>foo.slice</filename>, and the
181 <option>--slice=</option> argument is <filename>bar</filename>, the unit will be placed under the
182 <filename>foo-bar.slice</filename>.</para>
183
184 <xi:include href="version-info.xml" xpointer="v246"/>
185
186 </listitem>
187 </varlistentry>
188
189 <varlistentry>
190 <term><option>--expand-environment=<replaceable>BOOL</replaceable></option></term>
191
192 <listitem><para>Expand environment variables in command arguments. If enabled, environment variables
193 specified as <literal>${<replaceable>VARIABLE</replaceable>}</literal> will be expanded in the same
194 way as in commands specified via <varname>ExecStart=</varname> in units. With
195 <varname>--scope</varname>, this expansion is performed by <command>systemd-run</command> itself, and
196 in other cases by the service manager that spawns the command. Note that this is similar to, but not
197 the same as variable expansion in
198 <citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry>
199 and other shells.</para>
200
201 <para>The default is to enable this option in all cases, except for <varname>--scope</varname> where
202 it is disabled by default, for backward compatibility reasons. Note that this will be changed in a
203 future release, where it will be switched to enabled by default as well.</para>
204
205 <para>See
206 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
207 for a description of variable expansion. Disabling variable expansion is useful if the specified
208 command includes or may include a <literal>$</literal> sign.</para>
209
210 <xi:include href="version-info.xml" xpointer="v254"/>
211 </listitem>
212 </varlistentry>
213
214 <varlistentry>
215 <term><option>-r</option></term>
216 <term><option>--remain-after-exit</option></term>
217
218 <listitem><para>After the service process has terminated, keep the service around until it is explicitly
219 stopped. This is useful to collect runtime information about the service after it finished running. Also see
220 <varname>RemainAfterExit=</varname> in
221 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
222 </para>
223 </listitem>
224 </varlistentry>
225
226 <varlistentry>
227 <term><option>--send-sighup</option></term>
228
229 <listitem><para>When terminating the scope or service unit, send a SIGHUP immediately after SIGTERM. This is
230 useful to indicate to shells and shell-like processes that the connection has been severed. Also see
231 <varname>SendSIGHUP=</varname> in
232 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
233 </para>
234
235 <xi:include href="version-info.xml" xpointer="v207"/>
236 </listitem>
237 </varlistentry>
238
239 <varlistentry>
240 <term><option>--service-type=</option></term>
241
242 <listitem><para>Sets the service type. Also see
243 <varname>Type=</varname> in
244 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
245 option has no effect in conjunction with
246 <option>--scope</option>. Defaults to
247 <constant>simple</constant>.</para>
248
249 <xi:include href="version-info.xml" xpointer="v211"/>
250 </listitem>
251 </varlistentry>
252
253 <varlistentry>
254 <term><option>--uid=</option></term>
255 <term><option>--gid=</option></term>
256
257 <listitem><para>Runs the service process under the specified UNIX user and group. Also see
258 <varname>User=</varname> and <varname>Group=</varname> in
259 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
260
261 <xi:include href="version-info.xml" xpointer="v211"/>
262 </listitem>
263 </varlistentry>
264
265 <varlistentry>
266 <term><option>--nice=</option></term>
267
268 <listitem><para>Runs the service process with the specified
269 nice level. Also see <varname>Nice=</varname> in
270 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
271
272 <xi:include href="version-info.xml" xpointer="v211"/>
273 </listitem>
274 </varlistentry>
275
276 <varlistentry>
277 <term><option>--working-directory=</option></term>
278
279 <listitem><para>Runs the service process with the specified working directory. Also see
280 <varname>WorkingDirectory=</varname> in
281 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
282
283 <xi:include href="version-info.xml" xpointer="v240"/>
284 </listitem>
285 </varlistentry>
286
287 <varlistentry>
288 <term><option>--same-dir</option></term>
289 <term><option>-d</option></term>
290
291 <listitem><para>Similar to <option>--working-directory=</option>, but uses the current working
292 directory of the caller for the service to execute.</para>
293
294 <xi:include href="version-info.xml" xpointer="v240"/></listitem>
295 </varlistentry>
296
297 <varlistentry>
298 <term><option>-E <replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term>
299 <term><option>--setenv=<replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term>
300
301 <listitem><para>Runs the service process with the specified environment variable set. This parameter
302 may be used more than once to set multiple variables. When <literal>=</literal> and
303 <replaceable>VALUE</replaceable> are omitted, the value of the variable with the same name in the
304 program environment will be used.</para>
305
306 <para>Also see <varname>Environment=</varname> in
307 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
308
309 <xi:include href="version-info.xml" xpointer="v250"/>
310 </listitem>
311 </varlistentry>
312
313 <varlistentry>
314 <term><option>--pty</option></term>
315 <term><option>-t</option></term>
316
317 <listitem><para>When invoking the command, the transient service connects its standard input, output and error
318 to the terminal <command>systemd-run</command> is invoked on, via a pseudo TTY device. This allows running
319 programs that expect interactive user input/output as services, such as interactive command shells.</para>
320
321 <para>Note that
322 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
323 <command>shell</command> command is usually a better alternative for requesting a new, interactive login
324 session on the local host or a local container.</para>
325
326 <para>See below for details on how this switch combines with <option>--pipe</option>.</para>
327
328 <xi:include href="version-info.xml" xpointer="v219"/></listitem>
329 </varlistentry>
330
331 <varlistentry>
332 <term><option>--pipe</option></term>
333 <term><option>-P</option></term>
334
335 <listitem><para>If specified, standard input, output, and error of the transient service are inherited from the
336 <command>systemd-run</command> command itself. This allows <command>systemd-run</command>
337 to be used within shell pipelines.
338 Note that this mode is not suitable for interactive command shells and similar, as the
339 service process will not become a TTY controller when invoked on a terminal. Use <option>--pty</option> instead
340 in that case.</para>
341
342 <para>When both <option>--pipe</option> and <option>--pty</option> are used in combination the more appropriate
343 option is automatically determined and used. Specifically, when invoked with standard input, output and error
344 connected to a TTY <option>--pty</option> is used, and otherwise <option>--pipe</option>.</para>
345
346 <para>When this option is used the original file descriptors <command>systemd-run</command> receives are passed
347 to the service processes as-is. If the service runs with different privileges than
348 <command>systemd-run</command>, this means the service might not be able to re-open the passed file
349 descriptors, due to normal file descriptor access restrictions. If the invoked process is a shell script that
350 uses the <command>echo "hello" >/dev/stderr</command> construct for writing messages to stderr, this might
351 cause problems, as this only works if stderr can be re-opened. To mitigate this use the construct <command>echo
352 "hello" >&amp;2</command> instead, which is mostly equivalent and avoids this pitfall.</para>
353
354 <xi:include href="version-info.xml" xpointer="v235"/></listitem>
355 </varlistentry>
356
357 <varlistentry>
358 <term><option>--shell</option></term>
359 <term><option>-S</option></term>
360
361 <listitem><para>A shortcut for <literal>--pty --same-dir --wait --collect --service-type=exec $SHELL</literal>,
362 i.e. requests an interactive shell in the current working directory, running in service context, accessible
363 with a single switch.</para>
364
365 <xi:include href="version-info.xml" xpointer="v240"/></listitem>
366 </varlistentry>
367
368 <varlistentry>
369 <term><option>--quiet</option></term>
370 <term><option>-q</option></term>
371
372 <listitem><para>Suppresses additional informational output
373 while running. This is particularly useful in combination with
374 <option>--pty</option> when it will suppress the initial
375 message explaining how to terminate the TTY connection.</para>
376
377 <xi:include href="version-info.xml" xpointer="v219"/></listitem>
378 </varlistentry>
379
380 <varlistentry>
381 <term><option>--on-active=</option></term>
382 <term><option>--on-boot=</option></term>
383 <term><option>--on-startup=</option></term>
384 <term><option>--on-unit-active=</option></term>
385 <term><option>--on-unit-inactive=</option></term>
386
387 <listitem><para>Defines a monotonic timer relative to different starting points for starting the specified
388 command. See <varname>OnActiveSec=</varname>, <varname>OnBootSec=</varname>, <varname>OnStartupSec=</varname>,
389 <varname>OnUnitActiveSec=</varname> and <varname>OnUnitInactiveSec=</varname> in
390 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
391 details. These options are shortcuts for <command>--timer-property=</command> with the relevant properties.
392 These options may not be combined with <option>--scope</option> or <option>--pty</option>.</para>
393
394 <xi:include href="version-info.xml" xpointer="v218"/>
395 </listitem>
396 </varlistentry>
397
398 <varlistentry>
399 <term><option>--on-calendar=</option></term>
400
401 <listitem><para>Defines a calendar timer for starting the specified command. See <varname>OnCalendar=</varname>
402 in <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
403 option is a shortcut for <command>--timer-property=OnCalendar=</command>. This option may not be combined with
404 <option>--scope</option> or <option>--pty</option>.</para>
405
406 <xi:include href="version-info.xml" xpointer="v218"/>
407 </listitem>
408 </varlistentry>
409
410 <varlistentry>
411 <term><option>--on-clock-change</option></term>
412 <term><option>--on-timezone-change</option></term>
413
414 <listitem><para>Defines a trigger based on system clock jumps or timezone changes for starting the
415 specified command. See <varname>OnClockChange=</varname> and <varname>OnTimezoneChange=</varname> in
416 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. These
417 options are shortcuts for <command>--timer-property=OnClockChange=yes</command> and
418 <command>--timer-property=OnTimezoneChange=yes</command>. These options may not be combined with
419 <option>--scope</option> or <option>--pty</option>.</para>
420
421 <xi:include href="version-info.xml" xpointer="v242"/></listitem>
422 </varlistentry>
423
424 <varlistentry>
425 <term><option>--path-property=</option></term>
426 <term><option>--socket-property=</option></term>
427 <term><option>--timer-property=</option></term>
428
429 <listitem><para>Sets a property on the path, socket, or timer unit that is created. This option is
430 similar to <option>--property=</option>, but applies to the transient path, socket, or timer unit
431 rather than the transient service unit created. This option takes an assignment in the same format as
432 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
433 <command>set-property</command> command. These options may not be combined with
434 <option>--scope</option> or <option>--pty</option>.</para>
435 </listitem>
436 </varlistentry>
437
438 <varlistentry>
439 <term><option>--no-block</option></term>
440
441 <listitem>
442 <para>Do not synchronously wait for the unit start operation to finish. If this option is not specified, the
443 start request for the transient unit will be verified, enqueued and <command>systemd-run</command> will wait
444 until the unit's start-up is completed. By passing this argument, it is only verified and enqueued. This
445 option may not be combined with <option>--wait</option>.</para>
446
447 <xi:include href="version-info.xml" xpointer="v220"/>
448 </listitem>
449 </varlistentry>
450
451 <varlistentry>
452 <term><option>--wait</option></term>
453
454 <listitem><para>Synchronously wait for the transient service to terminate. If this option is specified, the
455 start request for the transient unit is verified, enqueued, and waited for. Subsequently the invoked unit is
456 monitored, and it is waited until it is deactivated again (most likely because the specified command
457 completed). On exit, terse information about the unit's runtime is shown, including total runtime (as well as
458 CPU usage, if <option>--property=CPUAccounting=1</option> was set) and the exit code and status of the main
459 process. This output may be suppressed with <option>--quiet</option>. This option may not be combined with
460 <option>--no-block</option>, <option>--scope</option> or the various path, socket, or timer options.</para>
461
462 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
463 </varlistentry>
464
465 <varlistentry>
466 <term><option>-G</option></term>
467 <term><option>--collect</option></term>
468
469 <listitem><para>Unload the transient unit after it completed, even if it failed. Normally, without this option,
470 all units that ran and failed are kept in memory until the user explicitly resets their failure state with
471 <command>systemctl reset-failed</command> or an equivalent command. On the other hand, units that ran
472 successfully are unloaded immediately. If this option is turned on the "garbage collection" of units is more
473 aggressive, and unloads units regardless if they exited successfully or failed. This option is a shortcut for
474 <command>--property=CollectMode=inactive-or-failed</command>, see the explanation for
475 <varname>CollectMode=</varname> in
476 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for further
477 information.</para>
478
479 <xi:include href="version-info.xml" xpointer="v236"/></listitem>
480 </varlistentry>
481
482 <xi:include href="user-system-options.xml" xpointer="user" />
483 <xi:include href="user-system-options.xml" xpointer="system" />
484 <xi:include href="user-system-options.xml" xpointer="host" />
485 <xi:include href="user-system-options.xml" xpointer="machine" />
486
487 <xi:include href="standard-options.xml" xpointer="help" />
488 <xi:include href="standard-options.xml" xpointer="version" />
489 </variablelist>
490
491 <para>All command line arguments after the first non-option argument become part of the command line of
492 the launched process.</para>
493 </refsect1>
494
495 <refsect1>
496 <title>Exit status</title>
497
498 <para>On success, 0 is returned. If <command>systemd-run</command> failed to start the service, a
499 non-zero return value will be returned. If <command>systemd-run</command> waits for the service to
500 terminate, the return value will be propagated from the service. 0 will be returned on success, including
501 all the cases where systemd considers a service to have exited cleanly, see the discussion of
502 <varname>SuccessExitStatus=</varname> in
503 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
504 </para>
505 </refsect1>
506
507 <refsect1>
508 <title>Examples</title>
509
510 <example>
511 <title>Logging environment variables provided by systemd to services</title>
512
513 <programlisting># systemd-run env
514 Running as unit: run-19945.service
515 # journalctl -u run-19945.service
516 Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env...
517 Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env.
518 Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
519 Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8
520 Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting>
521 </example>
522
523 <example>
524 <title>Limiting resources available to a command</title>
525
526 <programlisting># systemd-run -p IOWeight=10 updatedb</programlisting>
527
528 <para>This command invokes the <citerefentry
529 project='man-pages'><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry>
530 tool, but lowers the block I/O weight for it to 10. See
531 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
532 for more information on the <varname>IOWeight=</varname> property.</para>
533 </example>
534
535 <example>
536 <title>Running commands at a specified time</title>
537
538 <para>The following command will touch a file after 30 seconds.</para>
539
540 <programlisting># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo
541 Mon Dec 8 20:44:24 KST 2014
542 Running as unit: run-71.timer
543 Will run service as unit: run-71.service
544 # journalctl -b -u run-71.timer
545 -- Journal begins at Fri 2014-12-05 19:09:21 KST, ends at Mon 2014-12-08 20:44:54 KST. --
546 Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo.
547 Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo.
548 # journalctl -b -u run-71.service
549 -- Journal begins at Fri 2014-12-05 19:09:21 KST, ends at Mon 2014-12-08 20:44:54 KST. --
550 Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo...
551 Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</programlisting>
552 </example>
553
554 <example>
555 <title>Allowing access to the tty</title>
556
557 <para>The following command invokes <citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry>
558 as a service passing its standard input, output and error to the calling TTY.</para>
559
560 <programlisting># systemd-run -t --send-sighup bash</programlisting>
561 </example>
562
563 <example>
564 <title>Start <command>screen</command> as a user service</title>
565
566 <programlisting>$ systemd-run --scope --user screen
567 Running scope as unit run-r14b0047ab6df45bfb45e7786cc839e76.scope.
568
569 $ screen -ls
570 There is a screen on:
571 492..laptop (Detached)
572 1 Socket in /var/run/screen/S-fatima.
573 </programlisting>
574
575 <para>This starts the <command>screen</command> process as a child of the
576 <command>systemd --user</command> process that was started by
577 <filename>user@.service</filename>, in a scope unit. A
578 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>
579 unit is used instead of a
580 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
581 unit, because <command>screen</command> will exit when detaching from the terminal,
582 and a service unit would be terminated. Running <command>screen</command>
583 as a user unit has the advantage that it is not part of the session scope.
584 If <varname>KillUserProcesses=yes</varname> is configured in
585 <citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
586 the default, the session scope will be terminated when the user logs
587 out of that session.</para>
588
589 <para>The <filename>user@.service</filename> is started automatically
590 when the user first logs in, and stays around as long as at least one
591 login session is open. After the user logs out of the last session,
592 <filename>user@.service</filename> and all services underneath it
593 are terminated. This behavior is the default, when "lingering" is
594 not enabled for that user. Enabling lingering means that
595 <filename>user@.service</filename> is started automatically during
596 boot, even if the user is not logged in, and that the service is
597 not terminated when the user logs out.</para>
598
599 <para>Enabling lingering allows the user to run processes without being logged in,
600 for example to allow <command>screen</command> to persist after the user logs out,
601 even if the session scope is terminated. In the default configuration, users can
602 enable lingering for themselves:</para>
603
604 <programlisting>$ loginctl enable-linger</programlisting>
605 </example>
606
607 <example>
608 <title>Variable expansion by the manager</title>
609
610 <programlisting>$ systemd-run -t echo "&lt;${INVOCATION_ID}>" '&lt;${INVOCATION_ID}>'
611 &lt;> &lt;5d0149bfa2c34b79bccb13074001eb20>
612 </programlisting>
613
614 <para>The first argument is expanded by the shell (double quotes), but the second one is not expanded
615 by the shell (single quotes). <command>echo</command> is called with [<literal>/usr/bin/echo</literal>,
616 <literal>[]</literal>, <literal>[${INVOCATION_ID}]</literal>] as the argument array, and then
617 <command>systemd</command> generates <varname>${INVOCATION_ID}</varname> and substitutes it in the
618 command-line. This substitution could not be done on the client side, because the target ID that will
619 be set for the service isn't known before the call is made.</para>
620 </example>
621
622 <example>
623 <title>Variable expansion and output redirection using a shell</title>
624
625 <para>Variable expansion by <command>systemd</command> can be disabled with
626 <varname>--expand-environment=no</varname>.</para>
627
628 <para>Disabling variable expansion can be useful if the command to execute contains dollar characters
629 and escaping them would be inconvenient. For example, when a shell is used:</para>
630
631 <programlisting>$ systemd-run --expand-environment=no -t bash \
632 -c 'echo $SHELL $$ >/dev/stdout'
633 /bin/bash 12345
634 </programlisting>
635
636 <para>The last argument is passed verbatim to the <command>bash</command> shell which is started by the
637 service unit. The shell expands <literal>$SHELL</literal> to the path of the shell, and
638 <literal>$$</literal> to its process number, and then those strings are passed to the
639 <command>echo</command> built-in and printed to standard output (which in this case is connected to the
640 calling terminal).</para>
641 </example>
642
643 <example>
644 <title>Return value</title>
645
646 <programlisting>$ systemd-run --user --wait true
647 $ systemd-run --user --wait -p SuccessExitStatus=11 bash -c 'exit 11'
648 $ systemd-run --user --wait -p SuccessExitStatus=SIGUSR1 --expand-environment=no \
649 bash -c 'kill -SIGUSR1 $$'</programlisting>
650
651 <para>Those three invocations will succeed, i.e. terminate with an exit code of 0.</para>
652 </example>
653 </refsect1>
654
655 <refsect1>
656 <title>See Also</title>
657 <para>
658 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
659 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
660 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
661 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
662 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
663 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
664 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
665 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
666 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
667 <citerefentry><refentrytitle>systemd-mount</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
668 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
669 </para>
670 </refsect1>
671
672 </refentry>