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>
228 <xi:include href="user-system-options.xml" xpointer="user" />
229 <xi:include href="user-system-options.xml" xpointer="system" />
230 <xi:include href="user-system-options.xml" xpointer="host" />
231 <xi:include href="user-system-options.xml" xpointer="machine" />
234 <term><option>--on-active=</option></term>
235 <term><option>--on-boot=</option></term>
236 <term><option>--on-startup=</option></term>
237 <term><option>--on-unit-active=</option></term>
238 <term><option>--on-unit-inactive=</option></term>
240 <listitem><para>Defines monotonic timers relative to different
241 starting points. Also see <varname>OnActiveSec=</varname>,
242 <varname>OnBootSec=</varname>,
243 <varname>OnStartupSec=</varname>,
244 <varname>OnUnitActiveSec=</varname> and
245 <varname>OnUnitInactiveSec=</varname> in
246 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
247 options have no effect in conjunction with
248 <option>--scope</option>.</para>
253 <term><option>--on-calendar=</option></term>
255 <listitem><para>Defines realtime (i.e. wallclock) timers with
256 calendar event expressions. Also see
257 <varname>OnCalendar=</varname> in
258 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
259 option has no effect in conjunction with
260 <option>--scope</option>.</para>
265 <term><option>--timer-property=</option></term>
267 <listitem><para>Sets a timer unit property for the timer unit
268 that is created. It is similar with
269 <option>--property</option> but only for created timer
270 unit. This option only has effect in conjunction with
271 <option>--on-active=</option>, <option>--on-boot=</option>,
272 <option>--on-startup=</option>,
273 <option>--on-unit-active=</option>,
274 <option>--on-unit-inactive=</option>,
275 <option>--on-calendar=</option>. This takes an assignment in
277 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
278 <command>set-property</command> command.</para> </listitem>
281 <xi:include href="standard-options.xml" xpointer="help" />
282 <xi:include href="standard-options.xml" xpointer="version" />
285 <para>All command line arguments after the first non-option
286 argument become part of the command line of the launched
287 process. If a command is run as service unit, its first argument
288 needs to be an absolute binary path.</para>
292 <title>Exit status</title>
294 <para>On success, 0 is returned, a non-zero failure
295 code otherwise.</para>
299 <title>Examples</title>
301 <para>The following command will log the environment variables
302 provided by systemd to services:</para>
304 <programlisting># systemd-run env
305 Running as unit run-19945.service.
306 # journalctl -u run-19945.service
307 Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env...
308 Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env.
309 Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
310 Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8
311 Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting>
313 <para>The following command invokes the
314 <citerefentry project='man-pages'><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry>
315 tool, but lowers the block IO weight for it to 10. See
316 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
317 for more information on the <varname>BlockIOWeight=</varname>
320 <programlisting># systemd-run -p BlockIOWeight=10 updatedb</programlisting>
322 <para>The following command will touch a file after 30 seconds.</para>
324 <programlisting># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo
325 Mon Dec 8 20:44:24 KST 2014
326 Running as unit run-71.timer.
327 Will run as unit run-71.service.
328 # journalctl -b -u run-73.timer
329 -- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
330 Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo.
331 Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo.
332 # journalctl -b -u run-73.service
333 -- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
334 Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo...
335 Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</programlisting>
339 <title>See Also</title>
341 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
342 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
343 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
344 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
345 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
346 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
347 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
348 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
349 <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
350 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>