linux – 有没有办法将两个实例化的systemd服务作为一个单元进行控制?

前端之家收集整理的这篇文章主要介绍了linux – 有没有办法将两个实例化的systemd服务作为一个单元进行控制?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些 python Web服务,我正试图在Fedora 15机器上运行.它们由paster运行,启动它们的唯一区别是它们读取的配置文件.

这似乎非常适合systemd的实例化服务,但我希望能够将它们作为一个单元进行控制.需要两种服务的系统目标似乎是接近它的方法.启动目标会启动两个服务,但停止目标会使它们继续运行.

这是服务文件

[Unit]
Description=AUI Instance on Port %i
After=syslog.target

[Service]
WorkingDirectory=/usr/local/share/aui
ExecStart=/opt/cogo/bin/paster serve --log-file=/var/log/aui/%i deploy-%i.ini        
Restart=always
RestartSec=2
User=aui
Group=aui

[Install]
WantedBy=multi-user.target

这是目标文件

[Unit]                    
Description=AUI           
Requires=aui@5001.service
Requires=aui@5002.service
After=syslog.target   

[Install]                 
WantedBy=multi-user.target

这种分组甚至可以用systemd吗?

解决方法

看看使用BindsTo选项将单元绑定在一起. systemd.unit(5)手册页描述如下:

BindsTo=

Configures requirement dependencies,very similar in style to
Requires=,however in addition to this behavior,it also declares that
this unit is stopped when any of the units listed suddenly disappears.
Units can suddenly,unexpectedly disappear if a service terminates on
its own choice,a device is unplugged or a mount point unmounted
without involvement of systemd.

这听起来应该做你想做的事情并将一个单元绑定到另一个单元,这样每当主设备停止从设备停止时,反之亦然,以便启动.

不要忘记您也可以使用Before / After来指定必要时应该开始的顺序.

原文链接:https://www.f2er.com/linux/399805.html

猜你在找的Linux相关文章