Qilan2 commited on
Commit
e014909
·
verified ·
1 Parent(s): 91a463b

Update Card_Hub.py

Browse files
Files changed (1) hide show
  1. Card_Hub.py +77 -44
Card_Hub.py CHANGED
@@ -353,6 +353,34 @@ def check_api1():
353
  Service_status = False
354
  n = 0
355
  nn = 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  while True:
357
  n += 1
358
  if not os.path.exists('/Card_Hub'):
@@ -371,7 +399,13 @@ def check_api1():
371
  response_json = response.json()
372
  print(f"{url} 接口返回信息: {response_json}")
373
  if "message" in response_json:
374
- print("源服务器正常运行,无需启动本地服务")
 
 
 
 
 
 
375
  time.sleep(300) # 每5分钟检查一次
376
  continue
377
  else:
@@ -700,25 +734,32 @@ def SillyTavern():
700
 
701
  clear_output()
702
 
 
703
  os.system(f"rm -r /a /card-hub /*.zi* {data_folder}")
704
  os.system(f"mkdir -p {data_folder}")
705
  os.chdir('/')
706
- print(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}")
707
- # os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}")
 
708
  download_n = 0
709
  while True:
710
- # 执行下载命令
711
  if download_n > 6:
712
  break
713
  os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name} -p /")
714
- # 检查文件是否存在
715
  if os.path.exists(f'/{huggingface_Data_name}.zip'):
716
  print(f"{huggingface_Data_name}.zip 下载成功!")
717
- break # 跳出循环
 
 
 
 
 
 
 
718
  print(f"{huggingface_Data_name}.zip 下载失败,正在重试...")
719
  download_n += 1
720
- time.sleep(300) # 等待一段时间再重试(例如5秒
721
- # os.system('kaggle datasets download xovale7506/sillytavern-data2')
722
  # 检查文件是否存在
723
  if not os.path.exists(f'/{huggingface_Data_name}.zip'):
724
  print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
@@ -726,46 +767,38 @@ def SillyTavern():
726
  copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan")
727
  sync_database()
728
  else:
729
-
730
- # 如果文件存在,可以继续执行后续代码
731
  print(f"文件 /{huggingface_Data_name}.zip 存在,继续执行程序。")
732
- os.system(f"7z x /{huggingface_Data_name}.zip -o/ -y")
733
- os.system("mv /Card_Hub.ctk card-hub.tar.gz")
734
- os.system("mv /card_Hub.ctk card-hub.tar.gz")
735
- os.system("ls /")
736
- os.system("ls /Card-Hub")
737
- os.system(f"tar -xvpf /card-hub.tar.gz -C / --use-compress-program=pigz > /dev/null")
738
-
739
- # 添加全面的权限修复
740
- project_path = '/Card_Hub/RoleCardSite'
741
- client_path = f'{project_path}/client'
742
- server_path = f'{project_path}/server'
743
-
744
- # 修复项目根目录权限
745
- subprocess.run(f'chmod -R 755 {project_path}', shell=True)
746
-
747
- # 修复客户端权限
748
- subprocess.run(f'chmod -R 755 {client_path}/node_modules', shell=True)
749
- subprocess.run(f'chmod +x {client_path}/node_modules/.bin/*', shell=True)
750
-
751
- # 特别修复 esbuild 权限
752
- esbuild_path = f'{client_path}/node_modules/@esbuild/linux-x64/bin/esbuild'
753
- if os.path.exists(esbuild_path):
754
- subprocess.run(f'chmod +x {esbuild_path}', shell=True)
755
-
756
- # 修复服务器权限
757
- subprocess.run(f'chmod -R 755 {server_path}/node_modules', shell=True)
758
- subprocess.run(f'chmod +x {server_path}/node_modules/.bin/*', shell=True)
759
-
760
- # 修复启动脚本权限
761
- subprocess.run(f'chmod +x {project_path}/start.sh', shell=True)
762
-
763
- print('更新文件')
764
- os.system("rm -r /card-hub.tar.gz /card-hub.zip /Card_Hub.ctk")
765
 
766
  install_dependencies()
767
  check_vite_config()
768
- print('-----------SillyTavern结束-------------')
769
  threading.Thread(target=SillyTavern, daemon=True).start()
770
  time.sleep(60)
771
  check_api1()
 
353
  Service_status = False
354
  n = 0
355
  nn = 0
