Score:0

Restart two Systemd services simulatenously

cn flag

I have two runtime services running on my linux machine. I have it setup so that apt-get update and apt-get upgrade updates the services, in case I've pushed an update to either one.

Now my problem is, that A.service makes an API call to B.service during initialization to retrieve system information. (A.service does stuff, B.service fetches information and exposes the information in form of an API for A.service).

After updating, I have to restart both services, to do so I'm executing 'sudo systemctl restart A.service B.service'. Now A.service fails to initialize because B.Service isn't running yet.

A.service configuration file:

[Unit]
Description=A.service
After=B.service
Requires=B.service

[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/bin/a_service

B.service configuration file:

[Unit]
Description=B.service
Before=A.service

[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/bin/b_service

To my understanding, 'After' and 'Before' should define the startup order. This works fine when rebooting the machine, but I have to make this work with restart as well, because rebooting after every update isn't feasible.

Desired Outcome:

$ sudo systemctl restart A.service B.service

...
Started B.service
Started A.service
...

Is there any way to achieve this? Currently when executing 'systemctl restart A.service B.service, A will start before B and therefore exit with a failure.

vn flag
`sudo systemctl restart B.service && sudo systemctl restart A.service`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.