12

Is there a way of restarting all instances of a service in systemd using only one command?

Suppose we have two daemons running called thingd@01 and thingd@02. Can I restart just those without having to resort to making one call to systemctl per instance?

bwDraco
  • 45,747
  • 43
  • 165
  • 205
user1096824
  • 123
  • 1
  • 1
  • 5

1 Answers1

28

You should be able to restart both of them with one systemctl, just put a space between the services. E.g. systemctl restart thingd@01 thingd@02

I usually stop all major services before cloning an instance after it has been removed from a load balanced pool. I use the following:

# stop php-fpm, MariaDB, nginx and postfix

systemctl stop php-fpm nginx postfix mariadb

# check status after they have been stopped

systemctl status php-fpm nginx postfix mariadb

# start all of them again

systemctl start php-fpm nginx postfix mariadb
mstephenson
  • 396
  • 4
  • 5
  • 4
    That works! also... `systemctl restart thing@{1..8}` seems to work with it. Thank you @mstephenson. – user1096824 Apr 04 '16 at 22:02
  • @user1096824 if this has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Sufian Jul 19 '19 at 10:39
  • 2
    For stop or restart also possible `systemctl stop 'thing*'`. Also [systemd target](https://www.freedesktop.org/software/systemd/man/systemd.target.html) could be used to group multiple instances. – dess Jan 14 '20 at 22:04