1 <?xml version='1.0'?> <!--*-nxml-*-->
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 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>
62 <title>Description</title>
64 <para><command>systemd-run</command> may be used to create and start
65 a transient <filename>.service</filename> or a
66 <filename>.scope</filename> unit and run the specified
67 <replaceable>COMMAND</replaceable> in it.</para>
69 <para>If a command is run as transient service unit, it will be
70 started and managed by the service manager like any other service,
71 and thus show up in the output of <command>systemctl
72 list-units</command> like any other unit. It will run in a clean
73 and detached execution environment. <command>systemd-run</command>
74 will start the service asynchronously in the background and
75 immediately return.</para>
77 <para>If a command is run as transient scope unit, it will be
78 started directly by <command>systemd-run</command> and thus
79 inherit the execution environment of the caller. It is however
80 managed by the service manager similar to normal services, and
81 will also show up in the output of <command>systemctl
82 list-units</command>. Execution in this case is synchronous, and
83 execution will return only when the command finishes.</para>
87 <title>Options</title>
89 <para>The following options are understood:</para>
93 <term><option>--scope</option></term>
96 <para>Create a transient <filename>.scope</filename> unit instead of
97 the default transient <filename>.service</filename> unit.
103 <term><option>--unit=</option></term>
105 <listitem><para>Use this unit name instead of an automatically
106 generated one.</para></listitem>
110 <term><option>--property=</option></term>
111 <term><option>-p</option></term>
113 <listitem><para>Sets a unit property for the scope or service
114 unit that is created. This takes an assignment in the same
116 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
117 <command>set-property</command> command.</para>
122 <term><option>--description=</option></term>
124 <listitem><para>Provide description for the service or scope
125 unit. If not specified, the command itself will be used as a
126 description. See <varname>Description=</varname> in
127 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
132 <term><option>--slice=</option></term>
134 <listitem><para>Make the new <filename>.service</filename> or
135 <filename>.scope</filename> unit part of the specified slice,
136 instead of the <filename>system.slice</filename>.</para>
141 <term><option>--remain-after-exit</option></term>
143 <listitem><para>After the service or scope process has
144 terminated, keep the service around until it is explicitly
145 stopped. This is useful to collect runtime information about
146 the service after it finished running. Also see
147 <varname>RemainAfterExit=</varname> in
148 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
154 <term><option>--send-sighup</option></term>
156 <listitem><para>When terminating the scope or service unit,
157 send a SIGHUP immediately after SIGTERM. This is useful to
158 indicate to shells and shell-like processes that the
159 connection has been severed. Also see
160 <varname>SendSIGHUP=</varname> in
161 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
167 <term><option>--service-type=</option></term>
169 <listitem><para>Sets the service type. Also see
170 <varname>Type=</varname> in
171 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
172 option has no effect in conjunction with
173 <option>--scope</option>. Defaults to
174 <constant>simple</constant>.</para>
179 <term><option>--uid=</option></term>
180 <term><option>--gid=</option></term>
182 <listitem><para>Runs the service process under the UNIX user
183 and group. Also see <varname>User=</varname> and
184 <varname>Group=</varname> in
185 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
186 option has no effect in conjunction with
187 <option>--scope</option>.</para>
192 <term><option>--nice=</option></term>
194 <listitem><para>Runs the service process with the specified
195 nice level. Also see <varname>Nice=</varname> in
196 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
197 option has no effect in conjunction with
198 <option>--scope</option>.</para>
203 <term><option>--setenv=</option></term>
205 <listitem><para>Runs the service process with the specified
206 environment variables set. Also see
207 <varname>Environment=</varname> in
208 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
209 option has no effect in conjunction with
210 <option>--scope</option>.</para>
214 <xi:include href="user-system-options.xml" xpointer="user" />
215 <xi:include href="user-system-options.xml" xpointer="system" />
216 <xi:include href="user-system-options.xml" xpointer="host" />
217 <xi:include href="user-system-options.xml" xpointer="machine" />
219 <xi:include href="standard-options.xml" xpointer="help" />
220 <xi:include href="standard-options.xml" xpointer="version" />
223 <para>All command-line arguments after the first non-option
224 argument become part of the commandline of the launched
225 process. If a command is run as service unit, its first argument
226 needs to be an absolute binary path.</para>
230 <title>Exit status</title>
232 <para>On success, 0 is returned, a non-zero failure
233 code otherwise.</para>
237 <title>Examples</title>
239 <para>The following command will log the environment variables
240 provided by systemd to services:</para>
242 <programlisting># systemd-run env
243 Running as unit run-19945.service.
244 # journalctl -u run-19945.service
245 Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env...
246 Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env.
247 Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
248 Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8
249 Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting>
251 <para>The following command invokes the
252 <citerefentry><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry>
253 tool but lowers the block IO weight for it to 10. See
254 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
255 for more information on the <varname>BlockIOWeight=</varname>
258 <programlisting># systemd-run -p BlockIOWeight=10 updatedb</programlisting>
262 <title>See Also</title>
264 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
265 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
266 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
267 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
268 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
269 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
270 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
271 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
272 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>