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