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