356
+
357
+ # 首先确保 Card-Hub 已下载和解压
358
+ if not os.path.exists('/Card_Hub/RoleCardSite'):
359
+ print("Card-Hub 未安装,开始下载和解压...")
360
+ try:
361
+ # 下载和解压 Card-Hub
362
+ os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name} -p /")
363
+ if os.path.exists(f'/{huggingface_Data_name}.zip'):
364
+ print(f"{huggingface_Data_name}.zip 下载成功!")
365
+ # 解压文件
366
+ print("开始解压文件...")
367
+ os.system(f"7z x /{huggingface_Data_name}.zip -o/ -y")
368
+ os.system("mv /Card_Hub.ctk card-hub.tar.gz")
369
+ os.system("mv /card_Hub.ctk card-hub.tar.gz")
370
+ os.system(f"tar -xvpf /card-hub.tar.gz -C / --use-compress-program=pigz > /dev/null")
371
+ print("文件解压完成")
372
+ # 清理临时文件
373
+ os.system("rm -r /card-hub.tar.gz /card-hub.zip /Card_Hub.ctk")
374
+ else:
375
+ print("下载失败,尝试使用实时同步...")
376
+ generate_ssh_key()
377
+ copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan")
378
+ except Exception as e:
379
+ print(f"下载和解压过程出错: {e}")
380
+
381
+ # 安装依赖
382
+ install_dependencies()
383
+
384
  while True:
385
  n += 1
386
  if not os.path.exists('/Card_Hub'):
 
399
  response_json = response.json()
400
  print(f"{url} 接口返回信息: {response_json}")
401
  if "message" in response_json:
402
+ print("源服务器正常运行,开始同步数据...")
403
+ try:
404
+ # 执行数据同步
405
+ sync_database()
406
+ print("数据同步完成")
407
+ except Exception as e:
408
+ print(f"数据同步失败: {e}")
409
  time.sleep(300) # 每5分钟检查一次
410
  continue
411
  else:
 
734
 
735
  clear_output()
736
 
737
+ # 清理并创建目录
738
  os.system(f"rm -r /a /card-hub /*.zi* {data_folder}")
739
  os.system(f"mkdir -p {data_folder}")
740
  os.chdir('/')
741
+
742
+ # 提前下载和解压备份
743
+ print("开始下载备份...")
744
  download_n = 0
745
  while True:
 
746
  if download_n > 6:
747
  break
748
  os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name} -p /")
 
749
  if os.path.exists(f'/{huggingface_Data_name}.zip'):
750
  print(f"{huggingface_Data_name}.zip 下载成功!")
751
+ # 解压文件
752
+ print("开始解压文件...")
753
+ os.system(f"7z x /{huggingface_Data_name}.zip -o/ -y")
754
+ os.system("mv /Card_Hub.ctk card-hub.tar.gz")
755
+ os.system("mv /card_Hub.ctk card-hub.tar.gz")
756
+ os.system(f"tar -xvpf /card-hub.tar.gz -C / --use-compress-program=pigz > /dev/null")
757
+ print("文件解压完成")
758
+ break
759
  print(f"{huggingface_Data_name}.zip 下载失败,正在重试...")
760
  download_n += 1
761
+ time.sleep(300)
762
+
763
  # 检查文件是否存在
764
  if not os.path.exists(f'/{huggingface_Data_name}.zip'):
765
  print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
 
767
  copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan")
768
  sync_database()
769
  else:
 
 
770
  print(f"文件 /{huggingface_Data_name}.zip 存在,继续执行程序。")
771
+
772
+ # 添加全面的权限修复
773
+ project_path = '/Card_Hub/RoleCardSite'
774
+ client_path = f'{project_path}/client'
775
+ server_path = f'{project_path}/server'
776
+
777
+ # 修复项目根目录权限
778
+ subprocess.run(f'chmod -R 755 {project_path}', shell=True)
779
+
780
+ # 修复客户端权限
781
+ subprocess.run(f'chmod -R 755 {client_path}/node_modules', shell=True)
782
+ subprocess.run(f'chmod +x {client_path}/node_modules/.bin/*', shell=True)
783
+
784
+ # 特别修复 esbuild 权限
785
+ esbuild_path = f'{client_path}/node_modules/@esbuild/linux-x64/bin/esbuild'
786
+ if os.path.exists(esbuild_path):
787
+ subprocess.run(f'chmod +x {esbuild_path}', shell=True)
788
+
789
+ # 修复服务器权限
790
+ subprocess.run(f'chmod -R 755 {server_path}/node_modules', shell=True)
791
+ subprocess.run(f'chmod +x {server_path}/node_modules/.bin/*', shell=True)
792
+
793
+ # 修复启动脚本权限
794
+ subprocess.run(f'chmod +x {project_path}/start.sh', shell=True)
795
+
796
+ print('更新文件')
797
+ os.system("rm -r /card-hub.tar.gz /card-hub.zip /Card_Hub.ctk")
 
 
 
 
 
 
798
 
799
  install_dependencies()
800
  check_vite_config()
801
+ print('-----------SillyTavern结束-------------')
802
  threading.Thread(target=SillyTavern, daemon=True).start()
803
  time.sleep(60)
804
  check_api1()