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">
6 This file is part of systemd.
8 Copyright 2013 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
24 <refentry id=
"systemd-run"
25 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
28 <title>systemd-run
</title>
29 <productname>systemd
</productname>
33 <contrib>Developer
</contrib>
34 <firstname>Lennart
</firstname>
35 <surname>Poettering
</surname>
36 <email>lennart@poettering.net
</email>
42 <refentrytitle>systemd-run
</refentrytitle>
43 <manvolnum>1</manvolnum>
47 <refname>systemd-run
</refname>
48 <refpurpose>Run programs in transient scope or service or timer units
</refpurpose>
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>
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>
69 <title>Description
</title>
71 <para><command>systemd-run
</command> may be used to create and
72 start a transient
<filename>.service
</filename> or
73 <filename>.scope
</filename> unit and run the specified
74 <replaceable>COMMAND
</replaceable> in it. It may also be used to
75 create and start transient
<filename>.timer
</filename>
78 <para>If a command is run as transient service unit, it will be
79 started and managed by the service manager like any other service,
80 and thus shows up in the output of
<command>systemctl
81 list-units
</command> like any other unit. It will run in a clean
82 and detached execution environment, with the service manager as
83 its parent process. In this mode
<command>systemd-run
</command>
84 will start the service asynchronously in the background and return
85 after the command has begun execution.
</para>
87 <para>If a command is run as transient scope unit, it will be
88 started by
<command>systemd-run
</command> itself as parent process
89 and will thus inherit the execution environment of the
90 caller. However, the processes of the command are managed by the
91 service manager similar to normal services, and will show up in
92 the output of
<command>systemctl list-units
</command>. Execution
93 in this case is synchronous, and will return only when the command
94 finishes. This mode is enabled via the
<option>--scope
</option>
95 switch (see below).
</para>
97 <para>If a command is run with timer options such as
98 <option>--on-calendar=
</option> (see below), a transient timer
99 unit is created alongside the service unit for the specified
100 command. Only the transient timer unit is started immediately, the
101 transient service unit will be started when the transient timer
102 elapses. If the
<option>--unit=
</option> is specified, the
103 <replaceable>COMMAND
</replaceable> may be omitted. In this case,
104 <command>systemd-run
</command> only creates a
105 <filename>.timer
</filename> unit that invokes the specified unit
106 when elapsing.
</para>
110 <title>Options
</title>
112 <para>The following options are understood:
</para>
116 <term><option>--no-ask-password
</option></term>
118 <listitem><para>Do not query the user for authentication for
119 privileged operations.
</para></listitem>
123 <term><option>--scope
</option></term>
126 <para>Create a transient
<filename>.scope
</filename> unit instead of
127 the default transient
<filename>.service
</filename> unit.
133 <term><option>--unit=
</option></term>
135 <listitem><para>Use this unit name instead of an automatically
136 generated one.
</para></listitem>
140 <term><option>--property=
</option></term>
141 <term><option>-p
</option></term>
143 <listitem><para>Sets a unit property for the scope or service
144 unit that is created. This takes an assignment in the same
146 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
147 <command>set-property
</command> command.
</para>
152 <term><option>--description=
</option></term>
154 <listitem><para>Provide a description for the service or scope
155 unit. If not specified, the command itself will be used as a
156 description. See
<varname>Description=
</varname> in
157 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
162 <term><option>--slice=
</option></term>
164 <listitem><para>Make the new
<filename>.service
</filename> or
165 <filename>.scope
</filename> unit part of the specified slice,
166 instead of the
<filename>system.slice
</filename>.
</para>
171 <term><option>--remain-after-exit
</option></term>
173 <listitem><para>After the service or scope process has
174 terminated, keep the service around until it is explicitly
175 stopped. This is useful to collect runtime information about
176 the service after it finished running. Also see
177 <varname>RemainAfterExit=
</varname> in
178 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
184 <term><option>--send-sighup
</option></term>
186 <listitem><para>When terminating the scope or service unit,
187 send a SIGHUP immediately after SIGTERM. This is useful to
188 indicate to shells and shell-like processes that the
189 connection has been severed. Also see
190 <varname>SendSIGHUP=
</varname> in
191 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
197 <term><option>--service-type=
</option></term>
199 <listitem><para>Sets the service type. Also see
200 <varname>Type=
</varname> in
201 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
202 option has no effect in conjunction with
203 <option>--scope
</option>. Defaults to
204 <constant>simple
</constant>.
</para>
209 <term><option>--uid=
</option></term>
210 <term><option>--gid=
</option></term>
212 <listitem><para>Runs the service process under the UNIX user
213 and group. Also see
<varname>User=
</varname> and
214 <varname>Group=
</varname> in
215 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
220 <term><option>--nice=
</option></term>
222 <listitem><para>Runs the service process with the specified
223 nice level. Also see
<varname>Nice=
</varname> in
224 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
229 <term><option>--setenv=
</option></term>
231 <listitem><para>Runs the service process with the specified
232 environment variables set. Also see
233 <varname>Environment=
</varname> in
234 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
239 <term><option>--pty
</option></term>
240 <term><option>-t
</option></term>
242 <listitem><para>When invoking a command as service connects
243 its standard input and output to the invoking tty via a
244 pseudo TTY device. This allows invoking binaries as services
245 that expect interactive user input, such as interactive
246 command shells.
</para></listitem>
250 <term><option>--quiet
</option></term>
251 <term><option>-q
</option></term>
253 <listitem><para>Suppresses additional informational output
254 while running. This is particularly useful in combination with
255 <option>--pty
</option> when it will suppress the initial
256 message explaining how to terminate the TTY connection.
</para></listitem>
260 <term><option>--on-active=
</option></term>
261 <term><option>--on-boot=
</option></term>
262 <term><option>--on-startup=
</option></term>
263 <term><option>--on-unit-active=
</option></term>
264 <term><option>--on-unit-inactive=
</option></term>
266 <listitem><para>Defines monotonic timers relative to different
267 starting points. Also see
<varname>OnActiveSec=
</varname>,
268 <varname>OnBootSec=
</varname>,
269 <varname>OnStartupSec=
</varname>,
270 <varname>OnUnitActiveSec=
</varname> and
271 <varname>OnUnitInactiveSec=
</varname> in
272 <citerefentry><refentrytitle>systemd.timer
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
273 options have no effect in conjunction with
274 <option>--scope
</option>.
</para>
279 <term><option>--on-calendar=
</option></term>
281 <listitem><para>Defines realtime (i.e. wallclock) timers with
282 calendar event expressions. Also see
283 <varname>OnCalendar=
</varname> in
284 <citerefentry><refentrytitle>systemd.timer
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
285 option has no effect in conjunction with
286 <option>--scope
</option>.
</para>
291 <term><option>--timer-property=
</option></term>
293 <listitem><para>Sets a timer unit property for the timer unit
294 that is created. It is similar with
295 <option>--property
</option> but only for created timer
296 unit. This option only has effect in conjunction with
297 <option>--on-active=
</option>,
<option>--on-boot=
</option>,
298 <option>--on-startup=
</option>,
299 <option>--on-unit-active=
</option>,
300 <option>--on-unit-inactive=
</option>,
301 <option>--on-calendar=
</option>. This takes an assignment in
303 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
304 <command>set-property
</command> command.
</para> </listitem>
308 <term><option>--no-block
</option></term>
311 <para>Do not synchronously wait for the requested operation
312 to finish. If this is not specified, the job will be
313 verified, enqueued and
<command>systemd-run
</command> will
314 wait until the unit's start-up is completed. By passing this
315 argument, it is only verified and enqueued.
</para>
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" />
324 <xi:include href=
"standard-options.xml" xpointer=
"help" />
325 <xi:include href=
"standard-options.xml" xpointer=
"version" />
328 <para>All command line arguments after the first non-option
329 argument become part of the command line of the launched
330 process. If a command is run as service unit, its first argument
331 needs to be an absolute binary path.
</para>
335 <title>Exit status
</title>
337 <para>On success,
0 is returned, a non-zero failure
338 code otherwise.
</para>
342 <title>Examples
</title>
344 <para>The following command will log the environment variables
345 provided by systemd to services:
</para>
347 <programlisting># systemd-run env
348 Running as unit run-
19945.service.
349 # journalctl -u run-
19945.service
350 Sep
08 07:
37:
21 bupkis systemd[
1]: Starting /usr/bin/env...
351 Sep
08 07:
37:
21 bupkis systemd[
1]: Started /usr/bin/env.
352 Sep
08 07:
37:
21 bupkis env[
19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
353 Sep
08 07:
37:
21 bupkis env[
19948]: LANG=en_US.UTF-
8
354 Sep
08 07:
37:
21 bupkis env[
19948]: BOOT_IMAGE=/vmlinuz-
3.11.0-
0.rc5.git6.2.fc20.x86_64
</programlisting>
356 <para>The following command invokes the
357 <citerefentry project='man-pages'
><refentrytitle>updatedb
</refentrytitle><manvolnum>8</manvolnum></citerefentry>
358 tool, but lowers the block IO weight for it to
10. See
359 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
360 for more information on the
<varname>BlockIOWeight=
</varname>
363 <programlisting># systemd-run -p BlockIOWeight=
10 updatedb
</programlisting>
365 <para>The following command will touch a file after
30 seconds.
</para>
367 <programlisting># date; systemd-run --on-active=
30 --timer-property=AccuracySec=
100ms /bin/touch /tmp/foo
368 Mon Dec
8 20:
44:
24 KST
2014
369 Running as unit run-
71.timer.
370 Will run as unit run-
71.service.
371 # journalctl -b -u run-
71.timer
372 -- Logs begin at Fri
2014-
12-
05 19:
09:
21 KST, end at Mon
2014-
12-
08 20:
44:
54 KST. --
373 Dec
08 20:
44:
38 container systemd[
1]: Starting /bin/touch /tmp/foo.
374 Dec
08 20:
44:
38 container systemd[
1]: Started /bin/touch /tmp/foo.
375 # journalctl -b -u run-
71.service
376 -- Logs begin at Fri
2014-
12-
05 19:
09:
21 KST, end at Mon
2014-
12-
08 20:
44:
54 KST. --
377 Dec
08 20:
44:
48 container systemd[
1]: Starting /bin/touch /tmp/foo...
378 Dec
08 20:
44:
48 container systemd[
1]: Started /bin/touch /tmp/foo.
</programlisting>
380 <para>The following command invokes
<filename>/bin/bash
</filename>
381 as a service passing its standard input, output and error to
382 the calling TTY.
</para>
384 <programlisting># systemd-run -t /bin/bash
</programlisting>
389 <title>See Also
</title>
391 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
392 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
393 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
394 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
395 <citerefentry><refentrytitle>systemd.scope
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
396 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
397 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
398 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
399 <citerefentry><refentrytitle>systemd.timer
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
400 <citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>