Debian Codegraph @

upstream/debian-trixie/man1/systemd-run.1

raw
1 '\" t
2 .TH "SYSTEMD\-RUN" "1" "" "systemd 257.13" "systemd-run"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 systemd-run \- Run programs in transient scope units, service units, or path\-, socket\-, or timer\-triggered service units
24 .SH "SYNOPSIS"
25 .HP \w'\fBsystemd\-run\fR\ 'u
26 \fBsystemd\-run\fR [OPTIONS...] \fICOMMAND\fR\ [ARGS...]
27 .HP \w'\fBsystemd\-run\fR\ 'u
28 \fBsystemd\-run\fR [OPTIONS...] [PATH\ OPTIONS...] {\fICOMMAND\fR} [ARGS...]
29 .HP \w'\fBsystemd\-run\fR\ 'u
30 \fBsystemd\-run\fR [OPTIONS...] [SOCKET\ OPTIONS...] {\fICOMMAND\fR} [ARGS...]
31 .HP \w'\fBsystemd\-run\fR\ 'u
32 \fBsystemd\-run\fR [OPTIONS...] [TIMER\ OPTIONS...] {\fICOMMAND\fR} [ARGS...]
33 .SH "DESCRIPTION"
34 .PP
35 \fBsystemd\-run\fR
36 may be used to create and start a transient
37 \&.service
38 or
39 \&.scope
40 unit and run the specified
41 \fICOMMAND\fR
42 in it\&. It may also be used to create and start a transient
43 \&.path,
44 \&.socket, or
45 \&.timer
46 unit, that activates a
47 \&.service
48 unit when elapsing\&.
49 .PP
50 If a command is run as transient service unit, it will be started and managed by the service manager like any other service, and thus shows up in the output of
51 \fBsystemctl list\-units\fR
52 like any other unit\&. It will run in a clean and detached execution environment, with the service manager as its parent process\&. In this mode,
53 \fBsystemd\-run\fR
54 will start the service asynchronously in the background and return after the command has begun execution (unless
55 \fB\-\-no\-block\fR,
56 \fB\-\-wait\fR,
57 \fB\-\-pipe\fR, or
58 \fB\-\-pty\fR
59 are specified, see below)\&.
60 .PP
61 If a command is run as transient scope unit, it will be executed by
62 \fBsystemd\-run\fR
63 itself as parent process and will thus inherit the execution environment of the caller\&. However, the processes of the command are managed by the service manager similarly to normal services, and will show up in the output of
64 \fBsystemctl list\-units\fR\&. Execution in this case is synchronous, and will return only when the command finishes\&. This mode is enabled via the
65 \fB\-\-scope\fR
66 switch (see below)\&.
67 .PP
68 If a command is run with path, socket, or timer options such as
69 \fB\-\-on\-calendar=\fR
70 (see below), a transient path, socket, or timer unit is created alongside the service unit for the specified command\&. Only the transient path, socket, or timer unit is started immediately, the transient service unit will be triggered by the path, socket, or timer unit\&. If the
71 \fB\-\-unit=\fR
72 option is specified, the
73 \fICOMMAND\fR
74 may be omitted\&. In this case,
75 \fBsystemd\-run\fR
76 creates only a
77 \&.path,
78 \&.socket, or
79 \&.timer
80 unit that triggers the specified unit\&.
81 .PP
82 By default, services created with
83 \fBsystemd\-run\fR
84 default to the
85 \fBsimple\fR
86 type, see the description of
87 \fIType=\fR
88 in
89 \fBsystemd.service\fR(5)
90 for details\&. Note that when this type is used, the service manager (and thus the
91 \fBsystemd\-run\fR
92 command) considers service start\-up successful as soon as the
93 \fBfork()\fR
94 for the main service process succeeded, i\&.e\&. before the
95 \fBexecve()\fR
96 is invoked, and thus even if the specified command cannot be started\&. Consider using the
97 \fBexec\fR
98 service type (i\&.e\&.
99 \fB\-\-property=Type=exec\fR) to ensure that
100 \fBsystemd\-run\fR
101 returns successfully only if the specified command line has been successfully started\&.
102 .PP
103 After
104 \fBsystemd\-run\fR
105 passes the command to the service manager, the manager performs variable expansion\&. This means that dollar characters ("$") which should not be expanded need to be escaped as
106 "$$"\&. Expansion can also be disabled using
107 \fI\-\-expand\-environment=no\fR\&.
108 .SH "OPTIONS"
109 .PP
110 The following options are understood:
111 .PP
112 \fB\-\-scope\fR
113 .RS 4
114 Create a transient
115 \&.scope
116 unit instead of the default transient
117 \&.service
118 unit (see above)\&.
119 .sp
120 Added in version 206\&.
121 .RE
122 .PP
123 \fB\-\-unit=\fR, \fB\-u\fR
124 .RS 4
125 Use this unit name instead of an automatically generated one\&.
126 .sp
127 Added in version 206\&.
128 .RE
129 .PP
130 \fB\-\-property=\fR, \fB\-p\fR
131 .RS 4
132 Sets a property on the scope or service unit that is created\&. This option takes an assignment in the same format as
133 \fBsystemctl\fR(1)\*(Aqs
134 \fBset\-property\fR
135 command\&.
136 .sp
137 Added in version 211\&.
138 .RE
139 .PP
140 \fB\-\-description=\fR
141 .RS 4
142 Provide a description for the service, scope, path, socket, or timer unit\&. If not specified, the command itself will be used as a description\&. See
143 \fIDescription=\fR
144 in
145 \fBsystemd.unit\fR(5)\&.
146 .sp
147 Added in version 206\&.
148 .RE
149 .PP
150 \fB\-\-slice=\fR
151 .RS 4
152 Make the new
153 \&.service
154 or
155 \&.scope
156 unit part of the specified slice, instead of
157 system\&.slice
158 (when running in
159 \fB\-\-system\fR
160 mode) or the root slice (when running in
161 \fB\-\-user\fR
162 mode)\&.
163 .sp
164 Added in version 206\&.
165 .RE
166 .PP
167 \fB\-\-slice\-inherit\fR
168 .RS 4
169 Make the new
170 \&.service
171 or
172 \&.scope
173 unit part of the slice the
174 \fBsystemd\-run\fR
175 itself has been invoked in\&. This option may be combined with
176 \fB\-\-slice=\fR, in which case the slice specified via
177 \fB\-\-slice=\fR
178 is placed within the slice the
179 \fBsystemd\-run\fR
180 command is invoked in\&.
181 .sp
182 Example: consider
183 \fBsystemd\-run\fR
184 being invoked in the slice
185 foo\&.slice, and the
186 \fB\-\-slice=\fR
187 argument is
188 bar\&. The unit will then be placed under
189 foo\-bar\&.slice\&.
190 .sp
191 Added in version 246\&.
192 .RE
193 .PP
194 \fB\-\-expand\-environment=\fR\fB\fIBOOL\fR\fR
195 .RS 4
196 Expand environment variables in command arguments\&. If enabled, environment variables specified as
197 "${\fIVARIABLE\fR}"
198 will be expanded in the same way as in commands specified via
199 \fIExecStart=\fR
200 in units\&. With
201 \fI\-\-scope\fR, this expansion is performed by
202 \fBsystemd\-run\fR
203 itself, and in other cases by the service manager that spawns the command\&. Note that this is similar to, but not the same as variable expansion in
204 \fBbash\fR(1)
205 and other shells\&.
206 .sp
207 The default is to enable this option in all cases, except for
208 \fI\-\-scope\fR
209 where it is disabled by default, for backward compatibility reasons\&. Note that this will be changed in a future release, where it will be switched to enabled by default as well\&.
210 .sp
211 See
212 \fBsystemd.service\fR(5)
213 for a description of variable expansion\&. Disabling variable expansion is useful if the specified command includes or may include a
214 "$"
215 sign\&.
216 .sp
217 Added in version 254\&.
218 .RE
219 .PP
220 \fB\-r\fR, \fB\-\-remain\-after\-exit\fR
221 .RS 4
222 After the service process has terminated, keep the service around until it is explicitly stopped\&. This is useful to collect runtime information about the service after it finished running\&. Also see
223 \fIRemainAfterExit=\fR
224 in
225 \fBsystemd.service\fR(5)\&.
226 .sp
227 Added in version 207\&.
228 .RE
229 .PP
230 \fB\-\-send\-sighup\fR
231 .RS 4
232 When terminating the scope or service unit, send a SIGHUP immediately after SIGTERM\&. This is useful to indicate to shells and shell\-like processes that the connection has been severed\&. Also see
233 \fISendSIGHUP=\fR
234 in
235 \fBsystemd.kill\fR(5)\&.
236 .sp
237 Added in version 207\&.
238 .RE
239 .PP
240 \fB\-\-service\-type=\fR
241 .RS 4
242 Sets the service type\&. Also see
243 \fIType=\fR
244 in
245 \fBsystemd.service\fR(5)\&. This option has no effect in conjunction with
246 \fB\-\-scope\fR\&. Defaults to
247 \fBsimple\fR\&.
248 .sp
249 Added in version 211\&.
250 .RE
251 .PP
252 \fB\-\-uid=\fR, \fB\-\-gid=\fR
253 .RS 4
254 Runs the service process under the specified UNIX user and group\&. Also see
255 \fIUser=\fR
256 and
257 \fIGroup=\fR
258 in
259 \fBsystemd.exec\fR(5)\&.
260 .sp
261 Added in version 211\&.
262 .RE
263 .PP
264 \fB\-\-nice=\fR
265 .RS 4
266 Runs the service process with the specified nice level\&. Also see
267 \fINice=\fR
268 in
269 \fBsystemd.exec\fR(5)\&.
270 .sp
271 Added in version 211\&.
272 .RE
273 .PP
274 \fB\-\-working\-directory=\fR
275 .RS 4
276 Runs the service process with the specified working directory\&. Also see
277 \fIWorkingDirectory=\fR
278 in
279 \fBsystemd.exec\fR(5)\&.
280 .sp
281 Added in version 240\&.
282 .RE
283 .PP
284 \fB\-\-same\-dir\fR, \fB\-d\fR
285 .RS 4
286 Similar to
287 \fB\-\-working\-directory=\fR, but uses the current working directory of the caller for the service to execute\&.
288 .sp
289 Added in version 240\&.
290 .RE
291 .PP
292 \fB\-E \fR\fB\fINAME\fR\fR\fB[=\fR\fB\fIVALUE\fR\fR\fB]\fR, \fB\-\-setenv=\fR\fB\fINAME\fR\fR\fB[=\fR\fB\fIVALUE\fR\fR\fB]\fR
293 .RS 4
294 Runs the service process with the specified environment variable set\&. This parameter may be used more than once to set multiple variables\&. When
295 "="
296 and
297 \fIVALUE\fR
298 are omitted, the value of the variable with the same name in the program environment will be used\&.
299 .sp
300 Also see
301 \fIEnvironment=\fR
302 in
303 \fBsystemd.exec\fR(5)\&.
304 .sp
305 Added in version 211\&.
306 .RE
307 .PP
308 \fB\-\-pty\fR, \fB\-t\fR
309 .RS 4
310 When invoking the command, the transient service connects its standard input, output and error to the terminal
311 \fBsystemd\-run\fR
312 is invoked on, via a pseudo TTY device\&. This allows running programs that expect interactive user input/output as services, such as interactive command shells\&.
313 .sp
314 This option will result in
315 \fBsystemd\-run\fR
316 synchronously waiting for the transient service to terminate, similar to specifying
317 \fB\-\-wait\fR\&. If specified along with
318 \fB\-\-wait\fR,
319 \fBsystemd\-run\fR
320 will not exit when manually disconnecting from the pseudo TTY device\&.
321 .sp
322 Note that
323 \fBmachinectl\fR(1)\*(Aqs
324 \fBshell\fR
325 command is usually a better alternative for requesting a new, interactive login session on the local host or a local container\&.
326 .sp
327 See below for details on how this switch combines with
328 \fB\-\-pipe\fR\&.
329 .sp
330 Added in version 219\&.
331 .RE
332 .PP
333 \fB\-\-pipe\fR, \fB\-P\fR
334 .RS 4
335 If specified, standard input, output, and error of the transient service are inherited from the
336 \fBsystemd\-run\fR
337 command itself\&. This allows
338 \fBsystemd\-run\fR
339 to be used within shell pipelines\&.
340 .sp
341 Note that this mode is not suitable for interactive command shells and similar, as the service process will not become a TTY controller when invoked on a terminal\&. Use
342 \fB\-\-pty\fR
343 instead in that case\&.
344 .sp
345 When both
346 \fB\-\-pipe\fR
347 and
348 \fB\-\-pty\fR
349 are used in combination the more appropriate option is automatically determined and used\&. Specifically, when invoked with standard input, output and error connected to a TTY
350 \fB\-\-pty\fR
351 is used, and otherwise
352 \fB\-\-pipe\fR\&.
353 .sp
354 This option will result in
355 \fBsystemd\-run\fR
356 synchronously waiting for the transient service to terminate, similar to specifying
357 \fB\-\-wait\fR\&.
358 .sp
359 When this option is used the original file descriptors
360 \fBsystemd\-run\fR
361 receives are passed to the service processes as\-is\&. If the service runs with different privileges than
362 \fBsystemd\-run\fR, this means the service might not be able to reopen the passed file descriptors, due to normal file descriptor access restrictions\&. If the invoked process is a shell script that uses the
363 \fBecho "hello" >/dev/stderr\fR
364 construct for writing messages to stderr, this might cause problems, as this only works if stderr can be reopened\&. To mitigate this use the construct
365 \fBecho "hello" >&2\fR
366 instead, which is mostly equivalent and avoids this pitfall\&.
367 .sp
368 Added in version 235\&.
369 .RE
370 .PP
371 \fB\-\-shell\fR, \fB\-S\fR
372 .RS 4
373 A shortcut for
374 "\-\-pty \-\-same\-dir \-\-wait \-\-collect \-\-service\-type=exec $SHELL", i\&.e\&. requests an interactive shell in the current working directory, running in service context, accessible with a single switch\&.
375 .sp
376 Added in version 240\&.
377 .RE
378 .PP
379 \fB\-\-quiet\fR, \fB\-q\fR
380 .RS 4
381 Suppresses additional informational output while running\&. This is particularly useful in combination with
382 \fB\-\-pty\fR
383 when it will suppress the initial message explaining how to terminate the TTY connection\&.
384 .sp
385 Added in version 219\&.
386 .RE
387 .PP
388 \fB\-\-on\-active=\fR, \fB\-\-on\-boot=\fR, \fB\-\-on\-startup=\fR, \fB\-\-on\-unit\-active=\fR, \fB\-\-on\-unit\-inactive=\fR
389 .RS 4
390 Defines a monotonic timer relative to different starting points for starting the specified command\&. See
391 \fIOnActiveSec=\fR,
392 \fIOnBootSec=\fR,
393 \fIOnStartupSec=\fR,
394 \fIOnUnitActiveSec=\fR
395 and
396 \fIOnUnitInactiveSec=\fR
397 in
398 \fBsystemd.timer\fR(5)
399 for details\&. These options are shortcuts for
400 \fB\-\-timer\-property=\fR
401 with the relevant properties\&. These options may not be combined with
402 \fB\-\-scope\fR
403 or
404 \fB\-\-pty\fR\&.
405 .sp
406 Added in version 218\&.
407 .RE
408 .PP
409 \fB\-\-on\-calendar=\fR
410 .RS 4
411 Defines a calendar timer for starting the specified command\&. See
412 \fIOnCalendar=\fR
413 in
414 \fBsystemd.timer\fR(5)\&. This option is a shortcut for
415 \fB\-\-timer\-property=OnCalendar=\fR\&. This option may not be combined with
416 \fB\-\-scope\fR
417 or
418 \fB\-\-pty\fR\&.
419 .sp
420 Added in version 218\&.
421 .RE
422 .PP
423 \fB\-\-on\-clock\-change\fR, \fB\-\-on\-timezone\-change\fR
424 .RS 4
425 Defines a trigger based on system clock jumps or timezone changes for starting the specified command\&. See
426 \fIOnClockChange=\fR
427 and
428 \fIOnTimezoneChange=\fR
429 in
430 \fBsystemd.timer\fR(5)\&. These options are shortcuts for
431 \fB\-\-timer\-property=OnClockChange=yes\fR
432 and
433 \fB\-\-timer\-property=OnTimezoneChange=yes\fR\&. These options may not be combined with
434 \fB\-\-scope\fR
435 or
436 \fB\-\-pty\fR\&.
437 .sp
438 Added in version 242\&.
439 .RE
440 .PP
441 \fB\-\-path\-property=\fR, \fB\-\-socket\-property=\fR, \fB\-\-timer\-property=\fR
442 .RS 4
443 Sets a property on the path, socket, or timer unit that is created\&. This option is similar to
444 \fB\-\-property=\fR, but applies to the transient path, socket, or timer unit rather than the transient service unit created\&. This option takes an assignment in the same format as
445 \fBsystemctl\fR(1)\*(Aqs
446 \fBset\-property\fR
447 command\&. These options may not be combined with
448 \fB\-\-scope\fR
449 or
450 \fB\-\-pty\fR\&.
451 .sp
452 Added in version 218\&.
453 .RE
454 .PP
455 \fB\-\-no\-block\fR
456 .RS 4
457 Do not synchronously wait for the unit start operation to finish\&. If this option is not specified, the start request for the transient unit will be verified, enqueued and
458 \fBsystemd\-run\fR
459 will wait until the unit\*(Aqs start\-up is completed\&. By passing this argument, it is only verified and enqueued\&. This option may not be combined with
460 \fB\-\-wait\fR\&.
461 .sp
462 Added in version 220\&.
463 .RE
464 .PP
465 \fB\-\-wait\fR
466 .RS 4
467 Synchronously wait for the transient service to terminate\&. If this option is specified, the start request for the transient unit is verified, enqueued, and waited for\&. Subsequently the invoked unit is monitored, and it is waited until it is deactivated again (most likely because the specified command completed)\&. On exit, terse information about the unit\*(Aqs runtime is shown, including total runtime (as well as CPU, memory, IO, and IP accounting data, if the corresponding cgroup accounting settings are enabled) and the exit code and status of the main process\&. This output may be suppressed with
468 \fB\-\-quiet\fR\&. This option may not be combined with
469 \fB\-\-no\-block\fR,
470 \fB\-\-scope\fR
471 or the various path, socket, or timer options\&.
472 .sp
473 Added in version 232\&.
474 .RE
475 .PP
476 \fB\-G\fR, \fB\-\-collect\fR
477 .RS 4
478 Unload the transient unit after it completed, even if it failed\&. Normally, without this option, all units that ran and failed are kept in memory until the user explicitly resets their failure state with
479 \fBsystemctl reset\-failed\fR
480 or an equivalent command\&. On the other hand, units that ran successfully are unloaded immediately\&. If this option is turned on the "garbage collection" of units is more aggressive, and unloads units regardless if they exited successfully or failed\&. This option is a shortcut for
481 \fB\-\-property=CollectMode=inactive\-or\-failed\fR, see the explanation for
482 \fICollectMode=\fR
483 in
484 \fBsystemd.unit\fR(5)
485 for further information\&.
486 .sp
487 Added in version 236\&.
488 .RE
489 .PP
490 \fB\-\-ignore\-failure\fR
491 .RS 4
492 By default, if the specified command fails the invoked unit will be marked failed (though possibly still unloaded, see
493 \fB\-\-collect=\fR, above), and this is reported in the logs\&. If this switch is specified this is suppressed and any non\-success exit status/code of the command is treated as success\&.
494 .sp
495 Added in version 256\&.
496 .RE
497 .PP
498 \fB\-\-background=\fR\fB\fICOLOR\fR\fR
499 .RS 4
500 Change the terminal background color to the specified ANSI color as long as the session lasts\&. The color specified should be an ANSI X3\&.64 SGR background color, i\&.e\&. strings such as
501 "40",
502 "41", \&...,
503 "47",
504 "48;2;\&...",
505 "48;5;\&..."\&. See
506 \m[blue]\fBANSI Escape Code (Wikipedia)\fR\m[]\&\s-2\u[1]\d\s+2
507 for details\&.
508 .sp
509 Added in version 256\&.
510 .RE
511 .PP
512 \fB\-\-user\fR
513 .RS 4
514 Talk to the service manager of the calling user, rather than the service manager of the system\&.
515 .RE
516 .PP
517 \fB\-\-system\fR
518 .RS 4
519 Talk to the service manager of the system\&. This is the implied default\&.
520 .RE
521 .PP
522 \fB\-H\fR, \fB\-\-host=\fR
523 .RS 4
524 Execute the operation remotely\&. Specify a hostname, or a username and hostname separated by
525 "@", to connect to\&. The hostname may optionally be suffixed by a port ssh is listening on, separated by
526 ":", and then a container name, separated by
527 "/", which connects directly to a specific container on the specified host\&. This will use SSH to talk to the remote machine manager instance\&. Container names may be enumerated with
528 \fBmachinectl \-H \fR\fB\fIHOST\fR\fR\&. Put IPv6 addresses in brackets\&.
529 .RE
530 .PP
531 \fB\-M\fR, \fB\-\-machine=\fR
532 .RS 4
533 Execute operation on a local container\&. Specify a container name to connect to, optionally prefixed by a user name to connect as and a separating
534 "@"
535 character\&. If the special string
536 "\&.host"
537 is used in place of the container name, a connection to the local system is made (which is useful to connect to a specific user\*(Aqs user bus:
538 "\-\-user \-\-machine=lennart@\&.host")\&. If the
539 "@"
540 syntax is not used, the connection is made as root user\&. If the
541 "@"
542 syntax is used either the left hand side or the right hand side may be omitted (but not both) in which case the local user name and
543 "\&.host"
544 are implied\&.
545 .RE
546 .PP
547 \fB\-C\fR, \fB\-\-capsule=\fR
548 .RS 4
549 Execute operation on a capsule\&. Specify a capsule name to connect to\&. See
550 \[email protected]\fR(5)
551 for details about capsules\&.
552 .sp
553 Added in version 256\&.
554 .RE
555 .PP
556 \fB\-\-no\-ask\-password\fR
557 .RS 4
558 Do not query the user for authentication for privileged operations\&.
559 .RE
560 .PP
561 \fB\-h\fR, \fB\-\-help\fR
562 .RS 4
563 Print a short help text and exit\&.
564 .RE
565 .PP
566 \fB\-\-version\fR
567 .RS 4
568 Print a short version string and exit\&.
569 .RE
570 .PP
571 \fB\-\-json=\fR\fB\fIMODE\fR\fR
572 .RS 4
573 Shows output formatted as JSON\&. Expects one of
574 "short"
575 (for the shortest possible output without any redundant whitespace or line breaks),
576 "pretty"
577 (for a pretty version of the same, with indentation and line breaks) or
578 "off"
579 (to turn off JSON output, the default)\&.
580 .RE
581 .PP
582 All command line arguments after the first non\-option argument become part of the command line of the launched process\&.
583 .SH "EXIT STATUS"
584 .PP
585 On success, 0 is returned\&. If
586 \fBsystemd\-run\fR
587 failed to start the service, a non\-zero return value will be returned\&. If
588 \fBsystemd\-run\fR
589 waits for the service to terminate, the return value will be propagated from the service\&. 0 will be returned on success, including all the cases where systemd considers a service to have exited cleanly, see the discussion of
590 \fISuccessExitStatus=\fR
591 in
592 \fBsystemd.service\fR(5)\&.
593 .SH "EXAMPLES"
594 .PP
595 \fBExample\ \&1.\ \&Logging environment variables provided by systemd to services\fR
596 .sp
597 .if n \{\
598 .RS 4
599 .\}
600 .nf
601 # systemd\-run env
602 Running as unit: run\-19945\&.service
603 # journalctl \-u run\-19945\&.service
604 Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env\&.\&.\&.
605 Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env\&.
606 Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
607 Sep 08 07:37:21 bupkis env[19948]: LANG=en_US\&.UTF\-8
608 Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz\-3\&.11\&.0\-0\&.rc5\&.git6\&.2\&.fc20\&.x86_64
609 .fi
610 .if n \{\
611 .RE
612 .\}
613 .PP
614 \fBExample\ \&2.\ \&Limiting resources available to a command\fR
615 .sp
616 .if n \{\
617 .RS 4
618 .\}
619 .nf
620 # systemd\-run \-p IOWeight=10 updatedb
621 .fi
622 .if n \{\
623 .RE
624 .\}
625 .PP
626 This command invokes the
627 \fBupdatedb\fR(8)
628 tool, but lowers the block I/O weight for it to 10\&. See
629 \fBsystemd.resource-control\fR(5)
630 for more information on the
631 \fIIOWeight=\fR
632 property\&.
633 .PP
634 \fBExample\ \&3.\ \&Running commands at a specified time\fR
635 .PP
636 The following command will touch a file after 30 seconds\&.
637 .sp
638 .if n \{\
639 .RS 4
640 .\}
641 .nf
642 # date; systemd\-run \-\-on\-active=30 \-\-timer\-property=AccuracySec=100ms /bin/touch /tmp/foo
643 Mon Dec 8 20:44:24 KST 2014
644 Running as unit: run\-71\&.timer
645 Will run service as unit: run\-71\&.service
646 # journalctl \-b \-u run\-71\&.timer
647 \-\- Journal begins at Fri 2014\-12\-05 19:09:21 KST, ends at Mon 2014\-12\-08 20:44:54 KST\&. \-\-
648 Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo\&.
649 Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo\&.
650 # journalctl \-b \-u run\-71\&.service
651 \-\- Journal begins at Fri 2014\-12\-05 19:09:21 KST, ends at Mon 2014\-12\-08 20:44:54 KST\&. \-\-
652 Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo\&.\&.\&.
653 Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo\&.
654 .fi
655 .if n \{\
656 .RE
657 .\}
658 .PP
659 \fBExample\ \&4.\ \&Allowing access to the tty\fR
660 .PP
661 The following command invokes
662 \fBbash\fR(1)
663 as a service passing its standard input, output and error to the calling TTY\&.
664 .sp
665 .if n \{\
666 .RS 4
667 .\}
668 .nf
669 # systemd\-run \-t \-\-send\-sighup bash
670 .fi
671 .if n \{\
672 .RE
673 .\}
674 .PP
675 \fBExample\ \&5.\ \&Start screen as a user service\fR
676 .sp
677 .if n \{\
678 .RS 4
679 .\}
680 .nf
681 $ systemd\-run \-\-scope \-\-user screen
682 Running scope as unit run\-r14b0047ab6df45bfb45e7786cc839e76\&.scope\&.
683
684 $ screen \-ls
685 There is a screen on:
686 492\&.\&.laptop (Detached)
687 1 Socket in /var/run/screen/S\-fatima\&.
688 .fi
689 .if n \{\
690 .RE
691 .\}
692 .PP
693 This starts the
694 \fBscreen\fR
695 process as a child of the
696 \fBsystemd \-\-user\fR
697 process that was started by
698 user@\&.service, in a scope unit\&. A
699 \fBsystemd.scope\fR(5)
700 unit is used instead of a
701 \fBsystemd.service\fR(5)
702 unit, because
703 \fBscreen\fR
704 will exit when detaching from the terminal, and a service unit would be terminated\&. Running
705 \fBscreen\fR
706 as a user unit has the advantage that it is not part of the session scope\&. If
707 \fIKillUserProcesses=yes\fR
708 is configured in
709 \fBlogind.conf\fR(5), the default, the session scope will be terminated when the user logs out of that session\&.
710 .PP
711 The
712 user@\&.service
713 is started automatically when the user first logs in, and stays around as long as at least one login session is open\&. After the user logs out of the last session,
714 user@\&.service
715 and all services underneath it are terminated\&. This behavior is the default, when "lingering" is not enabled for that user\&. Enabling lingering means that
716 user@\&.service
717 is started automatically during boot, even if the user is not logged in, and that the service is not terminated when the user logs out\&.
718 .PP
719 Enabling lingering allows the user to run processes without being logged in, for example to allow
720 \fBscreen\fR
721 to persist after the user logs out, even if the session scope is terminated\&. In the default configuration, users can enable lingering for themselves:
722 .sp
723 .if n \{\
724 .RS 4
725 .\}
726 .nf
727 $ loginctl enable\-linger
728 .fi
729 .if n \{\
730 .RE
731 .\}
732 .PP
733 \fBExample\ \&6.\ \&Variable expansion by the manager\fR
734 .sp
735 .if n \{\
736 .RS 4
737 .\}
738 .nf
739 $ systemd\-run \-t echo "<${INVOCATION_ID}>" \*(Aq<${INVOCATION_ID}>\*(Aq
740 <> <5d0149bfa2c34b79bccb13074001eb20>
741 .fi
742 .if n \{\
743 .RE
744 .\}
745 .PP
746 The first argument is expanded by the shell (double quotes), but the second one is not expanded by the shell (single quotes)\&.
747 \fBecho\fR(1)
748 is called with ["/usr/bin/echo",
749 "<>",
750 "<${INVOCATION_ID}>"] as the argument array, and then
751 \fBsystemd\fR(1)
752 generates
753 \fI${INVOCATION_ID}\fR
754 and substitutes it in the command\-line\&. This substitution could not be done on the client side, because the target ID that will be set for the service is not known before the call is made\&.
755 .PP
756 \fBExample\ \&7.\ \&Variable expansion and output redirection using a shell\fR
757 .PP
758 Variable expansion by
759 \fBsystemd\fR(1)
760 can be disabled with
761 \fI\-\-expand\-environment=no\fR\&.
762 .PP
763 Disabling variable expansion can be useful if the command to execute contains dollar characters and escaping them would be inconvenient\&. For example, when a shell is used:
764 .sp
765 .if n \{\
766 .RS 4
767 .\}
768 .nf
769 $ systemd\-run \-\-expand\-environment=no \-t bash \e
770 \-c \*(Aqecho $SHELL $$ >/dev/stdout\*(Aq
771 /bin/bash 12345
772 .fi
773 .if n \{\
774 .RE
775 .\}
776 .PP
777 The last argument is passed verbatim to the
778 \fBbash\fR(1)
779 shell which is started by the service unit\&. The shell expands
780 "$SHELL"
781 to the path of the shell, and
782 "$$"
783 to its process number, and then those strings are passed to the
784 \fBecho\fR
785 built\-in and printed to standard output (which, in this case, is connected to the calling terminal)\&.
786 .PP
787 \fBExample\ \&8.\ \&Return value\fR
788 .sp
789 .if n \{\
790 .RS 4
791 .\}
792 .nf
793 $ systemd\-run \-\-user \-\-wait true
794 $ systemd\-run \-\-user \-\-wait \-p SuccessExitStatus=11 bash \-c \*(Aqexit 11\*(Aq
795 $ systemd\-run \-\-user \-\-wait \-p SuccessExitStatus=SIGUSR1 \-\-expand\-environment=no \e
796 bash \-c \*(Aqkill \-SIGUSR1 $$\*(Aq
797 .fi
798 .if n \{\
799 .RE
800 .\}
801 .PP
802 Those three invocations will succeed, i\&.e\&. terminate with an exit code of 0\&.
803 .SH "SEE ALSO"
804 .PP
805 \fBsystemd\fR(1), \fBsystemctl\fR(1), \fBsystemd.unit\fR(5), \fBsystemd.service\fR(5), \fBsystemd.scope\fR(5), \fBsystemd.slice\fR(5), \fBsystemd.exec\fR(5), \fBsystemd.resource-control\fR(5), \fBsystemd.timer\fR(5), \fBsystemd-mount\fR(1), \fBmachinectl\fR(1), \fBrun0\fR(1)
806 .SH "NOTES"
807 .IP " 1." 4
808 ANSI Escape Code (Wikipedia)
809 .RS 4
810 \%https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
811 .RE