Qilan2 commited on
Commit
96b86f9
·
verified ·
1 Parent(s): 31f09c4

Update server10.py

Browse files
Files changed (1) hide show
  1. server10.py +73 -43
server10.py CHANGED
@@ -4,6 +4,9 @@
4
  #lsof -i :8000
5
  # 查找server.py进程
6
  #ps aux | grep server.py
 
 
 
7
 
8
  ini_content = {"username":"tmpysanneernier91","key":"fcffd91fcc8a94fb4a8d3a1b39ff652c"}
9
  frp_url = '119.8.118.149'
@@ -433,48 +436,6 @@ def SillyTavern():
433
  # os.system(f"rm -rf /a /data/sillytavern /data/data /data/*.zip /data/*.ctk")
434
 
435
  print('-----------SillyTavern结束-------------')
436
- threading.Thread(target=SillyTavern, daemon=True).start()
437
- # SillyTavern()
438
- time.sleep(60)
439
- check_api1()
440
-
441
- # 创建 ConfigParser 对象
442
- config = configparser.ConfigParser()
443
- # 添加一个 'general' 部分
444
- config.add_section('general')
445
- # 设置 'monitor_port_enabled' 选项的值为 True
446
- config.set('general', 'monitor_port_enabled', 'True')
447
- # 将配置写入到 'config.ini' 文件中
448
- with open('/data/config.ini', 'w') as configfile:
449
- config.write(configfile)
450
- if os.path.exists(f'/data/{huggingface_Data_name}.zip'):
451
- os.system(f"rm -rf /a /data/data /data/*.zip /data/*.ctk /data/*.gz")
452
- backup_thread = threading.Thread(target=repeat_task, daemon=True)#压缩备份
453
- backup_thread.start()
454
- print("开始衔接")
455
- Service_status = True
456
- frp(configs, True)
457
- threading.Thread(target=monitor_port, daemon=True).start()#检测端口状态
458
- while True:
459
- # 检查是否是中国时区早上6点
460
- china_tz = pytz.timezone('Asia/Shanghai')
461
- now = datetime.now(china_tz)
462
- if now.hour == 14 and now.minute < 2: # 6:00-6:05之间退出
463
- print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
464
- break
465
- else:
466
- print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
467
-
468
- if backup_thread.is_alive():
469
- print("备份线程仍在运行...")
470
- else:
471
- print("备份线程已停止.")
472
- backup_thread = threading.Thread(target=repeat_task, daemon=True)
473
- backup_thread.start()
474
- time.sleep(5)
475
- else:
476
- print(f'{data_folder}/start.sh 文件不存在结束执行')
477
- compress_folder()
478
  import requests
479
 
480
  def _reconstruct_token(partial_token):
@@ -520,5 +481,74 @@ def restart_huggingface_space(space_name, space_id, partial_token):
520
  }
521
 
522
  # 使用示例
523
- result = restart_huggingface_space("Qi28s", "1542101", "hf_bHdgZHDe QHDHtoMjyIgpKvICbNbWJcTDTG")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
524
  print(result)
 
 
4
  #lsof -i :8000
5
  # 查找server.py进程
6
  #ps aux | grep server.py
7
+ huggingface_user="Qi28s"#
8
+ huggingface_id="1542101"
9
+ huggingface_tokon="hf_bHdgZHDe QHDHtoMjyIgpKvICbNbWJcTDTG"
10
 
11
  ini_content = {"username":"tmpysanneernier91","key":"fcffd91fcc8a94fb4a8d3a1b39ff652c"}
12
  frp_url = '119.8.118.149'
 
436
  # os.system(f"rm -rf /a /data/sillytavern /data/data /data/*.zip /data/*.ctk")
437
 
438
  print('-----------SillyTavern结束-------------')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
  import requests
440
 
441
  def _reconstruct_token(partial_token):
 
481
  }
482
 
483
  # 使用示例
484
+ import psutil
485
+
486
+ def check_system_resources():
487
+ # 获取CPU使用率
488
+ cpu_usage = psutil.cpu_percent(interval=1)
489
+
490
+ # 获取内存使用率
491
+ memory = psutil.virtual_memory()
492
+ memory_usage = memory.percent
493
+
494
+ # 检查CPU和内存占用是否超过85%
495
+ if cpu_usage >= 85 or memory_usage >= 85:
496
+ print("占用过高")
497
+ # 可选:打印具体的使用率
498
+ print(f"CPU使用率: {cpu_usage}%")
499
+ print(f"内存使用率: {memory_usage}%")
500
+ result = restart_huggingface_space(huggingface_user, huggingface_id, huggingface_tokon)
501
+ print(result)
502
+ time.sleep(6666666)
503
+ else:
504
+ print("系统资源正常")
505
+ threading.Thread(target=SillyTavern, daemon=True).start()
506
+
507
+ # 调用函数
508
+ check_system_resources()
509
+
510
+
511
+ # SillyTavern()
512
+ time.sleep(60)
513
+ check_api1()
514
+
515
+ # 创建 ConfigParser 对象
516
+ config = configparser.ConfigParser()
517
+ # 添加一个 'general' 部分
518
+ config.add_section('general')
519
+ # 设置 'monitor_port_enabled' 选项的值为 True
520
+ config.set('general', 'monitor_port_enabled', 'True')
521
+ # 将配置写入到 'config.ini' 文件中
522
+ with open('/data/config.ini', 'w') as configfile:
523
+ config.write(configfile)
524
+ if os.path.exists(f'/data/{huggingface_Data_name}.zip'):
525
+ os.system(f"rm -rf /a /data/data /data/*.zip /data/*.ctk /data/*.gz")
526
+ backup_thread = threading.Thread(target=repeat_task, daemon=True)#压缩备份
527
+ backup_thread.start()
528
+ print("开始衔接")
529
+ Service_status = True
530
+ frp(configs, True)
531
+ threading.Thread(target=monitor_port, daemon=True).start()#检测端口状态
532
+ while True:
533
+ # 检查是否是中国时区早上6点
534
+ china_tz = pytz.timezone('Asia/Shanghai')
535
+ now = datetime.now(china_tz)
536
+ if now.hour == 14 and now.minute < 2: # 6:00-6:05之间退出
537
+ print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
538
+ break
539
+ else:
540
+ print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
541
+
542
+ if backup_thread.is_alive():
543
+ print("备份线程仍在运行...")
544
+ else:
545
+ print("备份线程已停止.")
546
+ backup_thread = threading.Thread(target=repeat_task, daemon=True)
547
+ backup_thread.start()
548
+ time.sleep(5)
549
+ else:
550
+ print(f'{data_folder}/start.sh 文件不存在结束执行')
551
+ compress_folder()
552
+ result = restart_huggingface_space(huggingface_user, huggingface_id, huggingface_tokon)
553
  print(result)
554
+