| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd-run" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>systemd-run</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>systemd-run</refentrytitle> |
| 16 |
<manvolnum>1</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>systemd-run</refname> |
| 21 |
<refpurpose>Run programs in transient scope units, service units, or path-, socket-, or timer-triggered service units</refpurpose> |
| 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> |
| 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> |
| 37 |
<arg choice="opt" rep="repeat">ARGS</arg> |
| 38 |
</arg> |
| 39 |
</cmdsynopsis> |
| 40 |
<cmdsynopsis> |
| 41 |
<command>systemd-run</command> |
| 42 |
<arg choice="opt" rep="repeat">OPTIONS</arg> |
| 43 |
<arg choice="opt" rep="repeat">SOCKET OPTIONS</arg> |
| 44 |
<arg choice="req"><replaceable>COMMAND</replaceable> |
| 45 |
<arg choice="opt" rep="repeat">ARGS</arg> |
| 46 |
</arg> |
| 47 |
</cmdsynopsis> |
| 48 |
<cmdsynopsis> |
| 49 |
<command>systemd-run</command> |
| 50 |
<arg choice="opt" rep="repeat">OPTIONS</arg> |
| 51 |
<arg choice="opt" rep="repeat">TIMER OPTIONS</arg> |
| 52 |
<arg choice="req"><replaceable>COMMAND</replaceable> |
| 53 |
<arg choice="opt" rep="repeat">ARGS</arg> |
| 54 |
</arg> |
| 55 |
</cmdsynopsis> |
| 56 |
</refsynopsisdiv> |
| 57 |
|
| 58 |
<refsect1> |
| 59 |
<title>Description</title> |
| 60 |
|
| 61 |
<para><command>systemd-run</command> may be used to create and start a transient <filename>.service</filename> or |
| 62 |
<filename>.scope</filename> unit and run the specified <replaceable>COMMAND</replaceable> in it. It may also be |
| 63 |
used to create and start a transient <filename>.path</filename>, <filename>.socket</filename>, or |
| 64 |
<filename>.timer</filename> unit, that activates a <filename>.service</filename> unit when elapsing.</para> |
| 65 |
|
| 66 |
<para>If a command is run as transient service unit, it will be started and managed by the service manager like any |
| 67 |
other service, and thus shows up in the output of <command>systemctl list-units</command> like any other unit. It |
| 68 |
will run in a clean and detached execution environment, with the service manager as its parent process. In this |
| 69 |
mode, <command>systemd-run</command> will start the service asynchronously in the background and return after the |
| 70 |
command has begun execution (unless <option>--no-block</option>, <option>--wait</option>, <option>--pipe</option>, |
| 71 |
or <option>--pty</option> are specified, see below).</para> |
| 72 |
|
| 73 |
<para>If a command is run as transient scope unit, it will be executed by <command>systemd-run</command> |
| 74 |
itself as parent process and will thus inherit the execution environment of the caller. However, the |
| 75 |
processes of the command are managed by the service manager similarly to normal services, and will show |
| 76 |
up in the output of <command>systemctl list-units</command>. Execution in this case is synchronous, and |
| 77 |
will return only when the command finishes. This mode is enabled via the <option>--scope</option> switch |
| 78 |
(see below).</para> |
| 79 |
|
| 80 |
<para>If a command is run with path, socket, or timer options such as <option>--on-calendar=</option> (see below), |
| 81 |
a transient path, socket, or timer unit is created alongside the service unit for the specified command. Only the |
| 82 |
transient path, socket, or timer unit is started immediately, the transient service unit will be triggered by the |
| 83 |
path, socket, or timer unit. If the <option>--unit=</option> option is specified, the |
| 84 |
<replaceable>COMMAND</replaceable> may be omitted. In this case, <command>systemd-run</command> creates only a |
| 85 |
<filename>.path</filename>, <filename>.socket</filename>, or <filename>.timer</filename> unit that triggers the |
| 86 |
specified unit.</para> |
| 87 |
|
| 88 |
<para>By default, services created with <command>systemd-run</command> default to the |
| 89 |
<option>simple</option> type, see the description of <varname>Type=</varname> in |
| 90 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
| 91 |
details. Note that when this type is used, the service manager (and thus the |
| 92 |
<command>systemd-run</command> command) considers service start-up successful as soon as the |
| 93 |
<function>fork()</function> for the main service process succeeded, i.e. before the |
| 94 |
<function>execve()</function> is invoked, and thus even if the specified command cannot be started. |
| 95 |
Consider using the <option>exec</option> service type (i.e. <option>--property=Type=exec</option>) to |
| 96 |
ensure that <command>systemd-run</command> returns successfully only if the specified command line has |
| 97 |
been successfully started.</para> |
| 98 |
|
| 99 |
<para>After <command>systemd-run</command> passes the command to the service manager, the manager |
| 100 |
performs variable expansion. This means that dollar characters (<literal>$</literal>) which should not be |
| 101 |
expanded need to be escaped as <literal>$$</literal>. Expansion can also be disabled using |
| 102 |
<varname>--expand-environment=no</varname>.</para> |
| 103 |
</refsect1> |
| 104 |
|
| 105 |
<refsect1> |
| 106 |
<title>Options</title> |
| 107 |
|
| 108 |
<para>The following options are understood:</para> |
| 109 |
|
| 110 |
<variablelist> |
| 111 |
<varlistentry> |
| 112 |
<term><option>--scope</option></term> |
| 113 |
|
| 114 |
<listitem> |
| 115 |
<para>Create a transient <filename>.scope</filename> unit instead of the default transient |
| 116 |
<filename>.service</filename> unit (see above). |
| 117 |
</para> |
| 118 |
|
| 119 |
<xi:include href="version-info.xml" xpointer="v206"/> |
| 120 |
</listitem> |
| 121 |
</varlistentry> |
| 122 |
|
| 123 |
<varlistentry> |
| 124 |
<term><option>--unit=</option></term> |
| 125 |
<term><option>-u</option></term> |
| 126 |
|
| 127 |
<listitem><para>Use this unit name instead of an automatically |
| 128 |
generated one.</para> |
| 129 |
|
| 130 |
<xi:include href="version-info.xml" xpointer="v206"/></listitem> |
| 131 |
</varlistentry> |
| 132 |
|
| 133 |
<varlistentry> |
| 134 |
<term><option>--property=</option></term> |
| 135 |
<term><option>-p</option></term> |
| 136 |
|
| 137 |
<listitem><para>Sets a property on the scope or service unit that is created. This option takes an assignment |
| 138 |
in the same format as |
| 139 |
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 140 |
<command>set-property</command> command.</para> |
| 141 |
|
| 142 |
<xi:include href="version-info.xml" xpointer="v211"/> |
| 143 |
</listitem> |
| 144 |
</varlistentry> |
| 145 |
|
| 146 |
<varlistentry> |
| 147 |
<term><option>--description=</option></term> |
| 148 |
|
| 149 |
<listitem><para>Provide a description for the service, scope, path, socket, or timer unit. If not specified, |
| 150 |
the command itself will be used as a description. See <varname>Description=</varname> in |
| 151 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 152 |
</para> |
| 153 |
|
| 154 |
<xi:include href="version-info.xml" xpointer="v206"/></listitem> |
| 155 |
</varlistentry> |
| 156 |
|
| 157 |
<varlistentry> |
| 158 |
<term><option>--slice=</option></term> |
| 159 |
|
| 160 |
<listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part |
| 161 |
of the specified slice, instead of <filename>system.slice</filename> (when running in |
| 162 |
<option>--system</option> mode) or the root slice (when running in <option>--user</option> |
| 163 |
mode).</para> |
| 164 |
|
| 165 |
<xi:include href="version-info.xml" xpointer="v206"/> |
| 166 |
</listitem> |
| 167 |
</varlistentry> |
| 168 |
|
| 169 |
<varlistentry> |
| 170 |
<term><option>--slice-inherit</option></term> |
| 171 |
|
| 172 |
<listitem><para>Make the new <filename>.service</filename> or <filename>.scope</filename> unit part |
| 173 |
of the slice the <command>systemd-run</command> itself has been invoked in. This option may be |
| 174 |
combined with <option>--slice=</option>, in which case the slice specified via |
| 175 |
<option>--slice=</option> is placed within the slice the <command>systemd-run</command> command is |
| 176 |
invoked in.</para> |
| 177 |
|
| 178 |
<para>Example: consider <command>systemd-run</command> being invoked in the slice |
| 179 |
<filename>foo.slice</filename>, and the <option>--slice=</option> argument is |
| 180 |
<filename>bar</filename>. The unit will then be placed under |
| 181 |
<filename>foo-bar.slice</filename>.</para> |
| 182 |
|
| 183 |
<xi:include href="version-info.xml" xpointer="v246"/> |
| 184 |
|
| 185 |
</listitem> |
| 186 |
</varlistentry> |
| 187 |
|
| 188 |
<varlistentry> |
| 189 |
<term><option>--expand-environment=<replaceable>BOOL</replaceable></option></term> |
| 190 |
|
| 191 |
<listitem><para>Expand environment variables in command arguments. If enabled (the default), |
| 192 |
environment variables specified as <literal>${<replaceable>VARIABLE</replaceable>}</literal> will be |
| 193 |
expanded in the same way as in commands specified via <varname>ExecStart=</varname> in units. With |
| 194 |
<varname>--scope</varname>, this expansion is performed by <command>systemd-run</command> itself, and |
| 195 |
in other cases by the service manager that spawns the command. Note that this is similar to, but not |
| 196 |
the same as variable expansion in |
| 197 |
<citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 198 |
and other shells.</para> |
| 199 |
|
| 200 |
<para>See |
| 201 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 202 |
for a description of variable expansion. Disabling variable expansion is useful if the specified |
| 203 |
command includes or may include a <literal>$</literal> sign.</para> |
| 204 |
|
| 205 |
<xi:include href="version-info.xml" xpointer="v254"/> |
| 206 |
</listitem> |
| 207 |
</varlistentry> |
| 208 |
|
| 209 |
<varlistentry> |
| 210 |
<term><option>-r</option></term> |
| 211 |
<term><option>--remain-after-exit</option></term> |
| 212 |
|
| 213 |
<listitem><para>After the service process has terminated, keep the service around until it is explicitly |
| 214 |
stopped. This is useful to collect runtime information about the service after it finished running. Also see |
| 215 |
<varname>RemainAfterExit=</varname> in |
| 216 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 217 |
</para> |
| 218 |
|
| 219 |
<xi:include href="version-info.xml" xpointer="v207"/> |
| 220 |
</listitem> |
| 221 |
</varlistentry> |
| 222 |
|
| 223 |
<varlistentry> |
| 224 |
<term><option>--send-sighup</option></term> |
| 225 |
|
| 226 |
<listitem><para>When terminating the scope or service unit, send a SIGHUP immediately after SIGTERM. This is |
| 227 |
useful to indicate to shells and shell-like processes that the connection has been severed. Also see |
| 228 |
<varname>SendSIGHUP=</varname> in |
| 229 |
<citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 230 |
</para> |
| 231 |
|
| 232 |
<xi:include href="version-info.xml" xpointer="v207"/> |
| 233 |
</listitem> |
| 234 |
</varlistentry> |
| 235 |
|
| 236 |
<varlistentry> |
| 237 |
<term><option>--service-type=</option></term> |
| 238 |
|
| 239 |
<listitem><para>Sets the service type. Also see |
| 240 |
<varname>Type=</varname> in |
| 241 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This |
| 242 |
option has no effect in conjunction with |
| 243 |
<option>--scope</option>. Defaults to |
| 244 |
<constant>simple</constant>.</para> |
| 245 |
|
| 246 |
<xi:include href="version-info.xml" xpointer="v211"/> |
| 247 |
</listitem> |
| 248 |
</varlistentry> |
| 249 |
|
| 250 |
<varlistentry> |
| 251 |
<term><option>--uid=</option></term> |
| 252 |
<term><option>--gid=</option></term> |
| 253 |
|
| 254 |
<listitem><para>Runs the service process under the specified UNIX user and group. Also see |
| 255 |
<varname>User=</varname> and <varname>Group=</varname> in |
| 256 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 257 |
|
| 258 |
<xi:include href="version-info.xml" xpointer="v211"/> |
| 259 |
</listitem> |
| 260 |
</varlistentry> |
| 261 |
|
| 262 |
<varlistentry> |
| 263 |
<term><option>--nice=</option></term> |
| 264 |
|
| 265 |
<listitem><para>Runs the service process with the specified |
| 266 |
nice level. Also see <varname>Nice=</varname> in |
| 267 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 268 |
|
| 269 |
<xi:include href="version-info.xml" xpointer="v211"/> |
| 270 |
</listitem> |
| 271 |
</varlistentry> |
| 272 |
|
| 273 |
<varlistentry> |
| 274 |
<term><option>--working-directory=</option></term> |
| 275 |
|
| 276 |
<listitem><para>Runs the service process with the specified working directory. Also see |
| 277 |
<varname>WorkingDirectory=</varname> in |
| 278 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 279 |
|
| 280 |
<xi:include href="version-info.xml" xpointer="v240"/> |
| 281 |
</listitem> |
| 282 |
</varlistentry> |
| 283 |
|
| 284 |
<varlistentry> |
| 285 |
<term><option>--same-dir</option></term> |
| 286 |
<term><option>-d</option></term> |
| 287 |
|
| 288 |
<listitem><para>Similar to <option>--working-directory=</option>, but uses the current working |
| 289 |
directory of the caller for the service to execute.</para> |
| 290 |
|
| 291 |
<xi:include href="version-info.xml" xpointer="v240"/></listitem> |
| 292 |
</varlistentry> |
| 293 |
|
| 294 |
<varlistentry> |
| 295 |
<term><option>--root-directory=</option></term> |
| 296 |
|
| 297 |
<listitem><para>Runs the service process with the specified root directory. Also see |
| 298 |
<varname>RootDirectory=</varname> in |
| 299 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 300 |
|
| 301 |
<para>Note that the path is looked up inside the file system namespace that systemd-run is running |
| 302 |
in, which might be different that the file system namespace the manager process is running in. Use |
| 303 |
the <varname>RootDirectory=</varname> property directly if you want the path to be looked up in the |
| 304 |
manager process's file system namespace.</para> |
| 305 |
|
| 306 |
<xi:include href="version-info.xml" xpointer="v259"/> |
| 307 |
</listitem> |
| 308 |
</varlistentry> |
| 309 |
|
| 310 |
<varlistentry> |
| 311 |
<term><option>--same-root-dir</option></term> |
| 312 |
<term><option>-R</option></term> |
| 313 |
|
| 314 |
<listitem><para>Similar to <option>--root-directory=</option>, but uses the root directory of the |
| 315 |
systemd-run process as the root directory to execute the service in.</para> |
| 316 |
|
| 317 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 318 |
</varlistentry> |
| 319 |
|
| 320 |
<varlistentry> |
| 321 |
<term><option>-E <replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term> |
| 322 |
<term><option>--setenv=<replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term> |
| 323 |
|
| 324 |
<listitem><para>Runs the service process with the specified environment variable set. This parameter |
| 325 |
may be used more than once to set multiple variables. When <literal>=</literal> and |
| 326 |
<replaceable>VALUE</replaceable> are omitted, the value of the variable with the same name in the |
| 327 |
program environment will be used.</para> |
| 328 |
|
| 329 |
<para>Also see <varname>Environment=</varname> in |
| 330 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 331 |
|
| 332 |
<xi:include href="version-info.xml" xpointer="v211"/> |
| 333 |
</listitem> |
| 334 |
</varlistentry> |
| 335 |
|
| 336 |
<varlistentry> |
| 337 |
<term><option>--pty</option></term> |
| 338 |
<term><option>-t</option></term> |
| 339 |
|
| 340 |
<listitem><para>When invoking the command, the transient service connects its standard input, output and error |
| 341 |
to the terminal <command>systemd-run</command> is invoked on, via a pseudo TTY device. This allows running |
| 342 |
programs that expect interactive user input/output as services, such as interactive command shells.</para> |
| 343 |
|
| 344 |
<para>This option will result in <command>systemd-run</command> synchronously waiting for |
| 345 |
the transient service to terminate, similar to specifying <option>--wait</option>. If specified |
| 346 |
along with <option>--wait</option>, <command>systemd-run</command> will not exit when manually disconnecting |
| 347 |
from the pseudo TTY device.</para> |
| 348 |
|
| 349 |
<para>Note that |
| 350 |
<citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 351 |
<command>shell</command> command is usually a better alternative for requesting a new, interactive login |
| 352 |
session on the local host or a local container.</para> |
| 353 |
|
| 354 |
<para>See below for details on how this switch combines with <option>--pipe</option>.</para> |
| 355 |
|
| 356 |
<xi:include href="version-info.xml" xpointer="v219"/></listitem> |
| 357 |
</varlistentry> |
| 358 |
|
| 359 |
<varlistentry> |
| 360 |
<term><option>--pty-late</option></term> |
| 361 |
<term><option>-T</option></term> |
| 362 |
|
| 363 |
<listitem><para>Much like <option>--pty</option>, but the PTY communication only begins once the unit |
| 364 |
start is complete. This effectively means PTY input during <varname>ExecStartPre=</varname> of a |
| 365 |
service is not available while using <option>--pty-late</option>, while it is available using |
| 366 |
<option>--pty</option>, for most service types. However, if this option is used, access to the |
| 367 |
invoking TTY is available for password queries (see <option>--no-ask-password</option> below) during |
| 368 |
unit start-up.</para> |
| 369 |
|
| 370 |
<xi:include href="version-info.xml" xpointer="v258"/></listitem> |
| 371 |
</varlistentry> |
| 372 |
|
| 373 |
<varlistentry> |
| 374 |
<term><option>--pipe</option></term> |
| 375 |
<term><option>-P</option></term> |
| 376 |
|
| 377 |
<listitem><para>If specified, standard input, output, and error of the transient service are inherited from the |
| 378 |
<command>systemd-run</command> command itself. This allows <command>systemd-run</command> |
| 379 |
to be used within shell pipelines.</para> |
| 380 |
|
| 381 |
<para>Note that this mode is not suitable for interactive command shells and similar, as the |
| 382 |
service process will not become a TTY controller when invoked on a terminal. Use <option>--pty</option> |
| 383 |
instead in that case.</para> |
| 384 |
|
| 385 |
<para>When both <option>--pipe</option> and <option>--pty</option> are used in combination the more appropriate |
| 386 |
option is automatically determined and used. Specifically, when invoked with standard input, output and error |
| 387 |
connected to a TTY <option>--pty</option> is used, and otherwise <option>--pipe</option>.</para> |
| 388 |
|
| 389 |
<para>This option will result in <command>systemd-run</command> synchronously waiting for |
| 390 |
the transient service to terminate, similar to specifying <option>--wait</option>.</para> |
| 391 |
|
| 392 |
<para>When this option is used the original file descriptors <command>systemd-run</command> receives are passed |
| 393 |
to the service processes as-is. If the service runs with different privileges than |
| 394 |
<command>systemd-run</command>, this means the service might not be able to reopen the passed file |
| 395 |
descriptors, due to normal file descriptor access restrictions. If the invoked process is a shell script that |
| 396 |
uses the <command>echo "hello" >/dev/stderr</command> construct for writing messages to stderr, this might |
| 397 |
cause problems, as this only works if stderr can be reopened. To mitigate this use the construct <command>echo |
| 398 |
"hello" >&2</command> instead, which is mostly equivalent and avoids this pitfall.</para> |
| 399 |
|
| 400 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 401 |
</varlistentry> |
| 402 |
|
| 403 |
<varlistentry> |
| 404 |
<term><option>--shell</option></term> |
| 405 |
<term><option>-S</option></term> |
| 406 |
|
| 407 |
<listitem><para>A shortcut for <literal>--pty --same-dir --wait --collect --service-type=exec $SHELL</literal>, |
| 408 |
i.e. requests an interactive shell in the current working directory, running in service context, accessible |
| 409 |
with a single switch.</para> |
| 410 |
|
| 411 |
<xi:include href="version-info.xml" xpointer="v240"/></listitem> |
| 412 |
</varlistentry> |
| 413 |
|
| 414 |
<varlistentry> |
| 415 |
<term><option>--quiet</option></term> |
| 416 |
<term><option>-q</option></term> |
| 417 |
|
| 418 |
<listitem><para>Suppresses additional informational output |
| 419 |
while running. This is particularly useful in combination with |
| 420 |
<option>--pty</option> when it will suppress the initial |
| 421 |
message explaining how to terminate the TTY connection.</para> |
| 422 |
|
| 423 |
<xi:include href="version-info.xml" xpointer="v219"/></listitem> |
| 424 |
</varlistentry> |
| 425 |
|
| 426 |
<varlistentry> |
| 427 |
<term><option>-v</option></term> |
| 428 |
<term><option>--verbose</option></term> |
| 429 |
|
| 430 |
<listitem> |
| 431 |
<para>Display unit log output while running.</para> |
| 432 |
|
| 433 |
<xi:include href="version-info.xml" xpointer="v258"/> |
| 434 |
</listitem> |
| 435 |
</varlistentry> |
| 436 |
|
| 437 |
<varlistentry> |
| 438 |
<term><option>--output=</option></term> |
| 439 |
|
| 440 |
<listitem> |
| 441 |
<para>Controls the formatting of verbose unit log output, see <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for possible values.</para> |
| 442 |
|
| 443 |
<xi:include href="version-info.xml" xpointer="v261"/> |
| 444 |
</listitem> |
| 445 |
</varlistentry> |
| 446 |
|
| 447 |
<varlistentry> |
| 448 |
<term><option>--on-active=</option></term> |
| 449 |
<term><option>--on-boot=</option></term> |
| 450 |
<term><option>--on-startup=</option></term> |
| 451 |
<term><option>--on-unit-active=</option></term> |
| 452 |
<term><option>--on-unit-inactive=</option></term> |
| 453 |
|
| 454 |
<listitem><para>Defines a monotonic timer relative to different starting points for starting the specified |
| 455 |
command. See <varname>OnActiveSec=</varname>, <varname>OnBootSec=</varname>, <varname>OnStartupSec=</varname>, |
| 456 |
<varname>OnUnitActiveSec=</varname> and <varname>OnUnitInactiveSec=</varname> in |
| 457 |
<citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
| 458 |
details. These options are shortcuts for <command>--timer-property=</command> with the relevant properties. |
| 459 |
These options may not be combined with <option>--scope</option> or <option>--pty</option>.</para> |
| 460 |
|
| 461 |
<xi:include href="version-info.xml" xpointer="v218"/> |
| 462 |
</listitem> |
| 463 |
</varlistentry> |
| 464 |
|
| 465 |
<varlistentry> |
| 466 |
<term><option>--on-calendar=</option></term> |
| 467 |
|
| 468 |
<listitem><para>Defines a calendar timer for starting the specified command. See <varname>OnCalendar=</varname> |
| 469 |
in <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This |
| 470 |
option is a shortcut for <command>--timer-property=OnCalendar=</command>. This option may not be combined with |
| 471 |
<option>--scope</option> or <option>--pty</option>.</para> |
| 472 |
|
| 473 |
<xi:include href="version-info.xml" xpointer="v218"/> |
| 474 |
</listitem> |
| 475 |
</varlistentry> |
| 476 |
|
| 477 |
<varlistentry> |
| 478 |
<term><option>--on-clock-change</option></term> |
| 479 |
<term><option>--on-timezone-change</option></term> |
| 480 |
|
| 481 |
<listitem><para>Defines a trigger based on system clock jumps or timezone changes for starting the |
| 482 |
specified command. See <varname>OnClockChange=</varname> and <varname>OnTimezoneChange=</varname> in |
| 483 |
<citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>. These |
| 484 |
options are shortcuts for <command>--timer-property=OnClockChange=yes</command> and |
| 485 |
<command>--timer-property=OnTimezoneChange=yes</command>. These options may not be combined with |
| 486 |
<option>--scope</option> or <option>--pty</option>.</para> |
| 487 |
|
| 488 |
<xi:include href="version-info.xml" xpointer="v242"/></listitem> |
| 489 |
</varlistentry> |
| 490 |
|
| 491 |
<varlistentry> |
| 492 |
<term><option>--path-property=</option></term> |
| 493 |
<term><option>--socket-property=</option></term> |
| 494 |
<term><option>--timer-property=</option></term> |
| 495 |
|
| 496 |
<listitem><para>Sets a property on the path, socket, or timer unit that is created. This option is |
| 497 |
similar to <option>--property=</option>, but applies to the transient path, socket, or timer unit |
| 498 |
rather than the transient service unit created. This option takes an assignment in the same format as |
| 499 |
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 500 |
<command>set-property</command> command. These options may not be combined with |
| 501 |
<option>--scope</option> or <option>--pty</option>.</para> |
| 502 |
|
| 503 |
<xi:include href="version-info.xml" xpointer="v218"/> |
| 504 |
</listitem> |
| 505 |
</varlistentry> |
| 506 |
|
| 507 |
<varlistentry> |
| 508 |
<term><option>--no-block</option></term> |
| 509 |
|
| 510 |
<listitem> |
| 511 |
<para>Do not synchronously wait for the unit start operation to finish. If this option is not specified, the |
| 512 |
start request for the transient unit will be verified, enqueued and <command>systemd-run</command> will wait |
| 513 |
until the unit's start-up is completed. By passing this argument, it is only verified and enqueued. This |
| 514 |
option may not be combined with <option>--wait</option>.</para> |
| 515 |
|
| 516 |
<xi:include href="version-info.xml" xpointer="v220"/> |
| 517 |
</listitem> |
| 518 |
</varlistentry> |
| 519 |
|
| 520 |
<varlistentry> |
| 521 |
<term><option>--wait</option></term> |
| 522 |
|
| 523 |
<listitem><para>Synchronously wait for the transient service to terminate. If this option is specified, the |
| 524 |
start request for the transient unit is verified, enqueued, and waited for. Subsequently the invoked unit is |
| 525 |
monitored, and it is waited until it is deactivated again (most likely because the specified command |
| 526 |
completed). On exit, terse information about the unit's runtime is shown, including total runtime (as well as |
| 527 |
CPU, memory, IO, and IP accounting data, if the corresponding cgroup accounting settings are enabled) |
| 528 |
and the exit code and status of the main process. This output may be suppressed with <option>--quiet</option>. |
| 529 |
This option may not be combined with <option>--no-block</option>, <option>--scope</option> or the various |
| 530 |
path, socket, or timer options.</para> |
| 531 |
|
| 532 |
<xi:include href="version-info.xml" xpointer="v232"/></listitem> |
| 533 |
</varlistentry> |
| 534 |
|
| 535 |
<varlistentry> |
| 536 |
<term><option>-G</option></term> |
| 537 |
<term><option>--collect</option></term> |
| 538 |
|
| 539 |
<listitem><para>Unload the transient unit after it completed, even if it failed. Normally, without this option, |
| 540 |
all units that ran and failed are kept in memory until the user explicitly resets their failure state with |
| 541 |
<command>systemctl reset-failed</command> or an equivalent command. On the other hand, units that ran |
| 542 |
successfully are unloaded immediately. If this option is turned on the "garbage collection" of units is more |
| 543 |
aggressive, and unloads units regardless of whether they exited successfully or failed. This option is a shortcut for |
| 544 |
<command>--property=CollectMode=inactive-or-failed</command>, see the explanation for |
| 545 |
<varname>CollectMode=</varname> in |
| 546 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for further |
| 547 |
information.</para> |
| 548 |
|
| 549 |
<xi:include href="version-info.xml" xpointer="v236"/></listitem> |
| 550 |
</varlistentry> |
| 551 |
|
| 552 |
<varlistentry> |
| 553 |
<term><option>--job-mode=<replaceable>MODE</replaceable></option></term> |
| 554 |
|
| 555 |
<listitem> |
| 556 |
<para>When queuing a new job, this option controls how to deal with |
| 557 |
already queued jobs.</para> |
| 558 |
|
| 559 |
<para>The option takes the same mode values as |
| 560 |
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 561 |
<option>--job-mode=</option> option. The default job mode is <literal>fail</literal>.</para> |
| 562 |
|
| 563 |
<para>Running <option>--job-mode=help</option> shows a list of available job modes.</para> |
| 564 |
|
| 565 |
<xi:include href="version-info.xml" xpointer="v258"/> |
| 566 |
</listitem> |
| 567 |
</varlistentry> |
| 568 |
|
| 569 |
<varlistentry> |
| 570 |
<term><option>--ignore-failure</option></term> |
| 571 |
|
| 572 |
<listitem><para>By default, if the specified command fails the invoked unit will be marked failed |
| 573 |
(though possibly still unloaded, see <option>--collect=</option>, above), and this is reported in the |
| 574 |
logs. If this switch is specified this is suppressed and any non-success exit status/code of the |
| 575 |
command is treated as success.</para> |
| 576 |
|
| 577 |
<xi:include href="version-info.xml" xpointer="v256"/></listitem> |
| 578 |
</varlistentry> |
| 579 |
|
| 580 |
<varlistentry> |
| 581 |
<term><option>--background=<replaceable>COLOR</replaceable></option></term> |
| 582 |
|
| 583 |
<listitem><para>Change the terminal background color to the specified ANSI color as long as the |
| 584 |
session lasts. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such as |
| 585 |
<literal>40</literal>, <literal>41</literal>, …, <literal>47</literal>, <literal>48;2;…</literal>, |
| 586 |
<literal>48;5;…</literal>. See <ulink |
| 587 |
url="https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters">ANSI |
| 588 |
Escape Code (Wikipedia)</ulink> for details.</para> |
| 589 |
|
| 590 |
<xi:include href="version-info.xml" xpointer="v256"/> |
| 591 |
</listitem> |
| 592 |
</varlistentry> |
| 593 |
|
| 594 |
<xi:include href="user-system-options.xml" xpointer="user" /> |
| 595 |
<xi:include href="user-system-options.xml" xpointer="system" /> |
| 596 |
<xi:include href="user-system-options.xml" xpointer="host" /> |
| 597 |
<xi:include href="user-system-options.xml" xpointer="machine" /> |
| 598 |
<xi:include href="user-system-options.xml" xpointer="capsule" /> |
| 599 |
|
| 600 |
<xi:include href="standard-options.xml" xpointer="no-ask-password" /> |
| 601 |
<xi:include href="standard-options.xml" xpointer="help" /> |
| 602 |
<xi:include href="standard-options.xml" xpointer="version" /> |
| 603 |
<xi:include href="standard-options.xml" xpointer="json" /> |
| 604 |
|
| 605 |
<varlistentry id='no-pager'> |
| 606 |
<term><option>--no-pager</option></term> |
| 607 |
|
| 608 |
<listitem><para>Do not pipe output into a pager. This currently only applies to |
| 609 |
<option>--help</option>. (The pager is not started during normal operation.)</para> |
| 610 |
|
| 611 |
<xi:include href="version-info.xml" xpointer="v258"/> |
| 612 |
</listitem> |
| 613 |
</varlistentry> |
| 614 |
</variablelist> |
| 615 |
|
| 616 |
<para>All command line arguments after the first non-option argument become part of the command line of |
| 617 |
the launched process.</para> |
| 618 |
</refsect1> |
| 619 |
|
| 620 |
<refsect1> |
| 621 |
<title>Exit status</title> |
| 622 |
|
| 623 |
<para>On success, 0 is returned. If <command>systemd-run</command> failed to start the service, a |
| 624 |
non-zero return value will be returned. If <command>systemd-run</command> waits for the service to |
| 625 |
terminate, the return value will be propagated from the service. 0 will be returned on success, including |
| 626 |
all the cases where systemd considers a service to have exited cleanly, see the discussion of |
| 627 |
<varname>SuccessExitStatus=</varname> in |
| 628 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 629 |
</para> |
| 630 |
</refsect1> |
| 631 |
|
| 632 |
<refsect1> |
| 633 |
<title>Examples</title> |
| 634 |
|
| 635 |
<example> |
| 636 |
<title>Logging environment variables provided by systemd to services</title> |
| 637 |
|
| 638 |
<programlisting># systemd-run env |
| 639 |
Running as unit: run-19945.service |
| 640 |
# journalctl -u run-19945.service |
| 641 |
Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env... |
| 642 |
Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env. |
| 643 |
Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin |
| 644 |
Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8 |
| 645 |
Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</programlisting> |
| 646 |
</example> |
| 647 |
|
| 648 |
<example> |
| 649 |
<title>Limiting resources available to a command</title> |
| 650 |
|
| 651 |
<programlisting># systemd-run -p IOWeight=10 updatedb</programlisting> |
| 652 |
|
| 653 |
<para>This command invokes the <citerefentry |
| 654 |
project='man-pages'><refentrytitle>updatedb</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 655 |
tool, but lowers the block I/O weight for it to 10. See |
| 656 |
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 657 |
for more information on the <varname>IOWeight=</varname> property.</para> |
| 658 |
</example> |
| 659 |
|
| 660 |
<example> |
| 661 |
<title>Running commands at a specified time</title> |
| 662 |
|
| 663 |
<para>The following command will touch a file after 30 seconds.</para> |
| 664 |
|
| 665 |
<programlisting># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo |
| 666 |
Mon Dec 8 20:44:24 KST 2014 |
| 667 |
Running as unit: run-71.timer |
| 668 |
Will run service as unit: run-71.service |
| 669 |
# journalctl -b -u run-71.timer |
| 670 |
-- Journal begins at Fri 2014-12-05 19:09:21 KST, ends at Mon 2014-12-08 20:44:54 KST. -- |
| 671 |
Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo. |
| 672 |
Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo. |
| 673 |
# journalctl -b -u run-71.service |
| 674 |
-- Journal begins at Fri 2014-12-05 19:09:21 KST, ends at Mon 2014-12-08 20:44:54 KST. -- |
| 675 |
Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo... |
| 676 |
Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</programlisting> |
| 677 |
</example> |
| 678 |
|
| 679 |
<example> |
| 680 |
<title>Allowing access to the tty</title> |
| 681 |
|
| 682 |
<para>The following command invokes |
| 683 |
<citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 684 |
as a service passing its standard input, output and error to the calling TTY.</para> |
| 685 |
|
| 686 |
<programlisting># systemd-run -t --send-sighup bash</programlisting> |
| 687 |
</example> |
| 688 |
|
| 689 |
<example> |
| 690 |
<title>Start <command>screen</command> as a user service</title> |
| 691 |
|
| 692 |
<programlisting>$ systemd-run --scope --user screen |
| 693 |
Running scope as unit run-r14b0047ab6df45bfb45e7786cc839e76.scope. |
| 694 |
|
| 695 |
$ screen -ls |
| 696 |
There is a screen on: |
| 697 |
492..laptop (Detached) |
| 698 |
1 Socket in /var/run/screen/S-fatima. |
| 699 |
</programlisting> |
| 700 |
|
| 701 |
<para>This starts the <command>screen</command> process as a child of the |
| 702 |
<command>systemd --user</command> process that was started by |
| 703 |
<filename>[email protected]</filename>, in a scope unit. A |
| 704 |
<citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 705 |
unit is used instead of a |
| 706 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 707 |
unit, because <command>screen</command> will exit when detaching from the terminal, |
| 708 |
and a service unit would be terminated. Running <command>screen</command> |
| 709 |
as a user unit has the advantage that it is not part of the session scope. |
| 710 |
If <varname>KillUserProcesses=yes</varname> is configured in |
| 711 |
<citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
| 712 |
the default, the session scope will be terminated when the user logs |
| 713 |
out of that session.</para> |
| 714 |
|
| 715 |
<para>The <filename>[email protected]</filename> is started automatically |
| 716 |
when the user first logs in, and stays around as long as at least one |
| 717 |
login session is open. After the user logs out of the last session, |
| 718 |
<filename>[email protected]</filename> and all services underneath it |
| 719 |
are terminated. This behavior is the default, when "lingering" is |
| 720 |
not enabled for that user. Enabling lingering means that |
| 721 |
<filename>[email protected]</filename> is started automatically during |
| 722 |
boot, even if the user is not logged in, and that the service is |
| 723 |
not terminated when the user logs out.</para> |
| 724 |
|
| 725 |
<para>Enabling lingering allows the user to run processes without being logged in, |
| 726 |
for example to allow <command>screen</command> to persist after the user logs out, |
| 727 |
even if the session scope is terminated. In the default configuration, users can |
| 728 |
enable lingering for themselves:</para> |
| 729 |
|
| 730 |
<programlisting>$ loginctl enable-linger</programlisting> |
| 731 |
</example> |
| 732 |
|
| 733 |
<example> |
| 734 |
<title>Variable expansion by the manager</title> |
| 735 |
|
| 736 |
<programlisting>$ systemd-run -t echo "<${INVOCATION_ID}>" '<${INVOCATION_ID}>' |
| 737 |
<> <5d0149bfa2c34b79bccb13074001eb20> |
| 738 |
</programlisting> |
| 739 |
|
| 740 |
<para>The first argument is expanded by the shell (double quotes), but the second one is not expanded |
| 741 |
by the shell (single quotes). |
| 742 |
<citerefentry project='man-pages'><refentrytitle>echo</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 743 |
is called with [<literal>/usr/bin/echo</literal>, |
| 744 |
<literal><></literal>, <literal><${INVOCATION_ID}></literal>] as the argument array, and then |
| 745 |
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 746 |
generates <varname>${INVOCATION_ID}</varname> and substitutes it in the command-line. This substitution |
| 747 |
could not be done on the client side, because the target ID that will be set for the service is not |
| 748 |
known before the call is made.</para> |
| 749 |
</example> |
| 750 |
|
| 751 |
<example> |
| 752 |
<title>Variable expansion and output redirection using a shell</title> |
| 753 |
|
| 754 |
<para>Variable expansion by |
| 755 |
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 756 |
can be disabled with <varname>--expand-environment=no</varname>.</para> |
| 757 |
|
| 758 |
<para>Disabling variable expansion can be useful if the command to execute contains dollar characters |
| 759 |
and escaping them would be inconvenient. For example, when a shell is used:</para> |
| 760 |
|
| 761 |
<programlisting>$ systemd-run --expand-environment=no -t bash \ |
| 762 |
-c 'echo $SHELL $$ >/dev/stdout' |
| 763 |
/bin/bash 12345 |
| 764 |
</programlisting> |
| 765 |
|
| 766 |
<para>The last argument is passed verbatim to the |
| 767 |
<citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 768 |
shell which is started by the service unit. The shell expands <literal>$SHELL</literal> to the path of |
| 769 |
the shell, and <literal>$$</literal> to its process number, and then those strings are passed to the |
| 770 |
<command>echo</command> built-in and printed to standard output (which, in this case, is connected to the |
| 771 |
calling terminal).</para> |
| 772 |
</example> |
| 773 |
|
| 774 |
<example> |
| 775 |
<title>Return value</title> |
| 776 |
|
| 777 |
<programlisting>$ systemd-run --user --wait true |
| 778 |
$ systemd-run --user --wait -p SuccessExitStatus=11 bash -c 'exit 11' |
| 779 |
$ systemd-run --user --wait -p SuccessExitStatus=SIGUSR1 --expand-environment=no \ |
| 780 |
bash -c 'kill -SIGUSR1 $$'</programlisting> |
| 781 |
|
| 782 |
<para>Those three invocations will succeed, i.e. terminate with an exit code of 0.</para> |
| 783 |
</example> |
| 784 |
</refsect1> |
| 785 |
|
| 786 |
<refsect1> |
| 787 |
<title>See Also</title> |
| 788 |
<para><simplelist type="inline"> |
| 789 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 790 |
<member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 791 |
<member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 792 |
<member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 793 |
<member><citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 794 |
<member><citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 795 |
<member><citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 796 |
<member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 797 |
<member><citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 798 |
<member><citerefentry><refentrytitle>systemd-mount</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 799 |
<member><citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 800 |
<member><citerefentry><refentrytitle>run0</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 801 |
</simplelist></para> |
| 802 |
</refsect1> |
| 803 |
|
| 804 |
</refentry> |