One of my servers is setup so that it will automatically connect to a VPN after booting up using a systemd service. Now I want to host a systemd socket on this VPN connection. And the socket should also be available after booting up and after the VPN connection is established.
Here is my current application.socket
file:
[Unit]
Description=My Socket on VPN
[Socket]
# 192.168.2.2 is the IP from inside the VPN
ListenStream=192.168.2.2:1234
Accept=true
[Install]
WantedBy=sockets.target
The issue is, that the socket starts too early: The network interface is not yet up so systemd decides that it cannot start my socket.
If I then ssh into the server and do a quick systemctl restart application.socket
it will start up fine, since the network interface is then up and ready to go. But I don't want to ssh into the server everytime I reboot it. What is the way to make sure, that my socket only starts, when the interface is up, ready and configured? I also don't want to listen to 0.0.0.0
and then block all unwanted devices in iptables
.
Things, that I tried so far:
After=vpn-application.service
-> didn't do anything. Looks like the device is still not available for binding to itAfter=sys-devices-virtual-net-<VPN Device>.device
-> The device does not exist at the time, systemd wants to start my socket. So it fails withx/RESOURCE
How do I make my socket wait for the VPN to be up?