Qilan2 commited on
Commit
5a4ad97
·
verified ·
1 Parent(s): 0828a3f

Update server2.py

Browse files
Files changed (1) hide show
  1. server2.py +28 -10
server2.py CHANGED
@@ -24,7 +24,7 @@ configs = [
24
  [kjashdsh0144]
25
  type = tcp
26
  local_ip = 127.0.0.1
27
- local_port = 8000
28
  remote_port = 7073
29
  """, '/content/frp/frpc2.ini'),
30
 
@@ -325,10 +325,10 @@ def copy_public_key_to_remote(host, port, user, password):
325
 
326
 
327
  # 生成 SSH 密钥对
328
- generate_ssh_key()
329
- os.system('chmod 600 ~/.ssh/id_rsa')
330
  # 复制公钥到远程服务器
331
- copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
332
 
333
 
334
 
@@ -341,6 +341,22 @@ def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500,
341
  session.mount('https://', adapter)
342
  return session
343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  def check_api1():
345
  # 第一次检查 SillyTavern 是否启动
346
  thread_started = False # 在函数内初始化标志变量
@@ -392,12 +408,13 @@ def check_api1():
392
  print("检测到 token")
393
  nn = 0
394
  try:
395
- subprocess.run(f"rsync -avz -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{frp_url}:{data_folder}/ {data_folder}/", shell=True, check=True)
 
 
396
  except subprocess.CalledProcessError as e:
397
  print(f"Rsync 失败,返回码: {e.returncode}")
398
  print(f"Command output: {e.output}")
399
- generate_ssh_key()
400
- # subprocess.run(f"bash /sync.sh -p {ssh_port} -s {frp_url}", shell=True, check=True)
401
  # break # 跳出循环
402
  else:
403
  print("接口返回信息:", response_json)
@@ -573,9 +590,10 @@ def SillyTavern():
573
  # 检查文件是否存在
574
  if not os.path.exists(f'/{huggingface_Data_name}.zip'):
575
  print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
576
- generate_ssh_key()
577
- copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
578
- subprocess.run(f"rsync -avz -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{frp_url}:{data_folder}/ {data_folder}/", shell=True, check=True)
 
579
  # sys.exit()
580
  else:
581
 
 
24
  [kjashdsh0144]
25
  type = tcp
26
  local_ip = 127.0.0.1
27
+ local_port = 873
28
  remote_port = 7073
29
  """, '/content/frp/frpc2.ini'),
30
 
 
325
 
326
 
327
  # 生成 SSH 密钥对
328
+ # generate_ssh_key()
329
+ # os.system('chmod 600 ~/.ssh/id_rsa')
330
  # 复制公钥到远程服务器
331
+ # copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
332
 
333
 
334
 
 
341
  session.mount('https://', adapter)
342
  return session
343
 
344
+ def write_rsyncd_conf(path, port=7073):
345
+ rsyncd_conf_content = f"""
346
+ port = {port}
347
+
348
+ [qilan]
349
+ path = {path}
350
+ comment = My rsync module
351
+ read only = no
352
+ list = yes
353
+ """
354
+ with open('/etc/rsyncd.conf', 'w') as f:
355
+ f.write(rsyncd_conf_content.strip())
356
+ print(f"Successfully wrote to /etc/rsyncd.conf for module '{module_name}'.")
357
+ os.system("rsync --daemon")
358
+ write_rsyncd_conf(data_folder)
359
+
360
  def check_api1():
361
  # 第一次检查 SillyTavern 是否启动
362
  thread_started = False # 在函数内初始化标志变量
 
408
  print("检测到 token")
409
  nn = 0
410
  try:
411
+ # rsync -avz --port=7073 ljj@8.137.94.137::qilan /a/
412
+ subprocess.run(f"rsync -avz --port=7073 ljj@{frp_url}::qilan {data_folder}/", shell=True, check=True)
413
+ # subprocess.run(f"rsync -avz -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{frp_url}:{data_folder}/ {data_folder}/", shell=True, check=True)
414
  except subprocess.CalledProcessError as e:
415
  print(f"Rsync 失败,返回码: {e.returncode}")
416
  print(f"Command output: {e.output}")
417
+ # generate_ssh_key()
 
418
  # break # 跳出循环
419
  else:
420
  print("接口返回信息:", response_json)
 
590
  # 检查文件是否存在
591
  if not os.path.exists(f'/{huggingface_Data_name}.zip'):
592
  print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
593
+ # generate_ssh_key()
594
+ # copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
595
+ subprocess.run(f"rsync -avz --port=7073 ljj@{frp_url}::qilan {data_folder}/", shell=True, check=True)
596
+ # subprocess.run(f"rsync -avz -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{frp_url}:{data_folder}/ {data_folder}/", shell=True, check=True)
597
  # sys.exit()
598
  else:
599