thrnz/docker-wireguard-pia

Custom Scripts

MitchTalmadge opened this issue · 4 comments

Hey there. I love this repo, it is very useful. Thanks for your work on it.

Summary

I would like to consider adding support for custom scripts written by the end user, to be run at various points in this container's lifecycle.

Suggested Implementation

  1. pre-up.sh Runs before WireGuard is brought up or iptables rules are created; essentially runs right away on container start.
  2. post-up.sh Runs after WireGuard is brought up and iptables rules are established, right before we would normally sleep.
  3. pre-down.sh Runs on container stop before bringing WireGuard down or removing any iptables rules.
  4. post-down.sh Runs on container stop after bringing WireGuard down and removing iptables rules.

The run entrypoint would look for these scripts in /pia/scripts and run them at the right time if they exist. If the script fails, the container should exit there.

Usage

In my case this is useful so that I can add custom iptables rules. I am running this container alongside another Wireguard container which requires an extra bit of networking. I could fork and modify this repo, but that would be excessive when all I need to do is run a couple commands.

Feedback

I'm of course open to ideas, opinions, criticisms, etc., and I am also willing to implement this.

Thanks for your consideration!

thrnz commented

That seems easy enough to do and could be useful. Would something like this work? Note that if a custom script fails the container will only exit if EXIT_ON_FATAL=1 is set, otherwise the container will just go to sleep and need manually stopping.

I've built and tagged it as thrnz/docker-wireguard-pia:testing on Docker hub if it makes it easier to try out.

Wow you are fast! The code looks great, I will test it when I'm back at my computer. Thank you for your time doing this.

It works perfectly, I greatly appreciate it!! I tested all the scripts and they all work as expected.

For anyone else who might come across this, make sure your scripts are executable (chmod +x scripts/pre-up.sh for example). I forgot to do this at first.

thrnz commented

Thanks for testing. It should be in the Docker hub build soon.