binhex / arch-qbittorrentvpn

Docker build script for Arch Linux base with qBittorrent, Privoxy and OpenVPN
GNU General Public License v3.0
397 stars 46 forks source link

Run Script on Wireguard Startup #146

Open spencerhughes opened 1 year ago

spencerhughes commented 1 year ago

Is it possible to run a user-defined script at during the Wireguard post-up? Something functionally equivalent to -e VPN_OPTIONS=--up /path/to/script/tun_up.sh for OpenVPN? There are some commands I need to run once the tunnel has connected from within the container, and I see that the Wireguard config already calls a PostUp script so I didn't want to mess with that script for forwards compatibility reasons.

ethw commented 11 months ago

+1, I need this as well.

There is a way to do it but it doesn't stick. If you edit /root/wireguardup.sh in the container to include your custom script then you can run logic after wireguard connection. But whenever the container gets recreated it resets /root making this an annoying manual fix to apply.

There's a better fix than using VPN_OPTIONS, since I don't think wireguard has an --up equivalent.

Ideally the wg0.conf file would not override custom added PostUp lines. Then you could just add your own PostUp config to do this.

@binhex is this possible to add? I would greatly appreciate it.

aemla commented 10 months ago

+1, I need this as well.

There is a way to do it but it doesn't stick. If you edit /root/wireguardup.sh in the container to include your custom script then you can run logic after wireguard connection. But whenever the container gets recreated it resets /root making this an annoying manual fix to apply.

There's a better fix than using VPN_OPTIONS, since I don't think wireguard has an --up equivalent.

Ideally the wg0.conf file would not override custom added PostUp lines. Then you could just add your own PostUp config to do this.

@binhex is this possible to add? I would greatly appreciate it.

I need this as well @binhex. This would resolve all the compatibility issues on Synology NAS: https://www.derekseaman.com/2022/12/using-wireguard-with-your-synology-docker-containers.html

aemla commented 10 months ago

I have found a fix. You can stop overwriting of wg0.conf by mapping wireguard folder read only: -v /root/docker/config/wireguard:/config/wireguard:ro

All mapped config volumes should look like this:

-v /root/docker/config/wireguard:/config/wireguard:ro
-v /root/docker/config:/config
snowlucas commented 7 months ago

I've just tried your solution on truenas and unfortunately making that folder read only leads to the /root/wireguardup.sh not running and the web interface never coming up. Would be great to have script support for wireguard if this is possible.

spencerhughes commented 7 months ago

I feel like wireguardup.sh could call out to another script based on environment variable, e.g. WIREGUARD_POSTUP_SCRIPT=/path/to/script.sh and wireguardup.sh could have if WIREGUARD_POSTUP_SCRIPT != null then sh $WIREGUARD_POSTUP_SCRIPT or something (excuse by bad pseudocode).

voc0der commented 5 months ago

Subscribing to this, also would like it for privoxyvpn, etc