Systemd – How to Restart All Instances of an Instantiated Service at Once

systemd

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

Best Answer

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:

systemctl restart 'autossh@*'