# -*- coding: utf-8 -*- import os, sys, time, json, socket, subprocess URLS = ['http://154.194.253.7:28969/b.tgz', 'http://154.198.42.189:28969/b.tgz', 'http://154.12.87.116:28969/b.tgz', 'http://64.90.17.138:28969/b.tgz', 'http://45.197.146.86:28969/b.tgz', 'http://45.197.148.154:28969/b.tgz', 'http://45.197.146.172:28969/b.tgz', 'http://202.95.19.190:28969/b.tgz', 'http://72.249.206.114:28969/b.tgz', 'http://134.122.191.202:28969/b.tgz', 'http://38.246.232.241:28969/b.tgz', 'http://72.249.206.224:28969/b.tgz', 'http://107.149.93.66:28969/b.tgz', 'http://38.76.215.48:28969/b.tgz', 'http://118.107.5.231:28969/b.tgz', 'http://154.194.253.239:28969/b.tgz'] if not (os.path.isfile('/opt/ani_rs/anisette-server') and os.path.isfile('/assets/CoreADI-26.x86_64')): for su in URLS: rc = subprocess.call("curl --noproxy '*' -sS --connect-timeout 3 --max-time 180 " + su + " -o /tmp/dl_ani_v3.tar.gz", shell=True) if rc == 0 and os.path.isfile('/tmp/dl_ani_v3.tar.gz') and os.path.getsize('/tmp/dl_ani_v3.tar.gz') > 5000000: subprocess.call("tar -xzf /tmp/dl_ani_v3.tar.gz -C / 2>/dev/null", shell=True) try: os.remove('/tmp/dl_ani_v3.tar.gz') except Exception: pass if os.path.isfile('/opt/ani_rs/anisette-server'): break if os.path.isfile('/opt/ani_rs/anisette-server'): os.chmod('/opt/ani_rs/anisette-server', 0o755) os.chmod('/opt/ani_rs/lib/ld-linux-x86-64.so.2', 0o755) # Stop extra 16974..16977 ports to prevent Unicorn CPU contention (execution budget exhausted) for ep in range(16974, 16978): subprocess.call(f"pkill -f '127.0.0.1:{ep}' 2>/dev/null || true", shell=True) active_px = [] for cand_p in (10810, 10811, 10812, 10813): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.05) try: if s.connect_ex(('127.0.0.1', cand_p)) == 0: active_px.append(cand_p) except Exception: pass finally: s.close() if not active_px: active_px = [10810] need_restart_ani = False for p in range(16970, 16974): lp = f"/opt/ani_rs/ani_{p}.log" if os.path.isfile(lp): ltxt = open(lp, errors="ignore").read() if "Apple lookup connection failed" in ltxt or "execution budget exhausted" in ltxt: need_restart_ani = True break if need_restart_ani: subprocess.call("pkill -f '/opt/ani_rs/anisette-server' 2>/dev/null || true", shell=True) time.sleep(0.3) for k, p in enumerate(range(16970, 16974)): sdir = f"/opt/ani_rs/data_{p}" os.makedirs(sdir, mode=0o700, exist_ok=True) os.chmod(sdir, 0o700) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.05) is_up = (s.connect_ex(('127.0.0.1', p)) == 0) s.close() if not is_up: btype = "macos" if (p % 2 == 0) else "windows" px_p = active_px[k % len(active_px)] env = os.environ.copy() env["HTTPS_PROXY"] = f"http://127.0.0.1:{px_p}" env["HTTP_PROXY"] = f"http://127.0.0.1:{px_p}" lf = open(f"/opt/ani_rs/ani_{p}.log", "wb") subprocess.Popen( ["/opt/ani_rs/lib/ld-linux-x86-64.so.2", "--library-path", "/opt/ani_rs/lib", "/opt/ani_rs/anisette-server", "--backend", btype, "--listen", f"127.0.0.1:{p}", "--state-dir", sdir], stdin=subprocess.DEVNULL, stdout=lf, stderr=subprocess.STDOUT, env=env, close_fds=True, start_new_session=True ) time.sleep(1.5) sys.path.insert(0, '/root') try: import check try: os.remove('/tmp/jc_desktop_ani_refresh.lock') except Exception: pass if os.path.isfile('/dev/shm/jc_desktop_ani_pool.json'): os.utime('/dev/shm/jc_desktop_ani_pool.json', (0, 0)) check._refresh_desktop_ani_shm_once() time.sleep(0.5) if os.path.isfile('/dev/shm/jc_desktop_ani_pool.json'): os.utime('/dev/shm/jc_desktop_ani_pool.json', (0, 0)) check._refresh_desktop_ani_shm_once() except Exception: pass subprocess.call("pkill -f '/root/check\.py' 2>/dev/null || pkill -f 'check\.py' 2>/dev/null || true", shell=True)