You are not logged in.

#1 2013-07-05 17:41:44

zenten
Member
Registered: 2012-03-27
Posts: 21

Systemd and starting another program after OpenVPN finishes connecting

I have a program that I want to launch only when OpenVPN has established a connection.  The problem is it is instead starting too soon, and going out into the Internet first before later using the OpenVPN connection.  I am having it start after OpenVPN with the following two lines in the .service file:

Requires=openvpn@config.service
After=openvpn@config.service

Is there a proper way to have it instead start after OpenVPN finishes its connection?  Right now I manually can start it after systemctl status openvpn@config.service
reports:

Initialization Sequence Completed

But that manually method is very much suboptimal.  I also want to have this other program start at boot which would completely preclude the manual method.

Offline

#2 2013-07-05 17:46:06

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd and starting another program after OpenVPN finishes connecting

What if you use Requisite=openvpn@config.service?  As I understand it, that will ensure that the service is active and running before allowing the next to start...

Additionally, if you want to be able to start the unit manually, without the openvpn.service started (that is by using "systemctl start <whatever>"), then you could use RequisiteOverridable=openvpn@config.service.


Edit: I guess there is also the additional question of whether the unit reports a success after starting the binary or actually making a connection.  I have never used openvpn, so I don't know about this.  But take, for example, the network.target and the network management services.  With the exception of NetworkManager.service (more specifically the NetworkManager-wait-online.service), the service is reported as successful, and the network.target is reached when the daemon itself is started, not when a full connection has been established.  If it reports success before full connection, that will make this much harder.

Last edited by WonderWoofy (2013-07-05 17:50:00)

Offline

#3 2013-07-05 17:53:01

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: Systemd and starting another program after OpenVPN finishes connecting

systemd has no way to know when openvpn has actually finished connecting, only when openvpn has forked (which is probably way before actually connecting). In other words, this can't possibly work with systemd. I suggest you use OpenVPN's built-in functionality to start scripts after the connection is established (--up).

Offline

#4 2013-07-05 18:01:47

zenten
Member
Registered: 2012-03-27
Posts: 21

Re: Systemd and starting another program after OpenVPN finishes connecting

WonderWoofy wrote:

What if you use Requisite=openvpn@config.service?  As I understand it, that will ensure that the service is active and running before allowing the next to start...

Nope, doesn't work with OpenVPN it seems.

65kid wrote:

systemd has no way to know when openvpn has actually finished connecting, only when openvpn has forked (which is probably way before actually connecting). In other words, this can't possibly work with systemd. I suggest you use OpenVPN's built-in functionality to start scripts after the connection is established (--up).

I thought maybe OpenVPN reported something along the lines that WonderWoofy was talking about (I didn't know about Requisite exactly but I wondered if there was something like it).

I see there's a --down command as well, so I guess I'll go with that.  I'll report back if it works properly for me.

Offline

#5 2013-07-05 18:06:14

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd and starting another program after OpenVPN finishes connecting

Yeah, see my edit above.  After posting, I questioned whether openvpn actually reported a full connection or if it simply reported successful starting of the service binary.

Offline

#6 2013-07-18 21:53:49

zenten
Member
Registered: 2012-03-27
Posts: 21

Re: Systemd and starting another program after OpenVPN finishes connecting

I wasn't able to get this to work properly.  I think I'll just set up a socket connection instead of a fully router VPN setup.

Offline

Board footer

Powered by FluxBB