diff --git a/scripts/aws/UID_CloudFormation.template.yml b/scripts/aws/UID_CloudFormation.template.yml index 7a7f3d6a0..58030f4d2 100644 --- a/scripts/aws/UID_CloudFormation.template.yml +++ b/scripts/aws/UID_CloudFormation.template.yml @@ -38,6 +38,8 @@ Parameters: - m6i.4xlarge - r6i.2xlarge - r6i.4xlarge + - r7i.2xlarge + - r7i.4xlarge ConstraintDescription: must be a valid EC2 instance type. RootVolumeSize: Description: Instance root volume size diff --git a/scripts/aws/ec2.py b/scripts/aws/ec2.py index 0fc1c5f2c..f58acb72f 100644 --- a/scripts/aws/ec2.py +++ b/scripts/aws/ec2.py @@ -167,8 +167,47 @@ def __run_config_server(self) -> None: self.run_service([command, command], "flask_config_server", separate_process=True) + def __configure_sockd_network_interface(self) -> None: + """ + Auto-detects the primary network interface and configures sockd.conf. + This ensures compatibility with R7i instances which use 'enp39s0' instead of 'ens5'. + """ + logging.info("Auto-detecting network interface for SOCKS proxy configuration") + + try: + with open('/etc/sockd.conf', 'r') as f: + config = f.read() + + # Extract current interface from config + current_match = re.search(r'external:\s+(\S+)', config) + current_interface = current_match.group(1) if current_match else "unknown" + + # Detect primary network interface + result = subprocess.run( + ["ip", "-o", "route", "get", "1"], + capture_output=True, text=True, check=True + ) + match = re.search(r'dev\s+(\S+)', result.stdout) + primary_interface = match.group(1) if match else "ens5" + + logging.info(f"Detected primary network interface: {primary_interface} (default in config: {current_interface})") + + new_config = re.sub(r'external:\s+\S+', f'external: {primary_interface}', config) + + with open('/etc/sockd.conf', 'w') as f: + f.write(new_config) + + logging.info(f"/etc/sockd.conf configured with interface: {primary_interface}") + + except Exception as e: + logging.error(f"Failed to auto-detect network interface: {e}") + logging.info("Continuing with existing /etc/sockd.conf configuration") + def __run_socks_proxy(self) -> None: logging.info("Starts the SOCKS proxy service") + + self.__configure_sockd_network_interface() + command = ["sockd", "-D"] # -d specifies debug level