大网数据广告活动
服务器运维问答

Systemd: Restart all instances of an Instantiated Service at once

· 52CE 我爱测

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 autoss…

问题原文

原帖链接 · guettli · CC BY-SA 4.0

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

已采纳解答

原帖链接 · weirdan · CC BY-SA 3.0

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@*'

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-11-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。