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 a transient
73 <filename>.timer
</filename> or a
<filename>.scope
</filename> unit
74 and run the specified
<replaceable>COMMAND
</replaceable> in
77 <para>If a command is run as transient service unit, it will be
78 started and managed by the service manager like any other service,
79 and thus show up in the output of
<command>systemctl
80 list-units
</command> like any other unit. It will run in a clean
81 and detached execution environment.
<command>systemd-run
</command>
82 will start the service asynchronously in the background and
83 immediately return.
</para>
85 <para>If a command is run with timer options, transient timer unit
86 also be created with transient service unit. But the transient
87 timer unit is only started immediately. The transient service unit
88 will be started when the transient timer is elapsed. If
89 <option>--unit=
</option> is specified with timer options, the
90 <replaceable>COMMAND
</replaceable> can be omitted. In this case,
91 <command>systemd-run
</command> assumes service unit is already
92 loaded and creates transient timer unit only. To successfully
93 create timer unit, already loaded service unit should be specified
94 with
<option>--unit=
</option>. This transient timer unit can
95 activate the existing service unit like any other timer.
</para>
97 <para>If a command is run as transient scope unit, it will be
98 started directly by
<command>systemd-run
</command> and thus
99 inherit the execution environment of the caller. It is however
100 managed by the service manager similar to normal services, and
101 will also show up in the output of
<command>systemctl
102 list-units
</command>. Execution in this case is synchronous, and
103 execution will return only when the command finishes.
</para>
107 <title>Options
</title>
109 <para>The following options are understood:
</para>
113 <term><option>--scope
</option></term>
116 <para>Create a transient
<filename>.scope
</filename> unit instead of
117 the default transient
<filename>.service
</filename> unit.
123 <term><option>--unit=
</option></term>
125 <listitem><para>Use this unit name instead of an automatically
126 generated one.
</para></listitem>
130 <term><option>--property=
</option></term>
131 <term><option>-p
</option></term>
133 <listitem><para>Sets a unit property for the scope or service
134 unit that is created. This takes an assignment in the same
136 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
137 <command>set-property
</command> command.
</para>
142 <term><option>--description=
</option></term>
144 <listitem><para>Provide a description for the service or scope
145 unit. If not specified, the command itself will be used as a
146 description. See
<varname>Description=
</varname> in
147 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
152 <term><option>--slice=
</option></term>
154 <listitem><para>Make the new
<filename>.service
</filename> or
155 <filename>.scope
</filename> unit part of the specified slice,
156 instead of the
<filename>system.slice
</filename>.
</para>
161 <term><option>--remain-after-exit
</option></term>
163 <listitem><para>After the service or scope process has
164 terminated, keep the service around until it is explicitly
165 stopped. This is useful to collect runtime information about
166 the service after it finished running. Also see
167 <varname>RemainAfterExit=
</varname> in
168 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
174 <term><option>--send-sighup
</option></term>
176 <listitem><para>When terminating the scope or service unit,
177 send a SIGHUP immediately after SIGTERM. This is useful to
178 indicate to shells and shell-like processes that the
179 connection has been severed. Also see
180 <varname>SendSIGHUP=
</varname> in
181 <citerefentry><refentrytitle>systemd.kill
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
187 <term><option>--service-type=
</option></term>
189 <listitem><para>Sets the service type. Also see
190 <varname>Type=
</varname> in
191 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
192 option has no effect in conjunction with
193 <option>--scope
</option>. Defaults to
194 <constant>simple
</constant>.
</para>
199 <term><option>--uid=
</option></term>
200 <term><option>--gid=
</option></term>
202 <listitem><para>Runs the service process under the UNIX user
203 and group. Also see
<varname>User=
</varname> and
204 <varname>Group=
</varname> in
205 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
210 <term><option>--nice=
</option></term>
212 <listitem><para>Runs the service process with the specified
213 nice level. Also see
<varname>Nice=
</varname> in
214 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
219 <term><option>--setenv=
</option></term>
221 <listitem><para>Runs the service process with the specified
222 environment variables set. Also see
223 <varname>Environment=
</varname> in
224 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
229 <term><option>--pty
</option></term>
230 <term><option>-t
</option></term>
232 <listitem><para>When invoking a command as service connects
233 its standard input and output to the invoking tty via a
234 pseudo TTY device. This allows invoking binaries as services
235 that expect interactive user input, such as an interactive
236 command shells.
</para></listitem>
240 <term><option>--on-active=
</option></term>
241 <term><option>--on-boot=
</option></term>
242 <term><option>--on-startup=
</option></term>
243 <term><option>--on-unit-active=
</option></term>
244 <term><option>--on-unit-inactive=
</option></term>
246 <listitem><para>Defines monotonic timers relative to different
247 starting points. Also see
<varname>OnActiveSec=
</varname>,
248 <varname>OnBootSec=
</varname>,
249 <varname>OnStartupSec=
</varname>,
250 <varname>OnUnitActiveSec=
</varname> and
251 <varname>OnUnitInactiveSec=
</varname> in
252 <citerefentry><refentrytitle>systemd.timer
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
253 options have no effect in conjunction with
254 <option>--scope
</option>.
</para>
259 <term><option>--on-calendar=
</option></term>
261 <listitem><para>Defines realtime (i.e. wallclock) timers with
262 calendar event expressions. Also see
263 <varname>OnCalendar=
</varname> in
264 <citerefentry><refentrytitle>systemd.timer
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
265 option has no effect in conjunction with
266 <option>--scope
</option>.
</para>
271 <term><option>--timer-property=
</option></term>
273 <listitem><para>Sets a timer unit property for the timer unit
274 that is created. It is similar with
275 <option>--property
</option> but only for created timer
276 unit. This option only has effect in conjunction with
277 <option>--on-active=
</option>,
<option>--on-boot=
</option>,
278 <option>--on-startup=
</option>,
279 <option>--on-unit-active=
</option>,
280 <option>--on-unit-inactive=
</option>,
281 <option>--on-calendar=
</option>. This takes an assignment in
283 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
284 <command>set-property
</command> command.
</para> </listitem>
287 <xi:include href=
"user-system-options.xml" xpointer=
"user" />
288 <xi:include href=
"user-system-options.xml" xpointer=
"system" />
289 <xi:include href=
"user-system-options.xml" xpointer=
"host" />
290 <xi:include href=
"user-system-options.xml" xpointer=
"machine" />
292 <xi:include href=
"standard-options.xml" xpointer=
"help" />
293 <xi:include href=
"standard-options.xml" xpointer=
"version" />
296 <para>All command line arguments after the first non-option
297 argument become part of the command line of the launched
298 process. If a command is run as service unit, its first argument
299 needs to be an absolute binary path.
</para>
303 <title>Exit status
</title>
305 <para>On success,
0 is returned, a non-zero failure
306 code otherwise.
</para>
310 <title>Examples
</title>
312 <para>The following command will log the environment variables
313 provided by systemd to services:
</para>
315 <programlisting># systemd-run env
316 Running as unit run-
19945.service.
317 # journalctl -u run-
19945.service
318 Sep
08 07:
37:
21 bupkis systemd[
1]: Starting /usr/bin/env...
319 Sep
08 07:
37:
21 bupkis systemd[
1]: Started /usr/bin/env.
320 Sep
08 07:
37:
21 bupkis env[
19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
321 Sep
08 07:
37:
21 bupkis env[
19948]: LANG=en_US.UTF-
8
322 Sep
08 07:
37:
21 bupkis env[
19948]: BOOT_IMAGE=/vmlinuz-
3.11.0-
0.rc5.git6.2.fc20.x86_64
</programlisting>
324 <para>The following command invokes the
325 <citerefentry project='man-pages'
><refentrytitle>updatedb
</refentrytitle><manvolnum>8</manvolnum></citerefentry>
326 tool, but lowers the block IO weight for it to
10. See
327 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
328 for more information on the
<varname>BlockIOWeight=
</varname>
331 <programlisting># systemd-run -p BlockIOWeight=
10 updatedb
</programlisting>
333 <para>The following command will touch a file after
30 seconds.
</para>
335 <programlisting># date; systemd-run --on-active=
30 --timer-property=AccuracySec=
100ms /bin/touch /tmp/foo
336 Mon Dec
8 20:
44:
24 KST
2014
337 Running as unit run-
71.timer.
338 Will run as unit run-
71.service.
339 # journalctl -b -u run-
73.timer
340 -- Logs begin at Fri
2014-
12-
05 19:
09:
21 KST, end at Mon
2014-
12-
08 20:
44:
54 KST. --
341 Dec
08 20:
44:
38 container systemd[
1]: Starting /bin/touch /tmp/foo.
342 Dec
08 20:
44:
38 container systemd[
1]: Started /bin/touch /tmp/foo.
343 # journalctl -b -u run-
73.service
344 -- Logs begin at Fri
2014-
12-
05 19:
09:
21 KST, end at Mon
2014-
12-
08 20:
44:
54 KST. --
345 Dec
08 20:
44:
48 container systemd[
1]: Starting /bin/touch /tmp/foo...
346 Dec
08 20:
44:
48 container systemd[
1]: Started /bin/touch /tmp/foo.
</programlisting>
348 <para>The following command invokes
<filename>/bin/bash
</filename>
349 as a service passing its standard input, output and error to
350 the calling TTY.
</para>
352 <programlisting># systemd-run -t /bin/bash
</programlisting>
357 <title>See Also
</title>
359 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
360 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
361 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
362 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
363 <citerefentry><refentrytitle>systemd.scope
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
364 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
365 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
366 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
367 <citerefentry><refentrytitle>systemd.timer
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
368 <citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>