Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Scripts #33

Closed
MitchTalmadge opened this issue Oct 7, 2021 · 4 comments
Closed

Custom Scripts #33

MitchTalmadge opened this issue Oct 7, 2021 · 4 comments

Comments

@MitchTalmadge
Copy link

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
Copy link
Owner

thrnz commented Oct 8, 2021

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.

@MitchTalmadge
Copy link
Author

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.

@MitchTalmadge
Copy link
Author

MitchTalmadge commented Oct 8, 2021

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 added a commit that referenced this issue Oct 9, 2021
@thrnz
Copy link
Owner

thrnz commented Oct 9, 2021

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

@thrnz thrnz closed this as completed Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants