How to restart a service if its dependent service is restarted

前端 未结 3 1482
生来不讨喜
生来不讨喜 2021-02-05 02:41

A service (say bar.service) is dependent on another service (say foo.service), like below

bar\'s service file:

[Unit]
After=foo.service
Requires=foo.serv         


        
3条回答
  •  無奈伤痛
    2021-02-05 03:31

    You can use PartOf.

    [Unit]
    After=foo.service
    Requires=foo.service
    PartOf=foo.service
    

    From the systemd.unit man page:

    PartOf=

    Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.

提交回复
热议问题