Update server.py
Browse files
server.py
CHANGED
|
@@ -229,6 +229,10 @@ def repeat_task():
|
|
| 229 |
# repeat_task()
|
| 230 |
# compress_folder()
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
def generate_ssh_key():
|
| 233 |
# 生成 SSH 密钥对,并捕获输出和错误信息
|
| 234 |
os.system("rm -f ~/.ssh/id_rsa ~/.ssh/id_rsa.pub")
|
|
@@ -243,11 +247,11 @@ def generate_ssh_key():
|
|
| 243 |
def copy_public_key_to_remote(host, port, user, password):
|
| 244 |
# 使用 pexpect 自动输入密码来复制公钥
|
| 245 |
try:
|
| 246 |
-
command = f"ssh-copy-id -p {port} {user}@{host}"
|
| 247 |
child = pexpect.spawn(command)
|
| 248 |
|
| 249 |
# 等待密码提示并发送密码
|
| 250 |
-
child.expect("password:")
|
| 251 |
child.sendline(password)
|
| 252 |
|
| 253 |
# 等待命令完成并输出结果
|
|
@@ -257,13 +261,14 @@ def copy_public_key_to_remote(host, port, user, password):
|
|
| 257 |
|
| 258 |
except Exception as e:
|
| 259 |
print(f"An error occurred: {e}")
|
|
|
|
|
|
|
| 260 |
# 生成 SSH 密钥对
|
| 261 |
generate_ssh_key()
|
|
|
|
| 262 |
# 复制公钥到远程服务器
|
| 263 |
copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
|
| 264 |
-
|
| 265 |
-
subprocess.run(f"rsync -avz -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{frp_url}:/sillytavern/ /sillytavern/", shell=True, check=True)
|
| 266 |
-
|
| 267 |
|
| 268 |
|
| 269 |
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|
|
|
|
| 229 |
# repeat_task()
|
| 230 |
# compress_folder()
|
| 231 |
|
| 232 |
+
import os
|
| 233 |
+
import subprocess
|
| 234 |
+
import pexpect
|
| 235 |
+
|
| 236 |
def generate_ssh_key():
|
| 237 |
# 生成 SSH 密钥对,并捕获输出和错误信息
|
| 238 |
os.system("rm -f ~/.ssh/id_rsa ~/.ssh/id_rsa.pub")
|
|
|
|
| 247 |
def copy_public_key_to_remote(host, port, user, password):
|
| 248 |
# 使用 pexpect 自动输入密码来复制公钥
|
| 249 |
try:
|
| 250 |
+
command = f"ssh-copy-id -o StrictHostKeyChecking=no -p {port} {user}@{host}"
|
| 251 |
child = pexpect.spawn(command)
|
| 252 |
|
| 253 |
# 等待密码提示并发送密码
|
| 254 |
+
child.expect("password:", timeout=10) # 增加超时时间
|
| 255 |
child.sendline(password)
|
| 256 |
|
| 257 |
# 等待命令完成并输出结果
|
|
|
|
| 261 |
|
| 262 |
except Exception as e:
|
| 263 |
print(f"An error occurred: {e}")
|
| 264 |
+
|
| 265 |
+
|
| 266 |
# 生成 SSH 密钥对
|
| 267 |
generate_ssh_key()
|
| 268 |
+
|
| 269 |
# 复制公钥到远程服务器
|
| 270 |
copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
|
| 271 |
+
|
|
|
|
|
|
|
| 272 |
|
| 273 |
|
| 274 |
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|