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