I am using raspbian. (Debian variant).
By default, openvpn is started with /etc/rc2.d/S03openvpn. I set up an
/etc/init.d script with a symlink
/etc/rc2.d/S04daemonname for a daemon I want to start after openvpn has started and a connection to my vpn provider has been established. The openvpn startup and connection works fine. However my daemon that I want to use the vpn connection seems to start up before the connection is established, since it uses my standard ip. If I kill the daemon and restart it in the terminal, it is then using the desired vpn ip.
How would I make it so my daemon runs at startup once the vpn connection is established? Can I do this by waiting until tun0 device has been created (how?), or is the tun0 creation not synonymous with established connection meaning this might be too early? I've also looked into using the run time dependencies LSB tags in the init.d script, but can't find how to make a certain network device (tun0) a requirement and again, I'm unsure whether this would work. There is also a file in
/etc/NetworkManager/VPN/ referencing the openvpn service, but I'm not sure how to use this or if the NetworkManager daemon is even being used because /VPN is the only subdirectory of it.
I would like solutions that are precise, eg. not just putting my init.d script with a low enough run priority in /etc/rc2.d/ or waiting until the openvpn connection should be established.