I use the nice feature of systemd: Instantiated Services.
Is there a simple way to reload all instantiated services with one call?
Example: I don't want to run all like this:
systemctl restart autossh@foo
systemctl restart autossh@bar
systemctl restart autossh@blu
I tried this, but this does not work
systemctl restart autossh@*
Related: Start N processes with one systemd service file
Update
First I was fascinated by Instantiated Services, but later I realized that running a configuration management tool like Ansible makes more sense. I learned: Keep the tools simple. Many tools starts to implement condition-checking (if .. else ...) and loops. For example webservers or mailserver congfiguration. But this should be solved at a different (upper) level: configuration management. See: https://github.com/guettli/programming-guidelines#dont-use-systemd-instantiated-units
Systemd (starting from systemd-209) supports wildcards, however your shell is likely trying to expand them. Use quotes to pass wildcards to the systemctl/service command verbatim:
@weirdan Answer is correct, but is missing something for certain distributions.
For Centos 7 and similar, you can do:
BUT, (start) will work ONLY, if you specify the flag "--all" :
Otherwise, it will not find the services, since they do not exist. This is systemd intended feature.
For Ubuntu based systems, it works pretty much the same way, but the difference is, that the "--all" flag must be specified for all of the systemctl arguments, otherwise it will not do anything.
Not nice, but this works for systems with an old systemd:
Of course the solution from above answer (
systemctl restart 'autossh@*'
) is better.I don't know if it's there an option for a wildcard on the terminal for systemd. The what you can do is adding one on your systemd scripts.
The %i would do the trick I think but is related on the way you scripted the instantiated services.
You may find an explanation here referred as specifiers
which shows that:
I'm not directly answering your question, but for what I guess you are trying to achieve. If you think your solution may be found following this idea, please share your systemd script, so we can eventually illustrate with examples and maybe even providing you the final script.
If you feel confident in editing your own script to reach a solution that way, here you have an example (I won't quote it as I don't know if it is relevant for the solution, and is too specific to what I'm proposing)