]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 ZJS |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
db9ecf05 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
f09114bc | 5 | |
dfdebb1b ZJS |
6 | <refentry id="systemd-run" |
7 | xmlns:xi="http://www.w3.org/2001/XInclude"> | |
f09114bc ZJS |
8 | |
9 | <refentryinfo> | |
10 | <title>systemd-run</title> | |
11 | <productname>systemd</productname> | |
f09114bc ZJS |
12 | </refentryinfo> |
13 | ||
14 | <refmeta> | |
15 | <refentrytitle>systemd-run</refentrytitle> | |
16 | <manvolnum>1</manvolnum> | |
17 | </refmeta> | |
18 | ||
19 | <refnamediv> | |
20 | <refname>systemd-run</refname> | |
624dd009 | 21 | <refpurpose>Run programs in transient scope units, service units, or path-, socket-, or timer-triggered service units</refpurpose> |
f09114bc ZJS |
22 | </refnamediv> |
23 | ||
24 | <refsynopsisdiv> | |
25 | <cmdsynopsis> | |
26 | <command>systemd-run</command> | |
27 | <arg choice="opt" rep="repeat">OPTIONS</arg> | |
28 | <arg choice="plain"><replaceable>COMMAND</replaceable> | |
29 | <arg choice="opt" rep="repeat">ARGS</arg> | |
30 | </arg> | |
31 | </cmdsynopsis> | |
624dd009 YW |
32 | <cmdsynopsis> |
33 | <command>systemd-run</command> | |
34 | <arg choice="opt" rep="repeat">OPTIONS</arg> | |
35 | <arg choice="opt" rep="repeat">PATH OPTIONS</arg> | |
36 | <arg choice="req"><replaceable>COMMAND</replaceable></arg> | |
37 | <arg choice="opt" rep="repeat">ARGS</arg> | |
38 | </cmdsynopsis> | |
39 | <cmdsynopsis> | |
40 | <command>systemd-run</command> | |
41 | <arg choice="opt" rep="repeat">OPTIONS</arg> | |
42 | <arg choice="opt" rep="repeat">SOCKET OPTIONS</arg> | |
43 | <arg choice="req"><replaceable>COMMAND</replaceable></arg> | |
44 | <arg choice="opt" rep="repeat">ARGS</arg> | |
45 | </cmdsynopsis> | |
4c213d6c WC |
46 | <cmdsynopsis> |
47 | <command>systemd-run</command> | |
48 | <arg choice="opt" rep="repeat">OPTIONS</arg> | |
49 | <arg choice="opt" rep="repeat">TIMER OPTIONS</arg> | |
50 | <arg choice="req"><replaceable>COMMAND</replaceable></arg> | |
51 | <arg choice="opt" rep="repeat">ARGS</arg> | |
52 | </cmdsynopsis> | |
f09114bc ZJS |
53 | </refsynopsisdiv> |
54 | ||
55 | <refsect1> | |
56 | <title>Description</title> | |
57 | ||
014c4c98 LP |
58 | <para><command>systemd-run</command> may be used to create and start a transient <filename>.service</filename> or |
59 | <filename>.scope</filename> unit and run the specified <replaceable>COMMAND</replaceable> in it. It may also be | |
624dd009 YW |
60 | used to create and start a transient <filename>.path</filename>, <filename>.socket</filename>, or |
61 | <filename>.timer</filename> unit, that activates a <filename>.service</filename> unit when elapsing.</para> | |
014c4c98 LP |
62 | |
63 | <para>If a command is run as transient service unit, it will be started and managed by the service manager like any | |
64 | other service, and thus shows up in the output of <command>systemctl list-units</command> like any other unit. It | |
65 | will run in a clean and detached execution environment, with the service manager as its parent process. In this | |
66 | mode, <command>systemd-run</command> will start the service asynchronously in the background and return after the | |
b03ec009 | 67 | command has begun execution (unless <option>--no-block</option> or <option>--wait</option> are specified, see |
014c4c98 LP |
68 | below).</para> |
69 | ||
15102ced ZJS |
70 | <para>If a command is run as transient scope unit, it will be executed by <command>systemd-run</command> |
71 | itself as parent process and will thus inherit the execution environment of the caller. However, the | |
72 | processes of the command are managed by the service manager similarly to normal services, and will show | |
73 | up in the output of <command>systemctl list-units</command>. Execution in this case is synchronous, and | |
74 | will return only when the command finishes. This mode is enabled via the <option>--scope</option> switch | |
6a6707ce | 75 | (see below).</para> |
014c4c98 | 76 | |
624dd009 YW |
77 | <para>If a command is run with path, socket, or timer options such as <option>--on-calendar=</option> (see below), |
78 | a transient path, socket, or timer unit is created alongside the service unit for the specified command. Only the | |
79 | transient path, socket, or timer unit is started immediately, the transient service unit will be triggered by the | |
80 | path, socket, or timer unit. If the <option>--unit=</option> option is specified, the | |
81 | <replaceable>COMMAND</replaceable> may be omitted. In this case, <command>systemd-run</command> creates only a | |
82 | <filename>.path</filename>, <filename>.socket</filename>, or <filename>.timer</filename> unit that triggers the | |
83 | specified unit.</para> | |
79905a24 | 84 | |
6a6707ce ZJS |
85 | <para>By default, services created with <command>systemd-run</command> default to the |
86 | <option>simple</option> type, see the description of <varname>Type=</varname> in | |
79905a24 | 87 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
6a6707ce ZJS |
88 | details. Note that when this type is used, the service manager (and thus the |
89 | <command>systemd-run</command> command) considers service start-up successful as soon as the | |
90 | <function>fork()</function> for the main service process succeeded, i.e. before the | |
91 | <function>execve()</function> is invoked, and thus even if the specified command cannot be started. | |
92 | Consider using the <option>exec</option> service type (i.e. <option>--property=Type=exec</option>) to | |
93 | ensure that <command>systemd-run</command> returns successfully only if the specified command line has | |
94 | been successfully started.</para> | |
f09114bc ZJS |
95 | </refsect1> |
96 | ||
97 | <refsect1> | |
98 | <title>Options</title> | |
99 | ||
100 | <para>The following options are understood:</para> | |
101 | ||
102 | <variablelist> | |
8c7db2fb EV |
103 | <varlistentry> |
104 | <term><option>--no-ask-password</option></term> | |
105 | ||
106 | <listitem><para>Do not query the user for authentication for | |
107 | privileged operations.</para></listitem> | |
108 | </varlistentry> | |
109 | ||
f09114bc ZJS |
110 | <varlistentry> |
111 | <term><option>--scope</option></term> | |
112 | ||
113 | <listitem> | |
014c4c98 LP |
114 | <para>Create a transient <filename>.scope</filename> unit instead of the default transient |
115 | <filename>.service</filename> unit (see above). | |
f09114bc ZJS |
116 | </para> |
117 | </listitem> | |
118 | </varlistentry> | |
119 | ||
120 | <varlistentry> | |
121 | <term><option>--unit=</option></term> | |
7976b9f0 | 122 | <term><option>-u</option></term> |
f09114bc ZJS |
123 | |
124 | <listitem><para>Use this unit name instead of an automatically | |
125 | generated one.</para></listitem> | |
126 | </varlistentry> | |
127 | ||
df31a6c0 LP |
128 | <varlistentry> |
129 | <term><option>--property=</option></term> | |
130 | <term><option>-p</option></term> | |
131 | ||
014c4c98 LP |
132 | <listitem><para>Sets a property on the scope or service unit that is created. This option takes an assignment |
133 | in the same format as | |
df31a6c0 LP |
134 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
135 | <command>set-property</command> command.</para> | |
136 | </listitem> | |
137 | </varlistentry> | |
138 | ||
f09114bc ZJS |
139 | <varlistentry> |
140 | <term><option>--description=</option></term> | |
141 | ||
624dd009 YW |
142 | <listitem><para>Provide a description for the service, scope, path, socket, or timer unit. If not specified, |
143 | the command itself will be used as a description. See <varname>Description=</varname> in | |
f09114bc ZJS |
144 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
145 | </para></listitem> | |
146 | </varlistentry> | |
147 | ||
148 | <varlistentry> | |
149 | <term><option>--slice=</option></term> | |
150 | ||
ba455349 LP |
151 | <listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part |
152 | of the specified slice, instead of <filename>system.slice</filename> (when running in | |
153 | <option>--system</option> mode) or the root slice (when running in <option>--user</option> | |
154 | mode).</para> | |
f09114bc ZJS |
155 | </listitem> |
156 | </varlistentry> | |
6577c7ce | 157 | |
2c7039b3 MAL |
158 | <varlistentry> |
159 | <term><option>--slice-inherit</option></term> | |
160 | ||
161 | <listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part | |
162 | of the inherited slice. This option can be combined with <option>--slice=</option>.</para> | |
163 | ||
164 | <para>An inherited slice is located within <command>systemd-run</command> slice. Example: if | |
165 | <command>systemd-run</command> slice is <filename>foo.slice</filename>, and the | |
166 | <option>--slice=</option> argument is <filename>bar</filename>, the unit will be placed under the | |
167 | <filename>foo-bar.slice</filename>.</para> | |
168 | ||
169 | </listitem> | |
170 | </varlistentry> | |
171 | ||
6577c7ce | 172 | <varlistentry> |
a953b31a | 173 | <term><option>-r</option></term> |
6577c7ce LP |
174 | <term><option>--remain-after-exit</option></term> |
175 | ||
014c4c98 LP |
176 | <listitem><para>After the service process has terminated, keep the service around until it is explicitly |
177 | stopped. This is useful to collect runtime information about the service after it finished running. Also see | |
6577c7ce LP |
178 | <varname>RemainAfterExit=</varname> in |
179 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. | |
180 | </para> | |
181 | </listitem> | |
182 | </varlistentry> | |
a6c0353b LP |
183 | |
184 | <varlistentry> | |
185 | <term><option>--send-sighup</option></term> | |
186 | ||
014c4c98 LP |
187 | <listitem><para>When terminating the scope or service unit, send a SIGHUP immediately after SIGTERM. This is |
188 | useful to indicate to shells and shell-like processes that the connection has been severed. Also see | |
981ee551 | 189 | <varname>SendSIGHUP=</varname> in |
a6c0353b LP |
190 | <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
191 | </para> | |
192 | </listitem> | |
193 | </varlistentry> | |
dfdebb1b | 194 | |
981ee551 LP |
195 | <varlistentry> |
196 | <term><option>--service-type=</option></term> | |
197 | ||
198 | <listitem><para>Sets the service type. Also see | |
199 | <varname>Type=</varname> in | |
200 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This | |
201 | option has no effect in conjunction with | |
202 | <option>--scope</option>. Defaults to | |
203 | <constant>simple</constant>.</para> | |
204 | </listitem> | |
205 | </varlistentry> | |
206 | ||
207 | <varlistentry> | |
208 | <term><option>--uid=</option></term> | |
209 | <term><option>--gid=</option></term> | |
210 | ||
014c4c98 LP |
211 | <listitem><para>Runs the service process under the specified UNIX user and group. Also see |
212 | <varname>User=</varname> and <varname>Group=</varname> in | |
4de33e7f | 213 | <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
981ee551 LP |
214 | </listitem> |
215 | </varlistentry> | |
216 | ||
217 | <varlistentry> | |
218 | <term><option>--nice=</option></term> | |
219 | ||
220 | <listitem><para>Runs the service process with the specified | |
221 | nice level. Also see <varname>Nice=</varname> in | |
4de33e7f | 222 | <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
981ee551 | 223 | </listitem> |
2d21165a LP |
224 | </varlistentry> |
225 | ||
226 | <varlistentry> | |
227 | <term><option>--working-directory=</option></term> | |
228 | ||
229 | <listitem><para>Runs the service process with the specified working directory. Also see | |
230 | <varname>WorkingDirectory=</varname> in | |
231 | <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> | |
232 | </listitem> | |
233 | </varlistentry> | |
234 | ||
235 | <varlistentry> | |
236 | <term><option>--same-dir</option></term> | |
237 | <term><option>-d</option></term> | |
238 | ||
15102ced ZJS |
239 | <listitem><para>Similar to <option>--working-directory=</option>, but uses the current working |
240 | directory of the caller for the service to execute.</para></listitem> | |
981ee551 LP |
241 | </varlistentry> |
242 | ||
243 | <varlistentry> | |
0337b3d5 ZJS |
244 | <term><option>-E <replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term> |
245 | <term><option>--setenv=<replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term> | |
981ee551 | 246 | |
0337b3d5 ZJS |
247 | <listitem><para>Runs the service process with the specified environment variable set. This parameter |
248 | may be used more than once to set multiple variables. When <literal>=</literal> and | |
249 | <replaceable>VALUE</replaceable> are omitted, the value of the variable with the same name in the | |
250 | program environment will be used.</para> | |
251 | ||
252 | <para>Also see <varname>Environment=</varname> in | |
4de33e7f | 253 | <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
981ee551 LP |
254 | </listitem> |
255 | </varlistentry> | |
256 | ||
9b15b784 LP |
257 | <varlistentry> |
258 | <term><option>--pty</option></term> | |
259 | <term><option>-t</option></term> | |
260 | ||
5dca7739 LP |
261 | <listitem><para>When invoking the command, the transient service connects its standard input, output and error |
262 | to the terminal <command>systemd-run</command> is invoked on, via a pseudo TTY device. This allows running | |
156d6036 | 263 | programs that expect interactive user input/output as services, such as interactive command shells.</para> |
7f129a1f LP |
264 | |
265 | <para>Note that | |
266 | <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s | |
267 | <command>shell</command> command is usually a better alternative for requesting a new, interactive login | |
5dca7739 LP |
268 | session on the local host or a local container.</para> |
269 | ||
270 | <para>See below for details on how this switch combines with <option>--pipe</option>.</para></listitem> | |
271 | </varlistentry> | |
272 | ||
273 | <varlistentry> | |
274 | <term><option>--pipe</option></term> | |
275 | <term><option>-P</option></term> | |
276 | ||
277 | <listitem><para>If specified, standard input, output, and error of the transient service are inherited from the | |
156d6036 ZJS |
278 | <command>systemd-run</command> command itself. This allows <command>systemd-run</command> |
279 | to be used within shell pipelines. | |
280 | Note that this mode is not suitable for interactive command shells and similar, as the | |
960d20e1 | 281 | service process will not become a TTY controller when invoked on a terminal. Use <option>--pty</option> instead |
5dca7739 LP |
282 | in that case.</para> |
283 | ||
284 | <para>When both <option>--pipe</option> and <option>--pty</option> are used in combination the more appropriate | |
285 | option is automatically determined and used. Specifically, when invoked with standard input, output and error | |
b0e8cec2 LP |
286 | connected to a TTY <option>--pty</option> is used, and otherwise <option>--pipe</option>.</para> |
287 | ||
288 | <para>When this option is used the original file descriptors <command>systemd-run</command> receives are passed | |
289 | to the service processes as-is. If the service runs with different privileges than | |
290 | <command>systemd-run</command>, this means the service might not be able to re-open the passed file | |
291 | descriptors, due to normal file descriptor access restrictions. If the invoked process is a shell script that | |
7a17e41d | 292 | uses the <command>echo "hello" >/dev/stderr</command> construct for writing messages to stderr, this might |
b0e8cec2 LP |
293 | cause problems, as this only works if stderr can be re-opened. To mitigate this use the construct <command>echo |
294 | "hello" >&2</command> instead, which is mostly equivalent and avoids this pitfall.</para></listitem> | |
9b15b784 | 295 | </varlistentry> |
88ae7333 | 296 | |
badd28e1 LP |
297 | <varlistentry> |
298 | <term><option>--shell</option></term> | |
299 | <term><option>-S</option></term> | |
300 | ||
301 | <listitem><para>A shortcut for <literal>--pty --same-dir --wait --collect --service-type=exec $SHELL</literal>, | |
302 | i.e. requests an interactive shell in the current working directory, running in service context, accessible | |
303 | with a single switch.</para></listitem> | |
304 | </varlistentry> | |
305 | ||
095dc596 LP |
306 | <varlistentry> |
307 | <term><option>--quiet</option></term> | |
308 | <term><option>-q</option></term> | |
309 | ||
310 | <listitem><para>Suppresses additional informational output | |
311 | while running. This is particularly useful in combination with | |
312 | <option>--pty</option> when it will suppress the initial | |
313 | message explaining how to terminate the TTY connection.</para></listitem> | |
314 | </varlistentry> | |
315 | ||
4c213d6c WC |
316 | <varlistentry> |
317 | <term><option>--on-active=</option></term> | |
318 | <term><option>--on-boot=</option></term> | |
319 | <term><option>--on-startup=</option></term> | |
320 | <term><option>--on-unit-active=</option></term> | |
321 | <term><option>--on-unit-inactive=</option></term> | |
322 | ||
014c4c98 LP |
323 | <listitem><para>Defines a monotonic timer relative to different starting points for starting the specified |
324 | command. See <varname>OnActiveSec=</varname>, <varname>OnBootSec=</varname>, <varname>OnStartupSec=</varname>, | |
325 | <varname>OnUnitActiveSec=</varname> and <varname>OnUnitInactiveSec=</varname> in | |
326 | <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry> for | |
624dd009 YW |
327 | details. These options are shortcuts for <command>--timer-property=</command> with the relevant properties. |
328 | These options may not be combined with <option>--scope</option> or <option>--pty</option>.</para> | |
4c213d6c WC |
329 | </listitem> |
330 | </varlistentry> | |
331 | ||
332 | <varlistentry> | |
333 | <term><option>--on-calendar=</option></term> | |
334 | ||
014c4c98 LP |
335 | <listitem><para>Defines a calendar timer for starting the specified command. See <varname>OnCalendar=</varname> |
336 | in <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This | |
624dd009 YW |
337 | option is a shortcut for <command>--timer-property=OnCalendar=</command>. This option may not be combined with |
338 | <option>--scope</option> or <option>--pty</option>.</para> | |
4c213d6c WC |
339 | </listitem> |
340 | </varlistentry> | |
341 | ||
d9b8c2ef LP |
342 | <varlistentry> |
343 | <term><option>--on-clock-change</option></term> | |
344 | <term><option>--on-timezone-change</option></term> | |
345 | ||
346 | <listitem><para>Defines a trigger based on system clock jumps or timezone changes for starting the | |
347 | specified command. See <varname>OnClockChange=</varname> and <varname>OnTimezoneChange=</varname> in | |
348 | <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. These | |
349 | options are shortcuts for <command>--timer-property=OnClockChange=yes</command> and | |
350 | <command>--timer-property=OnTimezoneChange=yes</command>. These options may not be combined with | |
351 | <option>--scope</option> or <option>--pty</option>.</para></listitem> | |
352 | </varlistentry> | |
353 | ||
4c213d6c | 354 | <varlistentry> |
624dd009 YW |
355 | <term><option>--path-property=</option></term> |
356 | <term><option>--socket-property=</option></term> | |
4c213d6c WC |
357 | <term><option>--timer-property=</option></term> |
358 | ||
15102ced ZJS |
359 | <listitem><para>Sets a property on the path, socket, or timer unit that is created. This option is |
360 | similar to <option>--property=</option>, but applies to the transient path, socket, or timer unit | |
361 | rather than the transient service unit created. This option takes an assignment in the same format as | |
624dd009 YW |
362 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
363 | <command>set-property</command> command. These options may not be combined with | |
364 | <option>--scope</option> or <option>--pty</option>.</para> | |
365 | </listitem> | |
4c213d6c WC |
366 | </varlistentry> |
367 | ||
3d161f99 LP |
368 | <varlistentry> |
369 | <term><option>--no-block</option></term> | |
370 | ||
371 | <listitem> | |
014c4c98 LP |
372 | <para>Do not synchronously wait for the unit start operation to finish. If this option is not specified, the |
373 | start request for the transient unit will be verified, enqueued and <command>systemd-run</command> will wait | |
374 | until the unit's start-up is completed. By passing this argument, it is only verified and enqueued. This | |
375 | option may not be combined with <option>--wait</option>.</para> | |
3d161f99 LP |
376 | </listitem> |
377 | </varlistentry> | |
378 | ||
014c4c98 LP |
379 | <varlistentry> |
380 | <term><option>--wait</option></term> | |
381 | ||
382 | <listitem><para>Synchronously wait for the transient service to terminate. If this option is specified, the | |
383 | start request for the transient unit is verified, enqueued, and waited for. Subsequently the invoked unit is | |
384 | monitored, and it is waited until it is deactivated again (most likely because the specified command | |
385 | completed). On exit, terse information about the unit's runtime is shown, including total runtime (as well as | |
386 | CPU usage, if <option>--property=CPUAccounting=1</option> was set) and the exit code and status of the main | |
387 | process. This output may be suppressed with <option>--quiet</option>. This option may not be combined with | |
624dd009 | 388 | <option>--no-block</option>, <option>--scope</option> or the various path, socket, or timer options.</para></listitem> |
014c4c98 LP |
389 | </varlistentry> |
390 | ||
fe9d0be9 LP |
391 | <varlistentry> |
392 | <term><option>-G</option></term> | |
393 | <term><option>--collect</option></term> | |
394 | ||
395 | <listitem><para>Unload the transient unit after it completed, even if it failed. Normally, without this option, | |
396 | all units that ran and failed are kept in memory until the user explicitly resets their failure state with | |
397 | <command>systemctl reset-failed</command> or an equivalent command. On the other hand, units that ran | |
398 | successfully are unloaded immediately. If this option is turned on the "garbage collection" of units is more | |
399 | aggressive, and unloads units regardless if they exited successfully or failed. This option is a shortcut for | |
400 | <command>--property=CollectMode=inactive-or-failed</command>, see the explanation for | |
401 | <varname>CollectMode=</varname> in | |
402 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for further | |
403 | information.</para></listitem> | |
404 | </varlistentry> | |
405 | ||
9b15b784 LP |
406 | <xi:include href="user-system-options.xml" xpointer="user" /> |
407 | <xi:include href="user-system-options.xml" xpointer="system" /> | |
408 | <xi:include href="user-system-options.xml" xpointer="host" /> | |
409 | <xi:include href="user-system-options.xml" xpointer="machine" /> | |
410 | ||
dfdebb1b ZJS |
411 | <xi:include href="standard-options.xml" xpointer="help" /> |
412 | <xi:include href="standard-options.xml" xpointer="version" /> | |
f09114bc ZJS |
413 | </variablelist> |
414 | ||
6a6707ce ZJS |
415 | <para>All command line arguments after the first non-option argument become part of the command line of |
416 | the launched process.</para> | |
f09114bc ZJS |
417 | </refsect1> |
418 | ||
419 | <refsect1> | |
420 | <title>Exit status</title> | |
421 | ||
7f3614e5 ZJS |
422 | <para>On success, 0 is returned. If <command>systemd-run</command> failed to start the service, a |
423 | non-zero return value will be returned. If <command>systemd-run</command> waits for the service to | |
424 | terminate, the return value will be propagated from the service. 0 will be returned on success, including | |
425 | all the cases where systemd considers a service to have exited cleanly, see the discussion of | |
426 | <varname>SuccessExitStatus=</varname> in | |
427 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. | |
428 | </para> | |
f09114bc ZJS |
429 | </refsect1> |
430 | ||
c9d954b2 | 431 | <refsect1> |
df31a6c0 | 432 | <title>Examples</title> |
c9d954b2 | 433 | |
4eac7f5c ZJS |
434 | <example> |
435 | <title>Logging environment variables provided by systemd to services</title> | |
c9d954b2 | 436 | |
4eac7f5c | 437 | <programlisting># systemd-run env |
f3ea87af | 438 | Running as unit: run-19945.service |
c9d954b2 ZJS |
439 | # journalctl -u run-19945.service |
440 | Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env... | |
441 | Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env. | |
442 | Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin | |
443 | Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8 | |
9fccdb0f | 444 | Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting> |
4eac7f5c | 445 | </example> |
df31a6c0 | 446 | |
4eac7f5c ZJS |
447 | <example> |
448 | <title>Limiting resources available to a command</title> | |
df31a6c0 | 449 | |
6d48c7cf | 450 | <programlisting># systemd-run -p IOWeight=10 updatedb</programlisting> |
4c213d6c | 451 | |
6d48c7cf LP |
452 | <para>This command invokes the <citerefentry |
453 | project='man-pages'><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry> | |
4eac7f5c ZJS |
454 | tool, but lowers the block I/O weight for it to 10. See |
455 | <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
6d48c7cf | 456 | for more information on the <varname>IOWeight=</varname> property.</para> |
4eac7f5c | 457 | </example> |
4c213d6c | 458 | |
4eac7f5c ZJS |
459 | <example> |
460 | <title>Running commands at a specified time</title> | |
461 | ||
462 | <para>The following command will touch a file after 30 seconds.</para> | |
463 | ||
464 | <programlisting># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo | |
4c213d6c | 465 | Mon Dec 8 20:44:24 KST 2014 |
f3ea87af ILG |
466 | Running as unit: run-71.timer |
467 | Will run service as unit: run-71.service | |
85fb8031 | 468 | # journalctl -b -u run-71.timer |
b91ae210 | 469 | -- Journal begins at Fri 2014-12-05 19:09:21 KST, ends at Mon 2014-12-08 20:44:54 KST. -- |
4c213d6c WC |
470 | Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo. |
471 | Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo. | |
85fb8031 | 472 | # journalctl -b -u run-71.service |
b91ae210 | 473 | -- Journal begins at Fri 2014-12-05 19:09:21 KST, ends at Mon 2014-12-08 20:44:54 KST. -- |
4c213d6c WC |
474 | Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo... |
475 | Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</programlisting> | |
4eac7f5c | 476 | </example> |
9b15b784 | 477 | |
4eac7f5c ZJS |
478 | <example> |
479 | <title>Allowing access to the tty</title> | |
9b15b784 | 480 | |
a3e03a3f | 481 | <para>The following command invokes <citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
1e8c094c | 482 | as a service passing its standard input, output and error to the calling TTY.</para> |
9b15b784 | 483 | |
1e8c094c | 484 | <programlisting># systemd-run -t --send-sighup bash</programlisting> |
4eac7f5c | 485 | </example> |
65eb37f8 ZJS |
486 | |
487 | <example> | |
488 | <title>Start <command>screen</command> as a user service</title> | |
489 | ||
490 | <programlisting>$ systemd-run --scope --user screen | |
491 | Running scope as unit run-r14b0047ab6df45bfb45e7786cc839e76.scope. | |
492 | ||
493 | $ screen -ls | |
494 | There is a screen on: | |
495 | 492..laptop (Detached) | |
496 | 1 Socket in /var/run/screen/S-fatima. | |
497 | </programlisting> | |
498 | ||
499 | <para>This starts the <command>screen</command> process as a child of the | |
500 | <command>systemd --user</command> process that was started by | |
501 | <filename>user@.service</filename>, in a scope unit. A | |
502 | <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
503 | unit is used instead of a | |
504 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
505 | unit, because <command>screen</command> will exit when detaching from the terminal, | |
506 | and a service unit would be terminated. Running <command>screen</command> | |
507 | as a user unit has the advantage that it is not part of the session scope. | |
508 | If <varname>KillUserProcesses=yes</varname> is configured in | |
509 | <citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
510 | the default, the session scope will be terminated when the user logs | |
511 | out of that session.</para> | |
512 | ||
513 | <para>The <filename>user@.service</filename> is started automatically | |
514 | when the user first logs in, and stays around as long as at least one | |
515 | login session is open. After the user logs out of the last session, | |
516 | <filename>user@.service</filename> and all services underneath it | |
2dd67817 | 517 | are terminated. This behavior is the default, when "lingering" is |
65eb37f8 ZJS |
518 | not enabled for that user. Enabling lingering means that |
519 | <filename>user@.service</filename> is started automatically during | |
520 | boot, even if the user is not logged in, and that the service is | |
521 | not terminated when the user logs out.</para> | |
522 | ||
523 | <para>Enabling lingering allows the user to run processes without being logged in, | |
524 | for example to allow <command>screen</command> to persist after the user logs out, | |
525 | even if the session scope is terminated. In the default configuration, users can | |
526 | enable lingering for themselves:</para> | |
527 | ||
528 | <programlisting>$ loginctl enable-linger</programlisting> | |
529 | </example> | |
7f3614e5 ZJS |
530 | |
531 | <example> | |
532 | <title>Return value</title> | |
533 | ||
534 | <programlisting>$ systemd-run --user --wait true | |
535 | $ systemd-run --user --wait -p SuccessExitStatus=11 bash -c 'exit 11' | |
536 | $ systemd-run --user --wait -p SuccessExitStatus=SIGUSR1 bash -c 'kill -SIGUSR1 $$$$'</programlisting> | |
537 | ||
538 | <para>Those three invocations will succeed, i.e. terminate with an exit code of 0.</para> | |
539 | </example> | |
c9d954b2 ZJS |
540 | </refsect1> |
541 | ||
f09114bc ZJS |
542 | <refsect1> |
543 | <title>See Also</title> | |
544 | <para> | |
545 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
3803cde4 | 546 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, |
f09114bc ZJS |
547 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
548 | <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
549 | <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
d21ed1ea | 550 | <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
df31a6c0 LP |
551 | <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
552 | <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
4c213d6c | 553 | <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
450442cf | 554 | <citerefentry><refentrytitle>systemd-mount</refentrytitle><manvolnum>1</manvolnum></citerefentry>, |
d21ed1ea | 555 | <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
f09114bc ZJS |
556 | </para> |
557 | </refsect1> | |
558 | ||
559 | </refentry> |