Systemd dependency not working
Hello,
I am fighting trying to make a dependency between services to work properly. I've looked everywhere and it looks like I'm doing the right thing (at least based on what everyone is saying on how it should be achieved), but unfortunately, it is not working. I want to have my TEST service only run whenever the openvpn.service is running. Unfortunately, it does not stop when I kill the VPN, for example. Code:
[Unit] Thanks a lot |
One of the main ideas behind systemd was automatic dependency resolution, so I'm not sure the "Requires=openvpn.service" line is valid (but I could be wrong).
The "After=openvpn.service" line means don't run your service until the "openvpn.service" has started, if my understanding is correct. I hope you haven't got the "Any help would be appreciated." line in your service, because that is most certainly not valid. The output you have given won't do what your asking, if I'm understanding your goal correctly. |
Thanks. I corrected the code :-).
I understood that Requires=... ensures that the service of the [UNIT] (TEST in my case) is running only when the "required" service is running (openvpn in my case). I have the same understanding as you for the After=... line. What would you then recommend that I try if I want to: - start openvpn at startup or if down (added "Restart=always" line in the openvpn@.service [SERVICE] section. I tried and it does work) - start TEST after openvpn has started - do not start TEST if openvpn cannot start - stop TEST if openvpn stops running It should be a unidirectional command: only start/stop TEST when openvpn is up/down. I do not want to have openvpn depend on the TEST service status. |
I think you could add the "PartOf=<service name here>" keyword there, if you want your service to stop when the openvpn service does.
Here's a link that explains it: https://stackoverflow.com/questions/...ervice-crashes (look down the bottom of that same link) |
I read the very same thread and tried this already, without success :-(. Same for "BindsTo=openvpn.service".
|
You could have a look at this thread. From what I read, it looks like it might be "BindsTo=<service name here>" that you need instead.
Let us know how it works out. |
Sorry for the typo. I tried to replace "Requires=" by "BindsTo=" as well (saw this post too :-)). Does not work.
|
Quote:
Quote:
jsb has given you plenty hints, now you need show us something to work with. commands issued, journal excerpts, systemctl status etc. and continue reading that documentation: Code:
man -K bindsto |
Quote:
I can recap what I did: 1- I stopped TEST manually. 2- I edited the [UNIT] section Code:
[Unit] 3- I reloaded TEST and restarted it manually. 4- I stopped the VPN: Code:
sudo pkill openvpn I did the same by replacing then "PartOf= openvpn.service" by "BindsTo= openvpn.service" without succeeding in making TEST stop. When the VPN is running this is the status: Code:
sudo systemctl status openvpn Code:
sudo systemctl status openvpn Code:
curl ipconfig.me/host Just let me know what you would like to see (and how to proceed...my knowledge is limited as I said). Thanks in advance. |
You need to make sure the openvpn service is stopped, if the actual service is still running, it won't matter what you have in your service file.
|
Quote:
and pease don't paraphrase, show us each command and the output it generated. i am particularly unsure about "I reloaded TEST and restarted it manually". and i think you should look at a unit's staus everytime you change something. btw, arch wiki has very good systemd documentation. recommend, even if you use another distro. all that said, not everything needs to be accomplished by systemd alone, as i already pointed out. |
Alright. I need then some further insight: what's the difference between "killing" and "stopping" a service ?
When I "kill" the VPN, the service seems to remain ACTIVE while the IP address is the one without VPN (90.x.x.x). When I "stop" the VPN, the service seems to be INACTIVE while the IP address is the one of the VPN (185.x.x.x) !!! (therefore, to me it looked like the VPN is still running) Here is the status after "stopping" the service with the following command: Code:
sudo systemcl stop openvpn Code:
sudo systemctl status openvpn But then, when I want to restart my VPN with Code:
sudo systemcl start openvpn Code:
sudo openvpn --config /etc/openvpn/VPN1.conf Code:
Sat Feb 23 18:02:08 2019 Initialization Sequence Completed |
You "kill" a process, you "stop" a service. Your service stopped because you actually stopped the openvpn service. Which was why it wasn't working for you before, because you had not stopped the openvpn service.
A running process is when you start an app, it may only have one process, it may have several - it depends on the app. So if you started Firefox, you would see "firefox" in your list of running processes. The operating system manages running processes. A service is something that runs in the background, and is managed by an init system (like systemd, but could be another init system depending on which Linux distribution it is you are talking about). |
Thank you. That's clearer but I still have multiple confusions/questions.
1- How can OPENVPN service be stopped but the VPN still running ? - I would have still expected that the process would be killed at the same time. 2- Actually, that makes me think that what I 'm trying to get to is a dependency with the VPN connection and not with the OPENVPN service. Because I want to stop TEST from running whenever the VPN connection is lost. It might never be the case that the OPENVPN service will be down, while it will surely happen that the VPN connection will be lost. Any idea how to do this ? 3- Any idea about why I cannot restart my VPN connection manually ? Thank you. |
you need to read a good systemd tutorial or documentation.
i recommend https://wiki.archlinux.org/index.php/Systemd |
All times are GMT -5. The time now is 05:54 PM. |