fix: fix proxy setup

This commit is contained in:
adlsdztony
2025-07-01 13:20:26 +00:00
parent 48ac57697a
commit 64f47d1a32
5 changed files with 37 additions and 21 deletions

View File

@@ -59,7 +59,7 @@ class SetupController:
{
"type": str, corresponding to the `_{:}_setup` methods of
this class
"parameters": dick like {str, Any} providing the keyword
"parameters": dict like {str, Any} providing the keyword
parameters
}
"""
@@ -368,6 +368,19 @@ class SetupController:
Args:
client_password (str): Password for sudo operations, defaults to "password"
"""
retry = 0
while retry < MAX_RETRIES:
try:
_ = requests.get(self.http_server + "/terminal")
break
except:
time.sleep(5)
retry += 1
logger.info(f"retry: {retry}/{MAX_RETRIES}")
if retry == MAX_RETRIES:
return False
# Get proxy from global proxy pool
proxy_pool = get_global_proxy_pool()
current_proxy = proxy_pool.get_next_proxy()
@@ -380,14 +393,21 @@ class SetupController:
proxy_url = proxy_pool._format_proxy_url(current_proxy)
logger.info(f"Setting up proxy: {current_proxy.host}:{current_proxy.port}")
# Configure system proxy environment variables
# Configure system proxy environment variables
proxy_commands = [
f"echo '{client_password}' | sudo -S bash -c \"echo 'export http_proxy={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export https_proxy={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export HTTP_PROXY={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export HTTPS_PROXY={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"apt-get update\"", ## TODO: remove this line if ami is already updated
f"echo '{client_password}' | sudo -S bash -c \"apt-get install -y tinyproxy\"", ## TODO: remove this line if tinyproxy is already installed
f"echo '{client_password}' | sudo -S bash -c \"echo 'Port 18888' > /tmp/tinyproxy.conf\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'Allow 127.0.0.1' >> /tmp/tinyproxy.conf\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'Upstream http {current_proxy.username}:{current_proxy.password}@{current_proxy.host}:{current_proxy.port}' >> /tmp/tinyproxy.conf\"",
# CML commands to set environment variables for proxy
f"echo 'export http_proxy={proxy_url}' >> ~/.bashrc",
f"echo 'export https_proxy={proxy_url}' >> ~/.bashrc",
f"echo 'export HTTP_PROXY={proxy_url}' >> ~/.bashrc",
f"echo 'export HTTPS_PROXY={proxy_url}' >> ~/.bashrc",
]
# Execute all proxy configuration commands
for cmd in proxy_commands:
try:
@@ -397,6 +417,8 @@ class SetupController:
proxy_pool.mark_proxy_failed(current_proxy)
raise
self._launch_setup(["tinyproxy -c /tmp/tinyproxy.conf -d"], shell=True)
# Reload environment variables
reload_cmd = "source /etc/environment"
try: