wiki/notebook/linux.systemd.transient-units.org
2022-11-23 17:57:59 +08:00

1.6 KiB

systemd transient units

You can create units on-the-go with systemd-run. Very useful for quickly creating and scheduling one-off services. Among other things, this can easily create systemd services, systemd timers, and roam:systemd path units which can be interacted with systemd tools as usual.

Like most systemd-related binaries, this can be run at system- and user-level (see systemd at user-level).

# This will create a user-level service file with the given command as the task.
systemd-run --user borgmatic --config emergency-config.yaml --verbose

# Create a transient timer for a unit.  This is useful for one-off scheduling
# for a certain service.
systemd-run --user --unit borg-backup@external-drive.service --on-calendar=12:00

# Create a transient path unit. This is useful for situations such as debugging
# configurations that is being used by a service. Take note, it does not
# properly escape unit specifiers and will not be considered an absolute path.
systemd-run --user --unit bspwm.service --path-property="PathChanged=${XDG_CONFIG_HOME}/bspwmrc"

The result should give you the generated name of the unit. Then, they can be managed like an ordinary unit. Unit generated this way will persist until the next boot. If you want to manage them on a permanent basis, create the appropriate unit files for them.