chiark / gitweb /
NEWS: prepare NEWS for new release
[elogind.git] / man / systemd-run.xml
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">
4
5 <!--
6 This file is part of systemd.
7
8 Copyright 2013 Zbigniew JÄ™drzejewski-Szmek
9
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.
14
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.
19
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/>.
22 -->
23
24 <refentry id="systemd-run"
25           xmlns:xi="http://www.w3.org/2001/XInclude">
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>
48     <refpurpose>Run programs in transient scope or service or timer units</refpurpose>
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>
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>
66   </refsynopsisdiv>
67
68   <refsect1>
69     <title>Description</title>
70
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
75     it.</para>
76
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>
84
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>
96
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>
104   </refsect1>
105
106   <refsect1>
107     <title>Options</title>
108
109     <para>The following options are understood:</para>
110
111     <variablelist>
112       <varlistentry>
113         <term><option>--scope</option></term>
114
115         <listitem>
116           <para>Create a transient <filename>.scope</filename> unit instead of
117           the default transient <filename>.service</filename> unit.
118           </para>
119         </listitem>
120       </varlistentry>
121
122       <varlistentry>
123         <term><option>--unit=</option></term>
124
125         <listitem><para>Use this unit name instead of an automatically
126         generated one.</para></listitem>
127       </varlistentry>
128
129       <varlistentry>
130         <term><option>--property=</option></term>
131         <term><option>-p</option></term>
132
133         <listitem><para>Sets a unit property for the scope or service
134         unit that is created. This takes an assignment in the same
135         format as
136         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
137         <command>set-property</command> command.</para>
138         </listitem>
139       </varlistentry>
140
141       <varlistentry>
142         <term><option>--description=</option></term>
143
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>.
148         </para></listitem>
149       </varlistentry>
150
151       <varlistentry>
152         <term><option>--slice=</option></term>
153
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>
157         </listitem>
158       </varlistentry>
159
160       <varlistentry>
161         <term><option>--remain-after-exit</option></term>
162
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>.
169         </para>
170         </listitem>
171       </varlistentry>
172
173       <varlistentry>
174         <term><option>--send-sighup</option></term>
175
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>.
182         </para>
183         </listitem>
184       </varlistentry>
185
186       <varlistentry>
187         <term><option>--service-type=</option></term>
188
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>
195         </listitem>
196       </varlistentry>
197
198       <varlistentry>
199         <term><option>--uid=</option></term>
200         <term><option>--gid=</option></term>
201
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>
206         </listitem>
207       </varlistentry>
208
209       <varlistentry>
210         <term><option>--nice=</option></term>
211
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>
215         </listitem>
216       </varlistentry>
217
218       <varlistentry>
219         <term><option>--setenv=</option></term>
220
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>
225         </listitem>
226       </varlistentry>
227
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" />
232
233       <varlistentry>
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>
239
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>
249         </listitem>
250       </varlistentry>
251
252       <varlistentry>
253         <term><option>--on-calendar=</option></term>
254
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>
261         </listitem>
262       </varlistentry>
263
264       <varlistentry>
265         <term><option>--timer-property=</option></term>
266
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
276         the same format as
277         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
278         <command>set-property</command> command.</para> </listitem>
279       </varlistentry>
280
281       <xi:include href="standard-options.xml" xpointer="help" />
282       <xi:include href="standard-options.xml" xpointer="version" />
283     </variablelist>
284
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>
289   </refsect1>
290
291   <refsect1>
292     <title>Exit status</title>
293
294     <para>On success, 0 is returned, a non-zero failure
295     code otherwise.</para>
296   </refsect1>
297
298   <refsect1>
299     <title>Examples</title>
300
301     <para>The following command will log the environment variables
302     provided by systemd to services:</para>
303
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>
312
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>
318     property.</para>
319
320     <programlisting># systemd-run -p BlockIOWeight=10 updatedb</programlisting>
321
322     <para>The following command will touch a file after 30 seconds.</para>
323
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>
336   </refsect1>
337
338   <refsect1>
339     <title>See Also</title>
340     <para>
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>
351     </para>
352   </refsect1>
353
354 </refentry>