Score:3

How to make service A stop if service B crashes or stops

cn flag

Using system-d: I have 2 services (Service A and Service B). Service B needs Service A to always be running. If service A ever crashes or is stopped, Service B should also be immediately stopped until service A is restored (At which point in time service B should start back up automatically). Is there a directive that can be put into the system.d unit files to force this type of a relationship?

Use case examples:

#1 Nginx and mariaDB

Nginx always needs maria to be running. I don't want to have customers hitting against a web-server which has not DB back-end. Should maria crash, I want nginx to shutdown immediately. Should service be restored back to maria, I want nginx to spring back to life without having to manually restart the nginx process. Therefore, if there is a sporadic and temporary interruption to maria, nginx doesn't serve up bad requests and just let's other nodes in the cluster handle the web request.

#2 Openvpn and web crawler

Web crawler service depends on open vpn. It would be bad to have webcrawler be running without vpn also running. If the openvpn client service is stopped, I want the webcrawler to stop as well automatically. If the openvpn is restored, I want the webcrawler to start working again without needing to be started manually.

in flag
Regarding the first example, would a 503 be better than a 500 from a customer's perspective? A 503 would be bad message from the browser saying the website doesn't exist. A 500 could be captured by the application to show a "fail whale" or something like that letting people know that the site exists but is having a little trouble ...
bac0n avatar
cn flag
Related: [Difference between PartOf and BindsTo](https://pychao.com/2021/02/24/difference-between-partof-and-bindsto-in-a-systemd-unit/)
in flag
In addition to the article posted by @bac0n, you may want to look at modifying the `.service` file(s) for the applications to have `Restart=on-failure` configured. This will ensure that the services are restarted automatically in the event of a debilitating error.
bac0n avatar
cn flag
on #2 I suggest using openvpn own script integration.
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.