chiark / gitweb /
run: add a new "-t" mode for invoking a binary on an allocated TTY
[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 an interactive
236         command shells.</para></listitem>
237       </varlistentry>
238
239       <varlistentry>
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>
245
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>
255         </listitem>
256       </varlistentry>
257
258       <varlistentry>
259         <term><option>--on-calendar=</option></term>
260
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>
267         </listitem>
268       </varlistentry>
269
270       <varlistentry>
271         <term><option>--timer-property=</option></term>
272
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
282         the same format as
283         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
284         <command>set-property</command> command.</para> </listitem>
285       </varlistentry>
286
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" />
291
292       <xi:include href="standard-options.xml" xpointer="help" />
293       <xi:include href="standard-options.xml" xpointer="version" />
294     </variablelist>
295
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>
300   </refsect1>
301
302   <refsect1>
303     <title>Exit status</title>
304
305     <para>On success, 0 is returned, a non-zero failure
306     code otherwise.</para>
307   </refsect1>
308
309   <refsect1>
310     <title>Examples</title>
311
312     <para>The following command will log the environment variables
313     provided by systemd to services:</para>
314
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>
323
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>
329     property.</para>
330
331     <programlisting># systemd-run -p BlockIOWeight=10 updatedb</programlisting>
332
333     <para>The following command will touch a file after 30 seconds.</para>
334
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>
347
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>
351
352     <programlisting># systemd-run -t /bin/bash</programlisting>
353
354   </refsect1>
355
356   <refsect1>
357     <title>See Also</title>
358     <para>
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>
369     </para>
370   </refsect1>
371
372 </refentry>