Update server9-bf.py
Browse files- server9-bf.py +43 -5
server9-bf.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
ini_content = {"username":"natclghpe","key":"21e32070151c7fe0fbd5af3287d7e489"}
|
|
|
|
|
|
|
|
|
|
| 2 |
frp_url = '119.8.118.149'
|
| 3 |
ssh_port = '7082'
|
| 4 |
ssh_url = '45.32.68.209'
|
|
@@ -126,6 +129,38 @@ os.system("mkdir -p /content/frp")
|
|
| 126 |
os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc")
|
| 127 |
os.system("chmod +x /content/frp/frpc")
|
| 128 |
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
def nezha():
|
| 130 |
agent_config ={
|
| 131 |
'client_secret': 'MLcD6YnifhoY08B9n129UP5cg2139NYa',
|
|
@@ -186,6 +221,7 @@ def update():
|
|
| 186 |
# 安装 p7zip-full
|
| 187 |
os.system("pip uninstall requests urllib3 -y")
|
| 188 |
os.system("pip install requests urllib3")
|
|
|
|
| 189 |
os.system("sudo apt install p7zip-full -y")
|
| 190 |
# os.system("pip install -U kaggle")
|
| 191 |
# os.system("pip uninstall -y kaggle > /dev/null 2>&1")
|
|
@@ -378,7 +414,7 @@ def copy_public_key_to_remote(host, port, user, password):
|
|
| 378 |
generate_ssh_key()
|
| 379 |
os.system('chmod 600 ~/.ssh/id_rsa')
|
| 380 |
# 复制公钥到远程服务器
|
| 381 |
-
copy_public_key_to_remote(
|
| 382 |
|
| 383 |
|
| 384 |
|
|
@@ -458,7 +494,7 @@ def check_api1():
|
|
| 458 |
break
|
| 459 |
if nn > 2:
|
| 460 |
break
|
| 461 |
-
url = f"{
|
| 462 |
try:
|
| 463 |
response = requests_retry_session().get(url, timeout=30)
|
| 464 |
response.raise_for_status()
|
|
@@ -467,7 +503,8 @@ def check_api1():
|
|
| 467 |
if "token" in response_json:
|
| 468 |
print("检测到 token")
|
| 469 |
try:
|
| 470 |
-
subprocess.run(f"rsync -avz --timeout=600 -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{ssh_url}:{data_folder}/ {data_folder}/",shell=True, check=True)
|
|
|
|
| 471 |
# break # 如果成功,跳出重试循环
|
| 472 |
except subprocess.CalledProcessError as e:
|
| 473 |
nn += 1
|
|
@@ -657,8 +694,8 @@ def SillyTavern():
|
|
| 657 |
if not os.path.exists(f'/{huggingface_Data_name}.zip'):
|
| 658 |
print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
|
| 659 |
generate_ssh_key()
|
| 660 |
-
copy_public_key_to_remote(
|
| 661 |
-
subprocess.run(f"rsync -avz --timeout=600 -e 'ssh -p
|
| 662 |
else:
|
| 663 |
|
| 664 |
# 如果文件存在,可以继续执行后续代码
|
|
@@ -718,6 +755,7 @@ if os.path.exists(f'{data_folder}/start.sh'):
|
|
| 718 |
print("开始衔接")
|
| 719 |
Service_status = True
|
| 720 |
frp(configs, True)
|
|
|
|
| 721 |
threading.Thread(target=monitor_port, daemon=True).start()#检测端口状态
|
| 722 |
while True:
|
| 723 |
if backup_thread.is_alive():
|
|
|
|
| 1 |
ini_content = {"username":"natclghpe","key":"21e32070151c7fe0fbd5af3287d7e489"}
|
| 2 |
+
cf_token = 'eyJhIjoiNmVjNWE5NzEzOGIzMTg4YTU2Y2U1NjdmMWRhZDBhMTUiLCJ0IjoiNjMyNTRkZjYtNWY0ZC00YjM2LTlmZjMtY2M1MzMxMzQ1ODUyIiwicyI6IlpXSTFNV1JsTkRndFlqWmhZUzAwWW1VNUxUZzFOemN0Wm1GbE1tUTFNREZrTldSaiJ9'
|
| 3 |
+
cf_jg = 'https://jg9-cf.qilan.sbs'
|
| 4 |
+
cf_ssh = 'jg9-ssh.qilan.sbs'
|
| 5 |
frp_url = '119.8.118.149'
|
| 6 |
ssh_port = '7082'
|
| 7 |
ssh_url = '45.32.68.209'
|
|
|
|
| 129 |
os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc")
|
| 130 |
os.system("chmod +x /content/frp/frpc")
|
| 131 |
import yaml
|
| 132 |
+
def cloudflared(zt):
|
| 133 |
+
if zt:
|
| 134 |
+
os.system("sudo mkdir -p --mode=0755 /usr/share/keyrings")
|
| 135 |
+
os.system("curl -fsSL https://pkg.cloudflare.com/cloudflare-public-v2.gpg | sudo tee /usr/share/keyrings/cloudflare-public-v2.gpg >/dev/null")
|
| 136 |
+
os.system("echo 'deb [signed-by=/usr/share/keyrings/cloudflare-public-v2.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list")
|
| 137 |
+
os.system("sudo apt-get update && sudo apt-get install cloudflared")
|
| 138 |
+
|
| 139 |
+
# 1. 创建 ~/.ssh 目录
|
| 140 |
+
ssh_dir = os.path.expanduser("~/.ssh")
|
| 141 |
+
os.makedirs(ssh_dir, exist_ok=True)
|
| 142 |
+
|
| 143 |
+
# 2. 准备配置文件的内容 (注意这里用 f""" """ 将变量 cf_ssh 注入进去)
|
| 144 |
+
# SSH 原本的 %h 会被原样保留,不会和 Python 的 f-string 冲突
|
| 145 |
+
ssh_config_content = f"""Host {cf_ssh}
|
| 146 |
+
ProxyCommand cloudflared access ssh --hostname %h
|
| 147 |
+
StrictHostKeyChecking no
|
| 148 |
+
"""
|
| 149 |
+
|
| 150 |
+
# 3. 写入内容到 ~/.ssh/config
|
| 151 |
+
config_path = os.path.join(ssh_dir, "config")
|
| 152 |
+
with open(config_path, "w") as f:
|
| 153 |
+
f.write(ssh_config_content)
|
| 154 |
+
|
| 155 |
+
# 4. 修改文件权限
|
| 156 |
+
os.chmod(config_path, 0o600)
|
| 157 |
+
|
| 158 |
+
# 打印日志也动态显示域名
|
| 159 |
+
print(f"✅ SSH config for {cf_ssh} generated successfully.")
|
| 160 |
+
|
| 161 |
+
else:
|
| 162 |
+
os.system(f"sudo cloudflared service install {cf_token}")
|
| 163 |
+
cloudflared(True)
|
| 164 |
def nezha():
|
| 165 |
agent_config ={
|
| 166 |
'client_secret': 'MLcD6YnifhoY08B9n129UP5cg2139NYa',
|
|
|
|
| 221 |
# 安装 p7zip-full
|
| 222 |
os.system("pip uninstall requests urllib3 -y")
|
| 223 |
os.system("pip install requests urllib3")
|
| 224 |
+
os.system("apt-get install -y sshpass")
|
| 225 |
os.system("sudo apt install p7zip-full -y")
|
| 226 |
# os.system("pip install -U kaggle")
|
| 227 |
# os.system("pip uninstall -y kaggle > /dev/null 2>&1")
|
|
|
|
| 414 |
generate_ssh_key()
|
| 415 |
os.system('chmod 600 ~/.ssh/id_rsa')
|
| 416 |
# 复制公钥到远程服务器
|
| 417 |
+
copy_public_key_to_remote(cf_ssh, 22, "root", "qilan")
|
| 418 |
|
| 419 |
|
| 420 |
|
|
|
|
| 494 |
break
|
| 495 |
if nn > 2:
|
| 496 |
break
|
| 497 |
+
url = f"{cf_jg}/csrf-token"
|
| 498 |
try:
|
| 499 |
response = requests_retry_session().get(url, timeout=30)
|
| 500 |
response.raise_for_status()
|
|
|
|
| 503 |
if "token" in response_json:
|
| 504 |
print("检测到 token")
|
| 505 |
try:
|
| 506 |
+
# subprocess.run(f"rsync -avz --timeout=600 -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{ssh_url}:{data_folder}/ {data_folder}/",shell=True, check=True)
|
| 507 |
+
subprocess.run(f"sshpass -p 'qilan' rsync -avz --timeout=600 -e 'ssh -p 22 -o StrictHostKeyChecking=no' root@{cf_ssh}:{data_folder}/ {data_folder}/",shell=True, check=True)
|
| 508 |
# break # 如果成功,跳出重试循环
|
| 509 |
except subprocess.CalledProcessError as e:
|
| 510 |
nn += 1
|
|
|
|
| 694 |
if not os.path.exists(f'/{huggingface_Data_name}.zip'):
|
| 695 |
print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
|
| 696 |
generate_ssh_key()
|
| 697 |
+
copy_public_key_to_remote(cf_ssh, 22, "root", "qilan")
|
| 698 |
+
subprocess.run(f"sshpass -p 'qilan' rsync -avz --timeout=600 -e 'ssh -p 22 -o StrictHostKeyChecking=no' root@{cf_ssh}:{data_folder}/ {data_folder}/",shell=True, check=True)
|
| 699 |
else:
|
| 700 |
|
| 701 |
# 如果文件存在,可以继续执行后续代码
|
|
|
|
| 755 |
print("开始衔接")
|
| 756 |
Service_status = True
|
| 757 |
frp(configs, True)
|
| 758 |
+
cloudflared(False)
|
| 759 |
threading.Thread(target=monitor_port, daemon=True).start()#检测端口状态
|
| 760 |
while True:
|
| 761 |
if backup_thread.is_alive():
|