I'm facing a weird problem, I have a script like this one :

ifconfig eth0 up
sleep 2
systemctl start openvpn@client.service

If eth0 is down prior to calling this script then openvpn will fail to connect. journalctl returns

openvpn Control process exited code exited status=1, Failed to start OpenVPN connection to client

However if I rerun this same script a second time with eth0 being up from the first call, it works just fine.. Any idea what is happening and how to fix this ?

  • 1
    Could you add a line like ifconfig -a > /tmp/script.log (or preferably ip addr show > /tmp/script.log) just after sleep 2? It will allow to find if the interface if actually coming up in 2 seconds. If that is the problem it can be easily fixed by making a systemd dependency chain. – grochmal Jul 30 '16 at 15:56
  • @grochmal it goes up but doesn't seem to acquire a link and inet ip. After the script ends with the systemctl error message the IP gets acquired on that interface. – ChiseledAbs Jul 30 '16 at 16:06
  • @Yeah waiting 10 sec for it to acquire an ip works. Btw how would you do a systemd chain ? How to do a chain based on the interface having an inet ? – ChiseledAbs Jul 30 '16 at 16:23
  • Next question, is there a reason why you start the interface manually? e.g. you plug a cable and then start the VPN? (it might be easier to force an interface up whenever a cable is connected.) Also what is your distro (different distros use different things for network services)? – grochmal Jul 30 '16 at 16:26
  • @grochmal I'm starting manually because I have a script to shutdown internet (ifconfig down, openvpn off) just want this to get to work. I'm under arch. I'm going to write a loop to stall until inet gets up but I'm interested in how to get this done via systemd – ChiseledAbs Jul 30 '16 at 16:30

Arch is great for that kind of configuration. Yet, you should really not be using ifconfig on Arch, it had switched to iproute2 a long time ago, and it is considerably better to do:

ip link set dev eth0 up
dhcpcd eth0

("Better" because you have two steps and you know exactly which step fails. Also, I believe you do not have eth0 but something like enp1s0 but that's a minor detail.)

Anyhow, instead of ifconfig eth0 you can start a wired interface with:

systemctl start netctl-auto@eth0.service

And then you can simply change the openvpn service, first copy the service file:

cp /usr/lib/systemd/system/openvpn@.service /etc/systemd/system/openvpn@.service

And then change it (the copy) to:


(That is not too much of a hack, even arch wiki suggests this. There is a dispute over that article because it uses the /usr/lib/systemd file, so I adapted the answer to make it the proper way by copying it first)

Now you should be able to start the VPN with

systemctl start openvpn@client.service

and the network will be started first. And stop both with:

systemctl stop netctl-auto@eth0.service
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.