Qilan2 commited on
Commit
feceb06
·
verified ·
1 Parent(s): 0218048

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +23 -1
server.py CHANGED
@@ -449,7 +449,28 @@ def replace_ip_and_country_in_file(file_path):
449
  except Exception as e:
450
  print(f"发生其他错误: {e}")
451
 
452
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
 
454
  def SillyTavern():
455
  print('-----------SillyTavern开始-------------')
@@ -532,6 +553,7 @@ if os.path.exists('/sillytavern/start.sh'):
532
  frp_thread2 = threading.Thread(target=frp, args=(config_data, '/content/frp/frpc.ini', False))
533
  frp_thread2.start()
534
  while True:
 
535
  if backup_thread.is_alive():
536
  print("备份线程仍在运行...")
537
  else:
 
449
  except Exception as e:
450
  print(f"发生其他错误: {e}")
451
 
452
+ def is_script_running(script_name):
453
+ try:
454
+ # 使用 pgrep 查找正在运行的进程
455
+ result = subprocess.run(
456
+ ["pgrep", "-f", script_name],
457
+ stdout=subprocess.PIPE,
458
+ stderr=subprocess.PIPE,
459
+ text=True
460
+ )
461
+
462
+ # 检查返回码和输出
463
+ if result.returncode == 0:
464
+ print(f"{script_name} 正在运行,进程 ID: {result.stdout.strip()}")
465
+ return True
466
+ else:
467
+ print(f"{script_name} 未在运行,进行重启")
468
+ subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True)
469
+ return False
470
+
471
+ except Exception as e:
472
+ print(f"发生错误: {e}")
473
+ return False
474
 
475
  def SillyTavern():
476
  print('-----------SillyTavern开始-------------')
 
553
  frp_thread2 = threading.Thread(target=frp, args=(config_data, '/content/frp/frpc.ini', False))
554
  frp_thread2.start()
555
  while True:
556
+ is_running = is_script_running("/sillytavern/start.sh")
557
  if backup_thread.is_alive():
558
  print("备份线程仍在运行...")
559
  else: