We have different VPNs, so I cannot test your script, and you cannot test mine, but as I don't need this setup for myself and it was just a challenge to get working, then I tested with another simple script, but if that script works, which it does for me, then the portforwarding should also work if not having any errors in the script. Anyway, even my test script wouldn't run properly before making several changes, but these are described below, and of course switch username and paths accordingly and try my test-script first also, instead of your own. Also, have deluged running.
/etc/openvpn/client/pia.conf:
Code: Select all
[...]
script-security 2
up /etc/openvpn/client/delu1
/etc/openvpn/client/delu1:
Code: Select all
#!/usr/bin/bash
/etc/openvpn/client/delu2 &
/etc/openvpn/client/delu2:
Code: Select all
#!/usr/bin/bash
/usr/bin/curl ifconfig.co > /home/martin/iptest.txt
/usr/bin/sudo -u martin /usr/bin/python /usr/bin/deluge-console "config -s listen_ports (10050,10050)"
/etc/systemd/system/openvpn-client@.service.d/override.conf: (You need to make both dir and file)
Code: Select all
[Service]
LimitNPROC=
LimitNPROC=infinity
ProtectHome=
ProtectHome=off
Run:
Now, check if you can see those above lines(from override.conf) at the bottom when running:
Code: Select all
sudo systemctl cat openvpn-client@.service
If you can, then the override is picked up correctly.
Then when testing, then start your vpn with:
Code: Select all
sudo systemctl start openvpn-client@pia
There should now after some secs be a file in your homedir named iptest.txt with the IP in it of your VPN and deluge should now been set to use port 10050. You can run this, to check it went well:
Code: Select all
sudo systemctl status openvpn-client@pia
Then stop the VPN again with:
Code: Select all
sudo systemctl stop openvpn-client@pia
Delete iptest.txt, and now that you know the setup is working, then you can add another working script instead as '/etc/openvpn/client/delu2'.
If not doing this test, then it's harder to know if it's the script or the "setup" that's still wrong.
Good luck
Edit: I deleted some lines from this posts '/etc/systemd/system/openvpn-client@.service.d/override.conf', as I found that some was redundant(won't hurt to include, just unneeded). Of the remaining two options I override, then the first limits the amount of processes you can run which your script would exhaust and hence fail. The second shields your /home partition, which won't work since that's where your profile dir is stored and hence makes deluge-console error out. There's also full of errors and issues posted on the net, where people get tripped up over these default settings in openvpn's systemd-unit.