chiark / gitweb /
update TODO
[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       <varlistentry>
229         <term><option>--pty</option></term>
230         <term><option>-t</option></term>
231
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 interactive
236         command shells.</para></listitem>
237       </varlistentry>
238
239       <varlistentry>
240         <term><option>--quiet</option></term>
241         <term><option>-q</option></term>
242
243         <listitem><para>Suppresses additional informational output
244         while running. This is particularly useful in combination with
245         <option>--pty</option> when it will suppress the initial
246         message explaining how to terminate the TTY connection.</para></listitem>
247       </varlistentry>
248
249       <varlistentry>
250         <term><option>--on-active=</option></term>
251         <term><option>--on-boot=</option></term>
252         <term><option>--on-startup=</option></term>
253         <term><option>--on-unit-active=</option></term>
254         <term><option>--on-unit-inactive=</option></term>
255
256         <listitem><para>Defines monotonic timers relative to different
257         starting points. Also see <varname>OnActiveSec=</varname>,
258         <varname>OnBootSec=</varname>,
259         <varname>OnStartupSec=</varname>,
260         <varname>OnUnitActiveSec=</varname> and
261         <varname>OnUnitInactiveSec=</varname> in
262         <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
263         options have no effect in conjunction with
264         <option>--scope</option>.</para>
265         </listitem>
266       </varlistentry>
267
268       <varlistentry>
269         <term><option>--on-calendar=</option></term>
270
271         <listitem><para>Defines realtime (i.e. wallclock) timers with
272         calendar event expressions. Also see
273         <varname>OnCalendar=</varname> in
274         <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
275         option has no effect in conjunction with
276         <option>--scope</option>.</para>
277         </listitem>
278       </varlistentry>
279
280       <varlistentry>
281         <term><option>--timer-property=</option></term>
282
283         <listitem><para>Sets a timer unit property for the timer unit
284         that is created. It is similar with
285         <option>--property</option> but only for created timer
286         unit. This option only has effect in conjunction with
287         <option>--on-active=</option>, <option>--on-boot=</option>,
288         <option>--on-startup=</option>,
289         <option>--on-unit-active=</option>,
290         <option>--on-unit-inactive=</option>,
291         <option>--on-calendar=</option>. This takes an assignment in
292         the same format as
293         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
294         <command>set-property</command> command.</para> </listitem>
295       </varlistentry>
296
297       <xi:include href="user-system-options.xml" xpointer="user" />
298       <xi:include href="user-system-options.xml" xpointer="system" />
299       <xi:include href="user-system-options.xml" xpointer="host" />
300       <xi:include href="user-system-options.xml" xpointer="machine" />
301
302       <xi:include href="standard-options.xml" xpointer="help" />
303       <xi:include href="standard-options.xml" xpointer="version" />
304     </variablelist>
305
306     <para>All command line arguments after the first non-option
307     argument become part of the command line of the launched
308     process. If a command is run as service unit, its first argument
309     needs to be an absolute binary path.</para>
310   </refsect1>
311
312   <refsect1>
313     <title>Exit status</title>
314
315     <para>On success, 0 is returned, a non-zero failure
316     code otherwise.</para>
317   </refsect1>
318
319   <refsect1>
320     <title>Examples</title>
321
322     <para>The following command will log the environment variables
323     provided by systemd to services:</para>
324
325     <programlisting># systemd-run env
326 Running as unit run-19945.service.
327 # journalctl -u run-19945.service
328 Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env...
329 Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env.
330 Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
331 Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8
332 Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting>
333
334     <para>The following command invokes the
335     <citerefentry project='man-pages'><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry>
336     tool, but lowers the block IO weight for it to 10. See
337     <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
338     for more information on the <varname>BlockIOWeight=</varname>
339     property.</para>
340
341     <programlisting># systemd-run -p BlockIOWeight=10 updatedb</programlisting>
342
343     <para>The following command will touch a file after 30 seconds.</para>
344
345     <programlisting># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo
346 Mon Dec  8 20:44:24 KST 2014
347 Running as unit run-71.timer.
348 Will run as unit run-71.service.
349 # journalctl -b -u run-73.timer
350 -- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
351 Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo.
352 Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo.
353 # journalctl -b -u run-73.service
354 -- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
355 Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo...
356 Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</programlisting>
357
358     <para>The following command invokes <filename>/bin/bash</filename>
359     as a service passing its standard input, output and error to
360     the calling TTY.</para>
361
362     <programlisting># systemd-run -t /bin/bash</programlisting>
363
364   </refsect1>
365
366   <refsect1>
367     <title>See Also</title>
368     <para>
369       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
370       <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
371       <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
372       <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
373       <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
374       <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
375       <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
376       <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
377       <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
378       <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
379     </para>
380   </refsect1>
381
382 </refentry>