Qilan2 commited on
Commit
a67307f
·
verified ·
1 Parent(s): 9dff8e5

Update server2.py

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