2023-03-21 03:19:40 +00:00
|
|
|
# systemd-run
|
|
|
|
|
2023-04-21 18:44:59 +01:00
|
|
|
> Run programs in transient scope units, service units, or path-, socket-, or timer-triggered service units.
|
|
|
|
> More information: <https://www.freedesktop.org/software/systemd/man/systemd-run.html>.
|
2023-03-21 03:19:40 +00:00
|
|
|
|
|
|
|
- Start a transient service:
|
|
|
|
|
|
|
|
`sudo systemd-run {{command}} {{argument1 argument2 ...}}`
|
|
|
|
|
|
|
|
- Start a transient service under the service manager of the current user (no privileges):
|
|
|
|
|
|
|
|
`systemd-run --user {{command}} {{argument1 argument2 ...}}`
|
|
|
|
|
|
|
|
- Start a transient service with a custom unit name and description:
|
|
|
|
|
|
|
|
`sudo systemd-run --unit={{name}} --description={{string}} {{command}} {{argument1 argument2 ...}}`
|
|
|
|
|
|
|
|
- Start a transient service that does not get cleaned up after it terminates with a custom environment variable:
|
|
|
|
|
|
|
|
`sudo systemd-run --remain-after-exit --set-env={{name}}={{value}} {{command}} {{argument1 argument2 ...}}`
|
|
|
|
|
|
|
|
- Start a transient timer that periodically runs its transient service (see `man systemd.time` for calendar event format):
|
|
|
|
|
|
|
|
`sudo systemd-run --on-calendar={{calendar_event}} {{command}} {{argument1 argument2 ...}}`
|
2023-04-21 18:44:59 +01:00
|
|
|
|
|
|
|
- Share the terminal with the program (allowing interactive input/output) and make sure the execution details remain after the program exits:
|
|
|
|
|
2023-05-16 14:08:05 +01:00
|
|
|
`systemd-run --remain-after-exit --pty {{command}}`
|
2023-04-21 18:44:59 +01:00
|
|
|
|
|
|
|
- Set properties (e.g. CPUQuota, MemoryMax) of the process and wait until it exits:
|
|
|
|
|
2023-05-16 14:08:05 +01:00
|
|
|
`systemd-run --property MemoryMax={{memory_in_bytes}} --property CPUQuota={{percentage_of_CPU_time}}% --wait {{command}}`
|
2023-04-21 18:44:59 +01:00
|
|
|
|
|
|
|
- Use the program in a shell pipeline:
|
|
|
|
|
2023-05-16 14:08:05 +01:00
|
|
|
`{{command1}} | systemd-run --pipe {{command2}} | {{command3}}`
|