Qilan2 commited on
Commit
515c768
·
verified ·
1 Parent(s): 3d64fad

Update server4.py

Browse files
Files changed (1) hide show
  1. server4.py +6 -4
server4.py CHANGED
@@ -424,6 +424,8 @@ def check_api1():
424
  if Service_status:
425
  print("结束检测")
426
  break
 
 
427
  url = f"{st_url}/csrf-token"
428
  try:
429
  response = requests_retry_session().get(url, timeout=30)
@@ -431,13 +433,13 @@ def check_api1():
431
  response_json = response.json()
432
  print("%s 接口返回信息: %s", url, response_json) # 修正日志记录
433
  if "token" in response_json:
434
- logging.info("检测到 token")
435
- nn = 0
436
  try:
437
  subprocess.run(f"rsync -avz --timeout=600 -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{ssh_url}:{data_folder}/ {data_folder}/",shell=True, check=True)
438
- break # 如果成功,跳出重试循环
439
  except subprocess.CalledProcessError as e:
440
- print(f"Rsync 失败,返回码: {e.returncode}, 尝试次数: {attempt + 1}")
 
441
  generate_ssh_key() # 处理 SSH 密钥生成
442
  else:
443
  print("%s 接口返回信息: %s", url, response_json) # 修正日志记录
 
424
  if Service_status:
425
  print("结束检测")
426
  break
427
+ if nn > 5:
428
+ break
429
  url = f"{st_url}/csrf-token"
430
  try:
431
  response = requests_retry_session().get(url, timeout=30)
 
433
  response_json = response.json()
434
  print("%s 接口返回信息: %s", url, response_json) # 修正日志记录
435
  if "token" in response_json:
436
+ print("检测到 token")
 
437
  try:
438
  subprocess.run(f"rsync -avz --timeout=600 -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' root@{ssh_url}:{data_folder}/ {data_folder}/",shell=True, check=True)
439
+ # break # 如果成功,跳出重试循环
440
  except subprocess.CalledProcessError as e:
441
+ nn += 1
442
+ print(f"Rsync 失败,返回码: {e.returncode}, 尝试次数: {nn}")
443
  generate_ssh_key() # 处理 SSH 密钥生成
444
  else:
445
  print("%s 接口返回信息: %s", url, response_json) # 修正日志记录