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