1

I have many service unit files that I have to restart, and I don't want to have to type them all out. Is it possible to have a single target or service that doesn't know anything about how to launch the other services, but groups them together so they're all restarted with a single command?

How do I write my systemd service unit file or target file if I want to systemctl restart one-to-rule-them-all?

Requirements: 1. The uber target wants many other services to be started. 2. The uber target should not know anything about how to start those services.

When I tried this sudo systemctl restart one-to-rule.target nothing happens.

# /etc/systemd/system/one-to-rule.target
[Unit]
Description=One To Rule Them All
Requires=multi-user.target
Wants=program-api.service  program-gui.service yet-another.service
After=multi-user.target display-manager.service

[Install]
WantedBy=graphical.target

Each of these units program-api.service program-gui.service yet-another.service and one-to-rule.target were all enabled, and they all seem to be loaded and active. I can boot the machine, and the services all come up exactly how I want them. However, I just want to type systemctl restart one-to-rule.target or something, instead of rebooting.

The dependency graphs look like this

$ systemctl list-dependencies one-to-rule.target
one-to-rule.target
● ├─program-api.service
● ├─program-gui.service
● ├─yet-another.service
● └─multi-user.target

$ systemctl list-dependencies --reverse one-to-rule.target
one-to-rule.target
● └─graphical.target

1 Answer 1

3

This can work, but each of those .service units must have PartOf=one-to-rule.target in order to have restarts propagated to them. (This is actually just a weaker version of Requires=<…>.target.)

Unfortunately it is not possible to specify the opposite dependency (ConsistsOf) directly in the target – you need to extend all service files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .