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

Issues adding .sh script on TUN up. #95

Open
BanditTech opened this issue Jul 12, 2021 · 11 comments
Open

Issues adding .sh script on TUN up. #95

BanditTech opened this issue Jul 12, 2021 · 11 comments

Comments

@BanditTech
Copy link

When attempting to follow the directions for a private tracker, they require an update of the IP from which qbit is downloading. I can run the command in the container manually, and it works. But if I add in the additional CLI options for OPVN it has this issue.

      - VPN_OPTIONS=--script-security 2 --up /config/tun_up.sh

adding this to the compose causes this to occur:

today at 8:28:07 PM 2021-07-11 20:28:07,576 DEBG 'start-script' stdout output:
today at 8:28:07 PM 2021-07-11 20:28:07 Multiple --up scripts defined.  The previously configured script is overridden.

This is the .sh which is just one line:

#!/bin/bash
curl -c /config/mam.cookies -b /config/mam.cookies https://t.myanonamouse.net/json/dynamicSeedbox.php

This essentially bricks the entire setup as nothing else finishes configuring.

Is there a better way for me to inject a script into the startup?

@BanditTech
Copy link
Author

was hoping to hear something, I am just manually running the script every once in a while from inside the container... :P

@szethh
Copy link

szethh commented Nov 28, 2021

I have the same issue... ever found a solution, besides modifying the Dockerfile?

@BanditTech
Copy link
Author

on the server host, it has a timer which runs, and sends the command to the docker container to run that script.

I think I set it to run every 2 hours.

This was the simplest solution I could figure without needing to edit the docker container file itself

@SoCraDi
Copy link

SoCraDi commented Dec 22, 2021

I had the same exact issue and was able to solve it by passing VPN_OPTIONS --route-up /config/tun_up.sh
However, in my tun_up.sh I added "sleep 5" to introduce a 5 sec delay before the curl command is called. From what I remember, not everything would initialize and the curl would fail otherwise

@shuang913
Copy link

@SoCraDi any chance you can share your exact environment variable and tun_up.sh script?
Tried this and the container still doesn't initialize.

@i-am-at0m
Copy link

i-am-at0m commented Apr 12, 2023

So the script it replaces if you use the --up option is /root/openvpnup.sh, but the way the arguments are formatted in the start-script, I don't think you can use a hack to smash them together in one --up argument like mentioned here to make it happen: https://superuser.com/questions/505012/how-to-execute-multiple-scripts-when-openvpn-establishes/1618709#1618709?newreg=833809e0a807452fa0dd829e7bc53298

I tried adding -e "VPN_OPTIONS=--script-security 2 --route-delay 5 --route-up /config/persists/tun_up.sh", which at least executes according to supervisord.log, but fails to resolve the MAM domain name so the curl fails. Delaying longer just slows the startup down, and it looks like a lot of the routing stuff gets added by the start-script after --route-up is executed anyways. However, getting into an interactive shell on the docker and executing it from there after the tunnel is up DOES work (although you have to be wary of permissions and CRLF if you created the .sh file in windows or you get weird error messages that I had to google to understand).

My solve was to create a cronjob/scheduled task on the host that executes every hour that just runs docker exec qbittorrentvpn sh -c '/config/persists/tun_up.sh'

@SoCraDi
Copy link

SoCraDi commented Apr 22, 2023

@SoCraDi any chance you can share your exact environment variable and tun_up.sh script? Tried this and the container still doesn't initialize.
Here it is. This is working for me

VPN_OPTIONS=--route-up /config/mam_tun_up.sh

mam_tun_up.sh:

#!/bin/bash
echo "running mam_tun_up.sh"
# redirect stdout/stderr to a file
exec &> /config/mam_tun_up.log

MAMdynamicIP()
{
echo "mam_tun_up.sh: sleeping for 5 sec"
sleep 5
echo "mam_tun_up.sh: calling t.myanonamouse.net"
curl -c /config/mam.cookies -b /config/mam.cookies https://t.myanonamouse.net/json/dynamicSeedbox.php
echo
echo "mam_tun_up.sh: done"
}

MAMdynamicIP &

@i-am-at0m
Copy link

@SoCraDi any chance you can share your exact environment variable and tun_up.sh script? Tried this and the container still doesn't initialize.
Here it is. This is working for me

VPN_OPTIONS=--route-up /config/mam_tun_up.sh

mam_tun_up.sh:

#!/bin/bash
echo "running mam_tun_up.sh"
# redirect stdout/stderr to a file
exec &> /config/mam_tun_up.log

MAMdynamicIP()
{
echo "mam_tun_up.sh: sleeping for 5 sec"
sleep 5
echo "mam_tun_up.sh: calling t.myanonamouse.net"
curl -c /config/mam.cookies -b /config/mam.cookies https://t.myanonamouse.net/json/dynamicSeedbox.php
echo
echo "mam_tun_up.sh: done"
}

MAMdynamicIP &

Weird that that works with a 5sec sleep in it but mine didn't work with a 5 sec startup delay. I'll have to try that out.

@mleenorris
Copy link

mleenorris commented Apr 24, 2024

Did anyone figure this out? I tried a couple of versions including the --route-up, but all I get is t.myanonymouse.net is unreachable or host not known.

It works fine if I just run it after it's up.

@i-am-at0m
Copy link

Did anyone figure this out? I tried a couple of versions including the --route-up, but all I get is t.myanonymouse.net is unreachable or host not known.

It works fine if I just run it after it's up.

The URL in this comment is wrong, that might be it? Or it's getting to execute before the tunnel is up and has a working DNS server, tough to say

@O-Mutt
Copy link

O-Mutt commented May 8, 2024

Or it's getting to execute before the tunnel is up and has a working DNS server, tough to say

this is what, from what i can tell, i just ran into. I added ENABLE_STARTUP_SCRIPTS=yes and then put my initial setup script in /config/scripts/something.sh. My VPN_OPTIONS=tun_up.sh is there as well but i think that one may end up being ok eventually

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

7 participants