Qilan2 commited on
Commit
f5ea8ab
·
verified ·
1 Parent(s): c9be20a

Update Card_Hub.py

Browse files
Files changed (1) hide show
  1. Card_Hub.py +36 -3
Card_Hub.py CHANGED
@@ -444,6 +444,8 @@ def prepare_database_sync():
444
 
445
  def sync_database():
446
  """同步数据库"""
 
 
447
  try:
448
  # 1. 准备同步
449
  prepare_database_sync()
@@ -453,7 +455,6 @@ def sync_database():
453
  subprocess.run(rsync_cmd, shell=True, check=True)
454
 
455
  # 3. 验证数据库完整性
456
- db_path = "/Card_Hub/RoleCardSite/server/src/data/database.sqlite"
457
  try:
458
  result = subprocess.run(f"sqlite3 {db_path} 'PRAGMA integrity_check;'",
459
  shell=True,
@@ -480,6 +481,10 @@ def sync_database():
480
  # 4. 重启服务
481
  try:
482
  os.chdir('/Card_Hub/RoleCardSite')
 
 
 
 
483
  subprocess.run('sh ./start.sh', shell=True)
484
  except Exception as e:
485
  print(f"重启服务时出错: {e}")
@@ -529,6 +534,15 @@ def Run_SillyTavern():
529
  subprocess.run(f"chmod 666 {db_path}", shell=True)
530
  subprocess.run(f"chmod 755 {os.path.dirname(db_path)}", shell=True)
531
 
 
 
 
 
 
 
 
 
 
532
  # 启动服务
533
  subprocess.run('sh ./start.sh', shell=True, check=True)
534
  print("已尝试启动 server.js")
@@ -537,6 +551,21 @@ def Run_SillyTavern():
537
  except Exception as e:
538
  print(f"发生异常: {e}")
539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
  def SillyTavern():
541
  print('-----------SillyTavern开始-------------')
542
  # 创建目录并写入 kaggle.json
@@ -584,10 +613,14 @@ def SillyTavern():
584
  os.system("ls /Card-Hub")
585
  os.system(f"tar -xvpf /card-hub.tar.gz -C / --use-compress-program=pigz > /dev/null")
586
 
587
- print('更新文件')
588
- # os.system('git pull --rebase --autostash')
 
 
589
 
 
590
  os.system("rm -r /card-hub.tar.gz /card-hub.zip /Card_Hub.ctk")
 
591
  print('-----------SillyTavern结束-------------')
592
  threading.Thread(target=SillyTavern, daemon=True).start()
593
  time.sleep(60)
 
444
 
445
  def sync_database():
446
  """同步数据库"""
447
+ db_path = "/Card_Hub/RoleCardSite/server/src/data/database.sqlite" # 移到函数开头
448
+
449
  try:
450
  # 1. 准备同步
451
  prepare_database_sync()
 
455
  subprocess.run(rsync_cmd, shell=True, check=True)
456
 
457
  # 3. 验证数据库完整性
 
458
  try:
459
  result = subprocess.run(f"sqlite3 {db_path} 'PRAGMA integrity_check;'",
460
  shell=True,
 
481
  # 4. 重启服务
482
  try:
483
  os.chdir('/Card_Hub/RoleCardSite')
484
+ # 修复权限问题
485
+ subprocess.run('chmod +x ./start.sh', shell=True)
486
+ subprocess.run('chmod +x ./server/node_modules/.bin/nodemon', shell=True)
487
+ subprocess.run('chmod +x ./client/node_modules/.bin/vite', shell=True)
488
  subprocess.run('sh ./start.sh', shell=True)
489
  except Exception as e:
490
  print(f"重启服务时出错: {e}")
 
534
  subprocess.run(f"chmod 666 {db_path}", shell=True)
535
  subprocess.run(f"chmod 755 {os.path.dirname(db_path)}", shell=True)
536
 
537
+ # 修复启动脚本和依赖的权限
538
+ subprocess.run('chmod +x ./start.sh', shell=True)
539
+ subprocess.run('chmod +x ./server/node_modules/.bin/nodemon', shell=True)
540
+ subprocess.run('chmod +x ./client/node_modules/.bin/vite', shell=True)
541
+
542
+ # 确保 node_modules 目录权限正确
543
+ subprocess.run('chmod -R 755 ./server/node_modules', shell=True)
544
+ subprocess.run('chmod -R 755 ./client/node_modules', shell=True)
545
+
546
  # 启动服务
547
  subprocess.run('sh ./start.sh', shell=True, check=True)
548
  print("已尝试启动 server.js")
 
551
  except Exception as e:
552
  print(f"发生异常: {e}")
553
 
554
+ def install_dependencies():
555
+ """安装必要的依赖"""
556
+ try:
557
+ # 安装 nodemon
558
+ subprocess.run('npm install -g nodemon', shell=True)
559
+ # 安装 vite
560
+ subprocess.run('npm install -g vite', shell=True)
561
+ # 安装项目依赖
562
+ os.chdir('/Card_Hub/RoleCardSite/server')
563
+ subprocess.run('npm install', shell=True)
564
+ os.chdir('/Card_Hub/RoleCardSite/client')
565
+ subprocess.run('npm install', shell=True)
566
+ except Exception as e:
567
+ print(f"安装依赖时出错: {e}")
568
+
569
  def SillyTavern():
570
  print('-----------SillyTavern开始-------------')
571
  # 创建目录并写入 kaggle.json
 
613
  os.system("ls /Card-Hub")
614
  os.system(f"tar -xvpf /card-hub.tar.gz -C / --use-compress-program=pigz > /dev/null")
615
 
616
+ # 添加权限修复
617
+ subprocess.run('chmod +x /Card_Hub/RoleCardSite/start.sh', shell=True)
618
+ subprocess.run('chmod -R 755 /Card_Hub/RoleCardSite/server/node_modules', shell=True)
619
+ subprocess.run('chmod -R 755 /Card_Hub/RoleCardSite/client/node_modules', shell=True)
620
 
621
+ print('更新文件')
622
  os.system("rm -r /card-hub.tar.gz /card-hub.zip /Card_Hub.ctk")
623
+ install_dependencies()
624
  print('-----------SillyTavern结束-------------')
625
  threading.Thread(target=SillyTavern, daemon=True).start()
626
  time.sleep(60)