Create server11-bf.py
Browse files- server11-bf.py +440 -389
server11-bf.py
CHANGED
|
@@ -1,104 +1,99 @@
|
|
| 1 |
-
|
| 2 |
-
#tail -f /data/server10.log
|
| 3 |
-
# 查找端口进程
|
| 4 |
-
#lsof -i :8000
|
| 5 |
-
# 查找server.py进程
|
| 6 |
-
#ps aux | grep server.py
|
| 7 |
-
#source /opt/venv/bin/activate
|
| 8 |
-
#python a.py
|
| 9 |
-
|
| 10 |
-
# huggingface_user="CourtneyCourtneyLNg"#
|
| 11 |
-
# huggingface_id="vguyeeewq11"
|
| 12 |
-
# huggingface_tokon="hf_BdUJ EGpSLdlpcekoHETcxNTxPDDtsCqkEW"
|
| 13 |
-
import subprocess
|
| 14 |
-
import os
|
| 15 |
-
import sys
|
| 16 |
-
import configparser
|
| 17 |
-
# from IPython.display import clear_output
|
| 18 |
-
import urllib.request
|
| 19 |
-
from pathlib import Path
|
| 20 |
-
import requests
|
| 21 |
-
import json
|
| 22 |
-
import threading
|
| 23 |
-
import time
|
| 24 |
-
import pexpect
|
| 25 |
-
import socket
|
| 26 |
-
import time
|
| 27 |
-
import glob # 导入 glob 模块
|
| 28 |
-
from requests.adapters import HTTPAdapter
|
| 29 |
-
from requests.packages.urllib3.util.retry import Retry
|
| 30 |
-
import logging
|
| 31 |
-
from datetime import datetime
|
| 32 |
-
import psutil
|
| 33 |
-
from typing import List, Dict
|
| 34 |
-
import pytz
|
| 35 |
-
|
| 36 |
-
huggingface_user = os.environ.get('HF_USER2', '')#用户名
|
| 37 |
-
huggingface_id = os.environ.get('HF_ID', '')#项目名
|
| 38 |
-
huggingface_tokon = os.environ.get('HF_TOKEN2', '')
|
| 39 |
-
|
| 40 |
-
ini_content = {"username":"rvbpm6lm","key":"3c17fa4e8261ab5fe7ddea63f2560516"}
|
| 41 |
frp_url = '119.8.118.149'
|
| 42 |
ssh_port = '7082'
|
| 43 |
ssh_url = '45.32.68.209'
|
| 44 |
-
st_url = f'http://{frp_url}:
|
| 45 |
-
huggingface_name = '
|
| 46 |
-
huggingface_Data_name = 'qilan-
|
| 47 |
-
data_folder = '/data/SillyTavern' # 要压缩的目录
|
| 48 |
-
zip_file_path = '/dev/shm/a/sillytavern.tar.gz' # 输出的 tar.gz 文件路径
|
| 49 |
-
metadata_file_path = '/dev/shm/a/dataset-metadata.json'
|
| 50 |
configs = [
|
| 51 |
("""
|
| 52 |
[common]
|
| 53 |
server_addr = 47.237.156.222
|
| 54 |
server_port = 7000
|
| 55 |
|
| 56 |
-
[
|
| 57 |
type = tcp
|
| 58 |
local_ip = 127.0.0.1
|
| 59 |
local_port = 8000
|
| 60 |
-
remote_port =
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
[common]
|
| 64 |
-
server_addr =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
server_port=7000
|
| 66 |
-
[
|
| 67 |
type=tcp
|
| 68 |
local_ip=127.0.0.1
|
| 69 |
local_port=8000
|
| 70 |
-
remote_port=
|
| 71 |
-
""", '/
|
| 72 |
("""
|
| 73 |
[common]
|
| 74 |
-
server_addr =
|
| 75 |
server_port=7000
|
| 76 |
-
[
|
| 77 |
type=tcp
|
| 78 |
local_ip=127.0.0.1
|
| 79 |
local_port=8000
|
| 80 |
-
remote_port=
|
| 81 |
-
""", '/
|
| 82 |
("""
|
| 83 |
[common]
|
| 84 |
-
server_addr =
|
| 85 |
server_port=7000
|
| 86 |
-
[
|
| 87 |
type=tcp
|
| 88 |
local_ip=127.0.0.1
|
| 89 |
local_port=8000
|
| 90 |
-
remote_port=
|
| 91 |
-
""", '/
|
| 92 |
-
|
| 93 |
[common]
|
| 94 |
-
server_addr =
|
| 95 |
server_port=7000
|
| 96 |
-
[
|
| 97 |
type=tcp
|
| 98 |
local_ip=127.0.0.1
|
| 99 |
-
local_port=
|
| 100 |
-
remote_port=
|
| 101 |
-
""", '/
|
| 102 |
]
|
| 103 |
kaggle_metadata = {
|
| 104 |
"title": "Your Dataset Title",
|
|
@@ -106,25 +101,30 @@ kaggle_metadata = {
|
|
| 106 |
"licenses": [{"name": "CC0-1.0"}]
|
| 107 |
}
|
| 108 |
st_status = True
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# 创建 FRP 文件夹并下载 frpc 可执行文件。
|
| 113 |
-
os.system("
|
| 114 |
-
os.system("wget
|
| 115 |
-
os.system("
|
| 116 |
-
os.system("mkdir -p /data/frp")
|
| 117 |
-
os.system("wget /data/frp/frpc -q https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /data/frp/frpc")
|
| 118 |
-
os.system("chmod +x /data/frp/frpc")
|
| 119 |
-
os.system("wget -q https://huggingface.co/datasets/Qilan2/st-server/resolve/main/xugou-agent-linux-amd64?download=true -O /data/xugou-agent")
|
| 120 |
-
os.system("chmod +x /data/xugou-agent")
|
| 121 |
-
# os.system('nohup /data/xugou-agent start --server "https://tz.282820.xyz" --token "xugou_meqz1qus_80244ac171f1d9cf3a1ead6be2ecf86f.7d4ae786cbb7e559" --interval "30" > /data/xugou-agent.log 2>&1 &')
|
| 122 |
-
|
| 123 |
-
# os.system("wget -O '/data/nezha-agent-amd64' 'https://huggingface.co/datasets/Qilan2/st-server/resolve/main/nezha-agent-v0.17.6?download=true'")
|
| 124 |
-
# os.system("chmod +x /data/nezha-agent-amd64")
|
| 125 |
-
# os.system('nohup /data/nezha-agent-amd64 -s tzz.282820.xyz:443 -p aLLlygYqAXgjq9Anln --tls --debug --temperature --disable-force-update --disable-auto-update > nezha-agent-amd64.log 2>&1 &')
|
| 126 |
-
# os.system('/data/nezha-agent-amd64 -s tzz.282820.xyz:443 -p aLLlygYqAXgjq9Anln --tls --debug --temperature --disable-force-update --disable-auto-update')
|
| 127 |
-
|
| 128 |
import yaml
|
| 129 |
def nezha():
|
| 130 |
agent_config ={
|
|
@@ -147,7 +147,7 @@ def nezha():
|
|
| 147 |
'tls': True,
|
| 148 |
'use_gitee_to_upgrade': False,
|
| 149 |
'use_ipv6_country_code': False,
|
| 150 |
-
'uuid': '
|
| 151 |
}
|
| 152 |
with open('./config.yaml', 'w') as file:
|
| 153 |
yaml.dump(agent_config, file, default_flow_style=False)
|
|
@@ -156,10 +156,52 @@ def nezha():
|
|
| 156 |
os.system("chmod +x f1")
|
| 157 |
os.system('./f1 -c ./config.yaml')
|
| 158 |
os.system('./f1 -c ./config.yaml')
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
def kill_frpc_processes():
|
| 165 |
try:
|
|
@@ -172,9 +214,40 @@ def kill_frpc_processes():
|
|
| 172 |
kill_frpc_processes()
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
# 创建一个锁
|
| 176 |
lock = threading.Lock()
|
| 177 |
-
|
|
|
|
|
|
|
| 178 |
last_uploaded_size = -1
|
| 179 |
|
| 180 |
|
|
@@ -194,25 +267,17 @@ def get_folder_size(folder):
|
|
| 194 |
|
| 195 |
def compress_folder():
|
| 196 |
global last_uploaded_size # 声明使用全局变量
|
| 197 |
-
|
| 198 |
-
# 检查是否是中国时区早上5点
|
| 199 |
-
china_tz = pytz.timezone('Asia/Shanghai')
|
| 200 |
-
now = datetime.now(china_tz)
|
| 201 |
-
if now.hour == 5:
|
| 202 |
-
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 早上5点,跳过备份操作")
|
| 203 |
-
return
|
| 204 |
-
|
| 205 |
# 清理并创建目录 /a
|
| 206 |
-
if os.path.exists('/
|
| 207 |
-
subprocess.run(['rm', '-
|
| 208 |
-
os.makedirs('/
|
| 209 |
with lock: # 使用锁
|
| 210 |
# 获取当前文件夹的大小
|
| 211 |
current_folder_size = get_folder_size(data_folder)
|
| 212 |
print(f"当前文件夹大小: {current_folder_size} 字节")
|
| 213 |
|
| 214 |
# 判断文件夹大小是否大于 800MB (800MB = 800 * 1024 * 1024 字节)
|
| 215 |
-
if current_folder_size < (
|
| 216 |
print("文件夹小于800MB,不进行上传和压缩。")
|
| 217 |
return
|
| 218 |
|
|
@@ -222,7 +287,6 @@ def compress_folder():
|
|
| 222 |
try:
|
| 223 |
# 执行压缩
|
| 224 |
result = subprocess.run(
|
| 225 |
-
# tar -cvf - /data/SillyTavern | pigz -p 2 -1 > /dev/shm/a/sillytavern.tar.gz 2> /dev/null
|
| 226 |
f'tar -cvf - {data_folder} | pigz -p 2 -1 > {zip_file_path} 2> /dev/null',
|
| 227 |
shell=True,
|
| 228 |
check=True,
|
|
@@ -234,14 +298,14 @@ def compress_folder():
|
|
| 234 |
return
|
| 235 |
|
| 236 |
print('压缩完成')
|
| 237 |
-
file_path = "/
|
| 238 |
subprocess.run(['mv', zip_file_path, file_path])
|
| 239 |
print(f"数据压缩为 {file_path}")
|
| 240 |
|
| 241 |
file_size = os.path.getsize(file_path) # 获取压缩包的大小
|
| 242 |
print('文件大小:', file_size)
|
| 243 |
|
| 244 |
-
if file_size < (
|
| 245 |
print("压缩文件小于800MB,不进行上传。")
|
| 246 |
return
|
| 247 |
|
|
@@ -253,8 +317,7 @@ def compress_folder():
|
|
| 253 |
with open(metadata_file_path, 'w') as json_fid:
|
| 254 |
json.dump(kaggle_metadata, json_fid)
|
| 255 |
|
| 256 |
-
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/
|
| 257 |
-
#kaggle datasets version -m 'new version message' -p /dev/shm/a
|
| 258 |
last_uploaded_size = file_size
|
| 259 |
else:
|
| 260 |
print(f"新文件大小 {file_size} 大于上次上传的大小,正在执行上传...")
|
|
@@ -263,7 +326,7 @@ def compress_folder():
|
|
| 263 |
with open(metadata_file_path, 'w') as json_fid:
|
| 264 |
json.dump(kaggle_metadata, json_fid)
|
| 265 |
|
| 266 |
-
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/
|
| 267 |
last_uploaded_size = file_size
|
| 268 |
|
| 269 |
else:
|
|
@@ -273,11 +336,50 @@ def repeat_task():
|
|
| 273 |
print('------打包线程启动-------------')
|
| 274 |
while True:
|
| 275 |
print('等待打包')
|
| 276 |
-
|
| 277 |
-
time.sleep(10800)# 2小时
|
| 278 |
compress_folder()
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
|
| 283 |
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|
|
@@ -289,92 +391,34 @@ def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500,
|
|
| 289 |
session.mount('https://', adapter)
|
| 290 |
return session
|
| 291 |
|
| 292 |
-
def
|
| 293 |
-
"""
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
| 310 |
-
try:
|
| 311 |
-
# 检查进程的连接
|
| 312 |
-
connections = proc.net_connections()
|
| 313 |
-
|
| 314 |
-
# 检查是否有指定端口的连接
|
| 315 |
-
port_matches = [
|
| 316 |
-
conn for conn in connections
|
| 317 |
-
if conn.laddr.port == port
|
| 318 |
-
]
|
| 319 |
-
|
| 320 |
-
if port_matches:
|
| 321 |
-
pid = proc.pid
|
| 322 |
-
name = proc.name()
|
| 323 |
-
|
| 324 |
-
print(f"找到端口 {port} 相关进程: PID {pid}, 名称 {name}")
|
| 325 |
-
|
| 326 |
-
try:
|
| 327 |
-
# 尝试优雅地终止进程
|
| 328 |
-
parent = psutil.Process(pid)
|
| 329 |
-
|
| 330 |
-
# 终止进程及其所有子进程
|
| 331 |
-
for child_proc in parent.children(recursive=True):
|
| 332 |
-
try:
|
| 333 |
-
child_proc.terminate()
|
| 334 |
-
print(f"终止子进程: PID {child_proc.pid}")
|
| 335 |
-
except Exception as child_err:
|
| 336 |
-
print(f"无法终止子进程 {child_proc.pid}: {child_err}")
|
| 337 |
-
|
| 338 |
-
parent.terminate()
|
| 339 |
-
|
| 340 |
-
# 等待进程结束
|
| 341 |
-
gone, alive = psutil.wait_procs([parent], timeout=3)
|
| 342 |
-
|
| 343 |
-
for p in alive:
|
| 344 |
-
print(f"强制杀死进程: PID {p.pid}")
|
| 345 |
-
p.kill()
|
| 346 |
-
|
| 347 |
-
killed_processes['success'].append(pid)
|
| 348 |
-
print(f"成功终止进程 {pid}")
|
| 349 |
-
|
| 350 |
-
except psutil.NoSuchProcess:
|
| 351 |
-
print(f"进程 {pid} 已不存在")
|
| 352 |
-
except psutil.AccessDenied:
|
| 353 |
-
print(f"没有权限终止进程 {pid}")
|
| 354 |
-
killed_processes['failed'].append(pid)
|
| 355 |
-
except Exception as e:
|
| 356 |
-
print(f"终止进程 {pid} 时发生错误: {e}")
|
| 357 |
-
killed_processes['failed'].append(pid)
|
| 358 |
-
|
| 359 |
-
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
| 360 |
-
continue
|
| 361 |
-
|
| 362 |
-
except Exception as e:
|
| 363 |
-
print(f"搜索进程时发生错误: {e}")
|
| 364 |
-
|
| 365 |
-
# 打印总结报告
|
| 366 |
-
print("--- 进程终止报告 ---")
|
| 367 |
-
print(f"成功终止进程数: {len(killed_processes['success'])}")
|
| 368 |
-
print(f"终止失败进程数: {len(killed_processes['failed'])}")
|
| 369 |
-
|
| 370 |
-
if killed_processes['success']:
|
| 371 |
-
print(f"成功终止的进程 PID: {killed_processes['success']}")
|
| 372 |
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
| 377 |
|
|
|
|
|
|
|
| 378 |
|
| 379 |
def check_api1():
|
| 380 |
# 第一次检查 SillyTavern 是否启动
|
|
@@ -400,7 +444,54 @@ def check_api1():
|
|
| 400 |
|
| 401 |
time.sleep(5)
|
| 402 |
|
| 403 |
-
print('ST本地已经运行')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
def frp(configs, backstage):
|
| 406 |
print('-----------FRP开始-------------')
|
|
@@ -409,49 +500,122 @@ def frp(configs, backstage):
|
|
| 409 |
with open(config_file_path, 'w') as config_file:
|
| 410 |
config_file.write(config_data)
|
| 411 |
# 启动 frpc 命令和参数。
|
| 412 |
-
frpc_cmd=['/
|
| 413 |
|
| 414 |
if backstage:
|
| 415 |
subprocess.Popen(frpc_cmd)
|
| 416 |
else:
|
| 417 |
-
subprocess.run(f'/
|
| 418 |
print('-----------FRP结束-------------')
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
|
| 421 |
|
| 422 |
def monitor_port():
|
| 423 |
while True:
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
# 读取 config.ini 中的 monitor_port_enabled 配置项
|
| 429 |
-
config = configparser.ConfigParser()
|
| 430 |
-
config.read('/data/config.ini')
|
| 431 |
-
monitor_port_enabled = config.getboolean('general', 'monitor_port_enabled', fallback=False)
|
| 432 |
-
if monitor_port_enabled:
|
| 433 |
-
kill_processes_on_port()
|
| 434 |
-
backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
|
| 435 |
-
backup_thread.start()
|
| 436 |
else:
|
| 437 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
|
| 439 |
-
time.sleep(
|
| 440 |
def Run_SillyTavern():
|
|
|
|
| 441 |
try:
|
| 442 |
-
os.chdir('/data/SillyTavern')
|
| 443 |
# 启动 Node.js 服务器,并将输出重定向到 /dev/null
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
os.system("yes | sh ./start.sh")
|
| 450 |
-
# subprocess.run(f'yes | sh ./start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 451 |
-
# subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 452 |
-
# subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 453 |
-
# subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 454 |
-
# subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 455 |
|
| 456 |
print("已尝试启动 server.js")
|
| 457 |
except subprocess.CalledProcessError as e:
|
|
@@ -462,40 +626,17 @@ def Run_SillyTavern():
|
|
| 462 |
def SillyTavern():
|
| 463 |
print('-----------SillyTavern开始-------------')
|
| 464 |
# 创建目录并写入 kaggle.json
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
# 确保目录存在
|
| 472 |
-
os.makedirs(kaggle_dir, exist_ok=True)
|
| 473 |
|
| 474 |
-
|
| 475 |
-
try:
|
| 476 |
-
with open(kaggle_file_path, 'w') as json_file:
|
| 477 |
-
json.dump(ini_content, json_file, indent=4)
|
| 478 |
-
|
| 479 |
-
# 验证文件内容
|
| 480 |
-
with open(kaggle_file_path, 'r') as json_file:
|
| 481 |
-
print("文件内容:", json_file.read())
|
| 482 |
-
|
| 483 |
-
# 设置权限
|
| 484 |
-
os.chmod(kaggle_file_path, 0o600)
|
| 485 |
-
|
| 486 |
-
print(f"文件已写入: {kaggle_file_path}")
|
| 487 |
-
except Exception as e:
|
| 488 |
-
print(f"发生错误: {e}")
|
| 489 |
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
os.
|
| 493 |
-
# os.system(f"mkdir -p {data_folder}")
|
| 494 |
-
print('----当前文件夹路径--------')
|
| 495 |
-
os.system('pwd')
|
| 496 |
-
print('----进入/data--------')
|
| 497 |
-
os.chdir('/data')
|
| 498 |
-
|
| 499 |
print(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}")
|
| 500 |
# os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}")
|
| 501 |
download_n = 0
|
|
@@ -503,9 +644,9 @@ def SillyTavern():
|
|
| 503 |
# 执行下载命令
|
| 504 |
if download_n > 6:
|
| 505 |
break
|
| 506 |
-
os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name} -p /
|
| 507 |
# 检查文件是否存在
|
| 508 |
-
if os.path.exists(f'/
|
| 509 |
print(f"{huggingface_Data_name}.zip 下载成功!")
|
| 510 |
break # 跳出循环
|
| 511 |
print(f"{huggingface_Data_name}.zip 下载失败,正在重试...")
|
|
@@ -513,131 +654,52 @@ def SillyTavern():
|
|
| 513 |
time.sleep(300) # 等待一段时间再重试(例如5秒
|
| 514 |
# os.system('kaggle datasets download xovale7506/sillytavern-data2')
|
| 515 |
# 检查文件是否存在
|
| 516 |
-
if not os.path.exists(f'/
|
| 517 |
print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
|
| 518 |
-
|
|
|
|
|
|
|
| 519 |
else:
|
| 520 |
-
|
| 521 |
# 如果文件存在,可以继续执行后续代码
|
| 522 |
-
print(
|
| 523 |
-
# os.system("ls")
|
| 524 |
-
print(f"文件 /data/{huggingface_Data_name}.zip 存在,继续执行程序。")
|
| 525 |
# # 解压 sillytavern.zip
|
| 526 |
# os.system("rm *.zip")
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
os.system("mv /
|
| 530 |
-
# os.system("
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
os.system("
|
|
|
|
|
|
|
| 534 |
# os.system("pv /sillytavern.tar.gz | tar -xvpf - -C / --use-compress-program=pigz")
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
os.
|
| 540 |
-
os.system("
|
| 541 |
-
|
| 542 |
os.system(f"ls {data_folder}")
|
| 543 |
-
|
| 544 |
os.system("nvm install node")
|
| 545 |
os.system("nvm use node")
|
| 546 |
os.system("npm install -y")
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
# os.system(f"ls {data_folder}")
|
| 554 |
-
|
| 555 |
-
# Run_SillyTavern()
|
| 556 |
backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
|
| 557 |
backup_thread.start()
|
| 558 |
-
# os.system(f"rm -rf /a /data/sillytavern /data/data /data/*.zip /data/*.ctk")
|
| 559 |
-
# os.system("ls /data/")
|
| 560 |
|
| 561 |
print('-----------SillyTavern结束-------------')
|
| 562 |
-
import requests
|
| 563 |
-
|
| 564 |
-
def _reconstruct_token(partial_token):
|
| 565 |
-
"""
|
| 566 |
-
重构完整的 token
|
| 567 |
-
|
| 568 |
-
:param partial_token: 部分 token
|
| 569 |
-
:return: 完整的 token
|
| 570 |
-
"""
|
| 571 |
-
return partial_token.replace(" ", "")
|
| 572 |
-
|
| 573 |
-
def restart_huggingface_space(space_name, space_id, partial_token):
|
| 574 |
-
"""
|
| 575 |
-
重启 Hugging Face Space
|
| 576 |
-
|
| 577 |
-
:param space_name: Space 的命名空间
|
| 578 |
-
:param space_id: Space 的 ID
|
| 579 |
-
:param partial_token: Hugging Face 部分访问令牌
|
| 580 |
-
:return: 响应结果字典
|
| 581 |
-
"""
|
| 582 |
-
# 重构完整 token
|
| 583 |
-
token = _reconstruct_token(partial_token)
|
| 584 |
-
|
| 585 |
-
url = f"https://huggingface.co/api/spaces/{space_name}/{space_id}/restart?factory=true"
|
| 586 |
-
headers = {
|
| 587 |
-
"Content-Type": "application/json",
|
| 588 |
-
"Authorization": f"Bearer {token}",
|
| 589 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
|
| 590 |
-
}
|
| 591 |
-
|
| 592 |
-
try:
|
| 593 |
-
response = requests.post(url, headers=headers, json={})
|
| 594 |
-
return {
|
| 595 |
-
"status_code": response.status_code,
|
| 596 |
-
"success": response.status_code == 200,
|
| 597 |
-
"message": response.text
|
| 598 |
-
}
|
| 599 |
-
except requests.RequestException as e:
|
| 600 |
-
return {
|
| 601 |
-
"status_code": None,
|
| 602 |
-
"success": False,
|
| 603 |
-
"message": str(e)
|
| 604 |
-
}
|
| 605 |
-
|
| 606 |
-
# 使用示例
|
| 607 |
-
import psutil
|
| 608 |
-
|
| 609 |
-
def check_system_resources():
|
| 610 |
-
print("查看CPU占用情况")
|
| 611 |
-
time.sleep(120)
|
| 612 |
-
# 获取CPU使用率
|
| 613 |
-
cpu_usage = psutil.cpu_percent(interval=1)
|
| 614 |
-
|
| 615 |
-
# 获取内存使用率
|
| 616 |
-
memory = psutil.virtual_memory()
|
| 617 |
-
memory_usage = memory.percent
|
| 618 |
-
|
| 619 |
-
# 检查CPU和内存占用是否超过85%
|
| 620 |
-
# if cpu_usage >= 90:
|
| 621 |
-
if cpu_usage >= 90 or memory_usage >= 95:
|
| 622 |
-
print("占用过高")
|
| 623 |
-
# 可选:打印具体的使用率
|
| 624 |
-
print(f"CPU使用率: {cpu_usage}%")
|
| 625 |
-
print(f"内存使用率: {memory_usage}%")
|
| 626 |
-
result = restart_huggingface_space(huggingface_user, huggingface_id, huggingface_tokon)
|
| 627 |
-
print(result)
|
| 628 |
-
# time.sleep(6666666)
|
| 629 |
-
else:
|
| 630 |
-
print("系统资源正常")
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
# 调用函数
|
| 634 |
-
|
| 635 |
-
|
| 636 |
threading.Thread(target=SillyTavern, daemon=True).start()
|
| 637 |
-
# SillyTavern()
|
| 638 |
time.sleep(60)
|
| 639 |
check_api1()
|
| 640 |
-
|
| 641 |
|
| 642 |
# 创建 ConfigParser 对象
|
| 643 |
config = configparser.ConfigParser()
|
|
@@ -646,38 +708,27 @@ config.add_section('general')
|
|
| 646 |
# 设置 'monitor_port_enabled' 选项的值为 True
|
| 647 |
config.set('general', 'monitor_port_enabled', 'True')
|
| 648 |
# 将配置写入到 'config.ini' 文件中
|
| 649 |
-
with open('/
|
| 650 |
config.write(configfile)
|
| 651 |
-
|
| 652 |
-
|
|
|
|
| 653 |
backup_thread = threading.Thread(target=repeat_task, daemon=True)#压缩备份
|
| 654 |
backup_thread.start()
|
| 655 |
print("开始衔接")
|
| 656 |
Service_status = True
|
| 657 |
frp(configs, True)
|
| 658 |
threading.Thread(target=monitor_port, daemon=True).start()#检测端口状态
|
| 659 |
-
threading.Thread(target=check_system_resources, daemon=True).start()#检测CPU内存状态
|
| 660 |
-
# threading.Thread(target=sbx, daemon=True).start()
|
| 661 |
-
os.system("python /data/ip_huggingface.py")
|
| 662 |
-
os.system("python /data/ipn.py")
|
| 663 |
-
# time.sleep(600)
|
| 664 |
while True:
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
if now.hour == 6 and now.minute < 5: # 6:00-6:05之间退出
|
| 669 |
-
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
|
| 670 |
-
break
|
| 671 |
-
# else:
|
| 672 |
-
# print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
|
| 673 |
-
|
| 674 |
-
if backup_thread.is_alive() == False:
|
| 675 |
print("备份线程已停止.")
|
| 676 |
backup_thread = threading.Thread(target=repeat_task, daemon=True)
|
| 677 |
backup_thread.start()
|
|
|
|
| 678 |
time.sleep(5)
|
|
|
|
| 679 |
else:
|
| 680 |
-
print(
|
| 681 |
-
compress_folder()
|
| 682 |
-
result = restart_huggingface_space(huggingface_user, huggingface_id, huggingface_tokon)
|
| 683 |
-
print(result)
|
|
|
|
| 1 |
+
ini_content = {"username":"natclghpe","key":"21e32070151c7fe0fbd5af3287d7e489"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
frp_url = '119.8.118.149'
|
| 3 |
ssh_port = '7082'
|
| 4 |
ssh_url = '45.32.68.209'
|
| 5 |
+
st_url = f'http://{frp_url}:7082'
|
| 6 |
+
huggingface_name = 'natclghpe'
|
| 7 |
+
huggingface_Data_name = 'qilan-st9'
|
|
|
|
|
|
|
|
|
|
| 8 |
configs = [
|
| 9 |
("""
|
| 10 |
[common]
|
| 11 |
server_addr = 47.237.156.222
|
| 12 |
server_port = 7000
|
| 13 |
|
| 14 |
+
[safsa99]
|
| 15 |
type = tcp
|
| 16 |
local_ip = 127.0.0.1
|
| 17 |
local_port = 8000
|
| 18 |
+
remote_port = 7090
|
| 19 |
+
|
| 20 |
+
[sascb2f99]
|
| 21 |
+
type = tcp
|
| 22 |
+
local_ip = 127.0.0.1
|
| 23 |
+
local_port = 22
|
| 24 |
+
remote_port = 7089
|
| 25 |
+
""", '/content/frp/frpc.ini'),
|
| 26 |
+
(f"""
|
| 27 |
+
[common]
|
| 28 |
+
server_addr = {frp_url}
|
| 29 |
+
server_port = 7000
|
| 30 |
+
token = qilan
|
| 31 |
+
[1kkjmk99]
|
| 32 |
+
type = tcp
|
| 33 |
+
local_ip = 127.0.0.1
|
| 34 |
+
local_port = 8000
|
| 35 |
+
remote_port = 7082
|
| 36 |
+
""", '/content/frp/frpc1.ini'),
|
| 37 |
("""
|
| 38 |
+
[common]
|
| 39 |
+
server_addr = 43.134.75.213
|
| 40 |
+
server_port = 7000
|
| 41 |
+
[2kjas9]
|
| 42 |
+
type = tcp
|
| 43 |
+
local_ip = 127.0.0.1
|
| 44 |
+
local_port = 8000
|
| 45 |
+
remote_port = 7079
|
| 46 |
+
""", '/content/frp/frpc2.ini'),
|
| 47 |
+
("""
|
| 48 |
[common]
|
| 49 |
+
server_addr = 8.210.217.27
|
| 50 |
+
server_port = 7000
|
| 51 |
+
[3kja1sh9]
|
| 52 |
+
type = tcp
|
| 53 |
+
local_ip = 127.0.0.1
|
| 54 |
+
local_port = 8000
|
| 55 |
+
remote_port = 7079
|
| 56 |
+
""", '/content/frp/frpc3.ini'),
|
| 57 |
+
("""
|
| 58 |
+
[common]
|
| 59 |
+
server_addr = 45.32.68.209
|
| 60 |
server_port=7000
|
| 61 |
+
[4kkji1mk9]
|
| 62 |
type=tcp
|
| 63 |
local_ip=127.0.0.1
|
| 64 |
local_port=8000
|
| 65 |
+
remote_port=7079
|
| 66 |
+
""", '/content/frp/frpc4.ini'),
|
| 67 |
("""
|
| 68 |
[common]
|
| 69 |
+
server_addr = 47.74.57.131
|
| 70 |
server_port=7000
|
| 71 |
+
[4kkji1mk9]
|
| 72 |
type=tcp
|
| 73 |
local_ip=127.0.0.1
|
| 74 |
local_port=8000
|
| 75 |
+
remote_port=7090
|
| 76 |
+
""", '/content/frp/frpc6.ini'),
|
| 77 |
("""
|
| 78 |
[common]
|
| 79 |
+
server_addr = 47.243.129.107
|
| 80 |
server_port=7000
|
| 81 |
+
[4kkji1mk9]
|
| 82 |
type=tcp
|
| 83 |
local_ip=127.0.0.1
|
| 84 |
local_port=8000
|
| 85 |
+
remote_port=7090
|
| 86 |
+
""", '/content/frp/frpc7.ini'),
|
| 87 |
+
(f"""
|
| 88 |
[common]
|
| 89 |
+
server_addr = {ssh_url}
|
| 90 |
server_port=7000
|
| 91 |
+
[5kkji1mk99]
|
| 92 |
type=tcp
|
| 93 |
local_ip=127.0.0.1
|
| 94 |
+
local_port=22
|
| 95 |
+
remote_port={ssh_port}
|
| 96 |
+
""", '/content/frp/frpc5.ini')
|
| 97 |
]
|
| 98 |
kaggle_metadata = {
|
| 99 |
"title": "Your Dataset Title",
|
|
|
|
| 101 |
"licenses": [{"name": "CC0-1.0"}]
|
| 102 |
}
|
| 103 |
st_status = True
|
| 104 |
+
import subprocess
|
| 105 |
+
import os
|
| 106 |
+
import sys
|
| 107 |
+
import configparser
|
| 108 |
+
from IPython.display import clear_output
|
| 109 |
+
import urllib.request
|
| 110 |
+
from pathlib import Path
|
| 111 |
+
import requests
|
| 112 |
+
import json
|
| 113 |
+
import threading
|
| 114 |
+
import time
|
| 115 |
+
import pexpect
|
| 116 |
+
import socket
|
| 117 |
+
import time
|
| 118 |
+
import glob # 导入 glob 模块
|
| 119 |
+
from requests.adapters import HTTPAdapter
|
| 120 |
+
from requests.packages.urllib3.util.retry import Retry
|
| 121 |
+
os.system("rm -r /sync.sh")
|
| 122 |
+
os.system("wget -O /sync.sh https://huggingface.co/datasets/Qilan2/st-server/resolve/main/sync.sh")
|
| 123 |
+
os.system("export LC_ALL=zh_CN.UTF-8")
|
| 124 |
# 创建 FRP 文件夹并下载 frpc 可执行文件。
|
| 125 |
+
os.system("mkdir -p /content/frp")
|
| 126 |
+
os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc")
|
| 127 |
+
os.system("chmod +x /content/frp/frpc")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
import yaml
|
| 129 |
def nezha():
|
| 130 |
agent_config ={
|
|
|
|
| 147 |
'tls': True,
|
| 148 |
'use_gitee_to_upgrade': False,
|
| 149 |
'use_ipv6_country_code': False,
|
| 150 |
+
'uuid': '1c552ffd-7c75-4a60-9811-8098c859e19b'
|
| 151 |
}
|
| 152 |
with open('./config.yaml', 'w') as file:
|
| 153 |
yaml.dump(agent_config, file, default_flow_style=False)
|
|
|
|
| 156 |
os.system("chmod +x f1")
|
| 157 |
os.system('./f1 -c ./config.yaml')
|
| 158 |
os.system('./f1 -c ./config.yaml')
|
| 159 |
+
# threading.Thread(target=nezha, daemon=True).start()
|
| 160 |
+
# 更新软件包列表
|
| 161 |
+
def is_installed(package):
|
| 162 |
+
"""Check if a package is installed."""
|
| 163 |
+
try:
|
| 164 |
+
# Check if the package is installed using dpkg (for apt packages)
|
| 165 |
+
subprocess.run(['dpkg', '-s', package], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 166 |
+
return True
|
| 167 |
+
except Exception as e:
|
| 168 |
+
return False
|
| 169 |
+
|
| 170 |
+
def install_package(package):
|
| 171 |
+
"""Install a package using apt."""
|
| 172 |
+
print(f"Installing {package}...")
|
| 173 |
+
os.system(f"sudo apt install {package} -y")
|
| 174 |
+
def update():
|
| 175 |
+
print('-----------更新软件包列表开始-------------')
|
| 176 |
+
# os.system("sudo apt update")
|
| 177 |
+
# 安装 Node.js 和 npm
|
| 178 |
+
# os.system("sudo apt install nodejs npm -y")
|
| 179 |
+
# # 全局安装 forever
|
| 180 |
+
# os.system("sudo npm install -g forever")
|
| 181 |
+
if not is_installed('nodejs'):
|
| 182 |
+
install_package('nodejs')
|
| 183 |
+
|
| 184 |
+
if not is_installed('npm'):
|
| 185 |
+
install_package('npm')
|
| 186 |
+
# 安装 p7zip-full
|
| 187 |
+
os.system("pip uninstall requests urllib3 -y")
|
| 188 |
+
os.system("pip install requests urllib3")
|
| 189 |
+
os.system("sudo apt install p7zip-full -y")
|
| 190 |
+
# os.system("pip install -U kaggle")
|
| 191 |
+
# os.system("pip uninstall -y kaggle > /dev/null 2>&1")
|
| 192 |
+
# os.system("pip install kaggle==1.5.6 > /dev/null 2>&1")
|
| 193 |
+
# os.system("apt-get install inotify-tools")
|
| 194 |
+
os.system("pip install ruamel.yaml") # install ruamel.yaml to solve the import issue
|
| 195 |
+
os.system("pip install pexpect")
|
| 196 |
+
os.system("pip install pytz")
|
| 197 |
+
os.system('apt-get install pigz')
|
| 198 |
+
os.system('apt-get install pv')
|
| 199 |
+
print('-----------更新软件包列表结束-------------')
|
| 200 |
+
update()
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
from ruamel.yaml import YAML
|
| 204 |
+
clear_output(wait=True) # 清除输出
|
| 205 |
|
| 206 |
def kill_frpc_processes():
|
| 207 |
try:
|
|
|
|
| 214 |
kill_frpc_processes()
|
| 215 |
|
| 216 |
|
| 217 |
+
# SSH
|
| 218 |
+
def run_command(command):
|
| 219 |
+
try:
|
| 220 |
+
subprocess.run(command, check=True, shell=True)
|
| 221 |
+
except subprocess.CalledProcessError as e:
|
| 222 |
+
print(f"An error occurred: {e}")
|
| 223 |
+
def ssh():
|
| 224 |
+
print('-----------SSH开始-------------')
|
| 225 |
+
subprocess.run("apt update", check=True, shell=True)
|
| 226 |
+
subprocess.run("apt install openssh-server -y", check=True, shell=True)
|
| 227 |
+
subprocess.run("apt-get install vim -y", check=True, shell=True)
|
| 228 |
+
|
| 229 |
+
config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config"
|
| 230 |
+
subprocess.run(config_client_cmd, check=True, shell=True)
|
| 231 |
+
config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config"
|
| 232 |
+
subprocess.run(config_server_cmd, check=True, shell=True)
|
| 233 |
+
run_command("systemctl restart ssh")
|
| 234 |
+
|
| 235 |
+
os.system("/etc/init.d/ssh restart")
|
| 236 |
+
os.system("echo 'root:qilan' | sudo chpasswd")
|
| 237 |
+
os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config")
|
| 238 |
+
os.system("service ssh restart ")
|
| 239 |
+
os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ")
|
| 240 |
+
print('-----------SSH结束-------------')
|
| 241 |
+
ssh()
|
| 242 |
+
clear_output()
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
|
| 246 |
# 创建一个锁
|
| 247 |
lock = threading.Lock()
|
| 248 |
+
data_folder = '/root/SillyTavern' # 要压缩的目录
|
| 249 |
+
zip_file_path = '/a/sillytavern.tar.gz' # 输出的 tar.gz 文件路径
|
| 250 |
+
metadata_file_path = '/a/dataset-metadata.json'
|
| 251 |
last_uploaded_size = -1
|
| 252 |
|
| 253 |
|
|
|
|
| 267 |
|
| 268 |
def compress_folder():
|
| 269 |
global last_uploaded_size # 声明使用全局变量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
# 清理并创建目录 /a
|
| 271 |
+
if os.path.exists('/a'):
|
| 272 |
+
subprocess.run(['rm', '-r', '/a/'])
|
| 273 |
+
os.makedirs('/a', exist_ok=True)
|
| 274 |
with lock: # 使用锁
|
| 275 |
# 获取当前文件夹的大小
|
| 276 |
current_folder_size = get_folder_size(data_folder)
|
| 277 |
print(f"当前文件夹大小: {current_folder_size} 字节")
|
| 278 |
|
| 279 |
# 判断文件夹大小是否大于 800MB (800MB = 800 * 1024 * 1024 字节)
|
| 280 |
+
if current_folder_size < (800 * 1024 ** 2):
|
| 281 |
print("文件夹小于800MB,不进行上传和压缩。")
|
| 282 |
return
|
| 283 |
|
|
|
|
| 287 |
try:
|
| 288 |
# 执行压缩
|
| 289 |
result = subprocess.run(
|
|
|
|
| 290 |
f'tar -cvf - {data_folder} | pigz -p 2 -1 > {zip_file_path} 2> /dev/null',
|
| 291 |
shell=True,
|
| 292 |
check=True,
|
|
|
|
| 298 |
return
|
| 299 |
|
| 300 |
print('压缩完成')
|
| 301 |
+
file_path = "/a/sillytavern.ctk"
|
| 302 |
subprocess.run(['mv', zip_file_path, file_path])
|
| 303 |
print(f"数据压缩为 {file_path}")
|
| 304 |
|
| 305 |
file_size = os.path.getsize(file_path) # 获取压缩包的大小
|
| 306 |
print('文件大小:', file_size)
|
| 307 |
|
| 308 |
+
if file_size < (800 * 1024 ** 2): # 判断压缩后的大小是否小于 800MB
|
| 309 |
print("压缩文件小于800MB,不进行上传。")
|
| 310 |
return
|
| 311 |
|
|
|
|
| 317 |
with open(metadata_file_path, 'w') as json_fid:
|
| 318 |
json.dump(kaggle_metadata, json_fid)
|
| 319 |
|
| 320 |
+
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a'])
|
|
|
|
| 321 |
last_uploaded_size = file_size
|
| 322 |
else:
|
| 323 |
print(f"新文件大小 {file_size} 大于上次上传的大小,正在执行上传...")
|
|
|
|
| 326 |
with open(metadata_file_path, 'w') as json_fid:
|
| 327 |
json.dump(kaggle_metadata, json_fid)
|
| 328 |
|
| 329 |
+
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a'])
|
| 330 |
last_uploaded_size = file_size
|
| 331 |
|
| 332 |
else:
|
|
|
|
| 336 |
print('------打包线程启动-------------')
|
| 337 |
while True:
|
| 338 |
print('等待打包')
|
| 339 |
+
time.sleep(18000)
|
|
|
|
| 340 |
compress_folder()
|
| 341 |
+
print('------打包线程结束-------------')
|
| 342 |
+
# repeat_task()
|
| 343 |
+
# compress_folder()
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def generate_ssh_key():
|
| 348 |
+
# 生成 SSH 密钥对,并捕获输出和错误信息
|
| 349 |
+
os.system("rm -f ~/.ssh/id_rsa ~/.ssh/id_rsa.pub")
|
| 350 |
+
keygen_command = "ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -N ''"
|
| 351 |
+
try:
|
| 352 |
+
result = subprocess.run(keygen_command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 353 |
+
print("SSH key pair generated.")
|
| 354 |
+
print(result.stdout.decode()) # 打印标准输出信息(如成功消息)
|
| 355 |
+
except subprocess.CalledProcessError as e:
|
| 356 |
+
print(f"Failed to generate SSH key: {e.stderr.decode() if e.stderr else e}")
|
| 357 |
|
| 358 |
+
def copy_public_key_to_remote(host, port, user, password):
|
| 359 |
+
# 使用 pexpect 自动输入密码来复制公钥
|
| 360 |
+
try:
|
| 361 |
+
command = f"ssh-copy-id -o StrictHostKeyChecking=no -p {port} {user}@{host}"
|
| 362 |
+
child = pexpect.spawn(command)
|
| 363 |
+
|
| 364 |
+
# 等待密码提示并发送密码
|
| 365 |
+
child.expect("password:", timeout=10) # 增加超时时间
|
| 366 |
+
child.sendline(password)
|
| 367 |
+
|
| 368 |
+
# 等待命令完成并输出结果
|
| 369 |
+
child.expect(pexpect.EOF)
|
| 370 |
+
|
| 371 |
+
print(child.before.decode()) # 打印输出结果
|
| 372 |
+
|
| 373 |
+
except Exception as e:
|
| 374 |
+
print(f"An error occurred: {e}")
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
# 生成 SSH 密钥对
|
| 378 |
+
generate_ssh_key()
|
| 379 |
+
os.system('chmod 600 ~/.ssh/id_rsa')
|
| 380 |
+
# 复制公钥到远程服务器
|
| 381 |
+
copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan")
|
| 382 |
+
|
| 383 |
|
| 384 |
|
| 385 |
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|
|
|
|
| 391 |
session.mount('https://', adapter)
|
| 392 |
return session
|
| 393 |
|
| 394 |
+
def write_rsyncd_conf(path, port=7075):
|
| 395 |
+
rsyncd_conf_content = f"""
|
| 396 |
+
port = {port}
|
| 397 |
+
|
| 398 |
+
[qilan]
|
| 399 |
+
path = {path}
|
| 400 |
+
comment = My rsync module
|
| 401 |
+
read only = no
|
| 402 |
+
list = yes
|
| 403 |
+
"""
|
| 404 |
+
with open('/etc/rsyncd.conf', 'w') as f:
|
| 405 |
+
f.write(rsyncd_conf_content.strip())
|
| 406 |
+
print(f"Successfully wrote to /etc/rsyncd.conf for module .")
|
| 407 |
+
os.system("sudo rsync --daemon")
|
| 408 |
+
os.system("sudo rsync --daemon")
|
| 409 |
+
os.system("sudo rsync --daemon")
|
| 410 |
+
os.system("sudo rsync --daemon")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
+
# write_rsyncd_conf(data_folder)
|
| 413 |
+
# os.system("ps aux | grep rsync")
|
| 414 |
+
import os
|
| 415 |
+
import time
|
| 416 |
+
import requests
|
| 417 |
+
import subprocess
|
| 418 |
+
import logging
|
| 419 |
|
| 420 |
+
# 配置日志
|
| 421 |
+
logging.basicConfig(level=logging.INFO)
|
| 422 |
|
| 423 |
def check_api1():
|
| 424 |
# 第一次检查 SillyTavern 是否启动
|
|
|
|
| 444 |
|
| 445 |
time.sleep(5)
|
| 446 |
|
| 447 |
+
print('ST本地已经运行,开始检测接口状态')
|
| 448 |
+
Service_status = False
|
| 449 |
+
n = 0
|
| 450 |
+
nn = 0
|
| 451 |
+
while True:
|
| 452 |
+
n += 1
|
| 453 |
+
if not os.path.exists(data_folder):
|
| 454 |
+
print(f"/sillytavern/ 文件不存在,结束检测")
|
| 455 |
+
break
|
| 456 |
+
if Service_status:
|
| 457 |
+
print("结束检测")
|
| 458 |
+
break
|
| 459 |
+
if nn > 2:
|
| 460 |
+
break
|
| 461 |
+
url = f"{st_url}/csrf-token"
|
| 462 |
+
try:
|
| 463 |
+
response = requests_retry_session().get(url, timeout=30)
|
| 464 |
+
response.raise_for_status()
|
| 465 |
+
response_json = response.json()
|
| 466 |
+
print("%s 接口返回信息: %s", url, response_json) # 修正日志记录
|
| 467 |
+
if "token" in response_json:
|
| 468 |
+
print("检测到 token")
|
| 469 |
+
try:
|
| 470 |
+
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)
|
| 471 |
+
# break # 如果成功,跳出重试循环
|
| 472 |
+
except subprocess.CalledProcessError as e:
|
| 473 |
+
nn += 1
|
| 474 |
+
print(f"Rsync 失败,返回码: {e.returncode}, 尝试次数: {nn}")
|
| 475 |
+
generate_ssh_key() # 处理 SSH 密钥生成
|
| 476 |
+
else:
|
| 477 |
+
print("%s 接口返回信息: %s", url, response_json) # 修正日志记录
|
| 478 |
+
except requests.exceptions.ConnectionError as e:
|
| 479 |
+
print(f"接口异常1: {e}, 尝试次数: {n}, nn: {nn}")
|
| 480 |
+
# time.sleep(3)
|
| 481 |
+
nn += 1
|
| 482 |
+
if nn > 5:
|
| 483 |
+
break
|
| 484 |
+
except requests.exceptions.Timeout as e:
|
| 485 |
+
print(f"接口异常2: {e}, 尝试次数: {n}")
|
| 486 |
+
break
|
| 487 |
+
except requests.exceptions.RequestException as e:
|
| 488 |
+
print(f"接口异常3: {e}, 尝试次数: {n}")
|
| 489 |
+
break
|
| 490 |
+
|
| 491 |
+
time.sleep(5)
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
|
| 495 |
|
| 496 |
def frp(configs, backstage):
|
| 497 |
print('-----------FRP开始-------------')
|
|
|
|
| 500 |
with open(config_file_path, 'w') as config_file:
|
| 501 |
config_file.write(config_data)
|
| 502 |
# 启动 frpc 命令和参数。
|
| 503 |
+
frpc_cmd=['/content/frp/frpc', '-c', config_file_path]
|
| 504 |
|
| 505 |
if backstage:
|
| 506 |
subprocess.Popen(frpc_cmd)
|
| 507 |
else:
|
| 508 |
+
subprocess.run(f'/content/frp/frpc -c {config_file_path}', shell=True, check=True)
|
| 509 |
print('-----------FRP结束-------------')
|
| 510 |
|
| 511 |
+
import requests
|
| 512 |
+
import re
|
| 513 |
+
from datetime import datetime, timedelta
|
| 514 |
+
import psutil # 用于获取系统启动时间
|
| 515 |
+
import pytz # 用于处理时区
|
| 516 |
+
|
| 517 |
+
def get_current_ip():
|
| 518 |
+
"""获取当前公共 IP 地址"""
|
| 519 |
+
response = requests.get("https://ipinfo.io/ip")
|
| 520 |
+
return response.text.strip()
|
| 521 |
+
|
| 522 |
+
def get_geo_info(ip_address):
|
| 523 |
+
"""根据 IP 地址获取地理位置信息"""
|
| 524 |
+
url = f"https://api.qjqq.cn/api/Local"
|
| 525 |
+
headers = {
|
| 526 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
response = requests.get(url, headers=headers)
|
| 530 |
+
|
| 531 |
+
if response.status_code == 200:
|
| 532 |
+
geo_info = response.json()
|
| 533 |
+
|
| 534 |
+
if geo_info['code'] == 200:
|
| 535 |
+
data = geo_info['data']
|
| 536 |
+
return {
|
| 537 |
+
'ip': data['ip'],
|
| 538 |
+
'country': data['country'],
|
| 539 |
+
'isp': data['isp']
|
| 540 |
+
}
|
| 541 |
+
return None
|
| 542 |
+
|
| 543 |
+
def get_next_relay_time():
|
| 544 |
+
"""获取下一次接力时间(系统启动时间+12小时,转换为中国时区)"""
|
| 545 |
+
# 获取系统启动时间
|
| 546 |
+
boot_time = datetime.fromtimestamp(psutil.boot_time())
|
| 547 |
+
# 设置为UTC时区
|
| 548 |
+
utc = pytz.UTC
|
| 549 |
+
boot_time = utc.localize(boot_time)
|
| 550 |
+
# 转换为中国时区
|
| 551 |
+
china_tz = pytz.timezone('Asia/Shanghai')
|
| 552 |
+
boot_time_china = boot_time.astimezone(china_tz)
|
| 553 |
+
# 加上12小时
|
| 554 |
+
next_time = boot_time_china + timedelta(hours=12)
|
| 555 |
+
return next_time.strftime("%Y-%m-%d %H:%M:%S")
|
| 556 |
+
|
| 557 |
+
def replace_info_in_file(file_path):
|
| 558 |
+
try:
|
| 559 |
+
# 获取当前 IP 地址和地理信息
|
| 560 |
+
ip_address = get_current_ip()
|
| 561 |
+
geo_info = get_geo_info(ip_address)
|
| 562 |
+
next_relay_time = get_next_relay_time()
|
| 563 |
+
|
| 564 |
+
if geo_info is not None:
|
| 565 |
+
# 读取文件内容
|
| 566 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 567 |
+
content = file.read()
|
| 568 |
+
|
| 569 |
+
# 替换接力时间
|
| 570 |
+
time_pattern = r'接力时间\[.*?\]'
|
| 571 |
+
time_replacement = f'接力时间[{next_relay_time}]'
|
| 572 |
+
content = re.sub(time_pattern, time_replacement, content)
|
| 573 |
+
|
| 574 |
+
# 替换 IP 信息
|
| 575 |
+
ip_pattern = r'IP\[.*?\]\s*国家\s*\[.*?\]\s*IPS\[.*?\]'
|
| 576 |
+
ip_replacement = f'IP[{ip_address}] 国家 [{geo_info["country"]}] IPS[{geo_info["isp"]}]'
|
| 577 |
+
content = re.sub(ip_pattern, ip_replacement, content)
|
| 578 |
+
|
| 579 |
+
# 写回文件
|
| 580 |
+
with open(file_path, 'w', encoding='utf-8') as file:
|
| 581 |
+
file.write(content)
|
| 582 |
+
|
| 583 |
+
print(f"成功更新信息:")
|
| 584 |
+
print(f"接力时间: {next_relay_time}")
|
| 585 |
+
print(f"IP信息: IP[{ip_address}] 国家 [{geo_info['country']}] IPS[{geo_info['isp']}]")
|
| 586 |
+
|
| 587 |
+
except Exception as e:
|
| 588 |
+
print(f"发生错误: {e}")
|
| 589 |
|
| 590 |
|
| 591 |
def monitor_port():
|
| 592 |
while True:
|
| 593 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 594 |
+
result = sock.connect_ex(('localhost', 8000))
|
| 595 |
+
if result == 0:
|
| 596 |
+
print(f"端口 8000 正在使用中")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
else:
|
| 598 |
+
print(f"端口 8000 未被使用")
|
| 599 |
+
# 读取 config.ini 中的 monitor_port_enabled 配置项
|
| 600 |
+
config = configparser.ConfigParser()
|
| 601 |
+
config.read('/config.ini')
|
| 602 |
+
monitor_port_enabled = config.getboolean('general', 'monitor_port_enabled', fallback=False)
|
| 603 |
+
if monitor_port_enabled:
|
| 604 |
+
backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
|
| 605 |
+
backup_thread.start()
|
| 606 |
+
else:
|
| 607 |
+
print(f"monitor_port_enabled 为False跳过")
|
| 608 |
|
| 609 |
+
time.sleep(5) # 每5秒检查一次
|
| 610 |
def Run_SillyTavern():
|
| 611 |
+
os.chdir(data_folder)
|
| 612 |
try:
|
|
|
|
| 613 |
# 启动 Node.js 服务器,并将输出重定向到 /dev/null
|
| 614 |
+
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 615 |
+
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 616 |
+
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 617 |
+
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
| 618 |
+
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
|
| 620 |
print("已尝试启动 server.js")
|
| 621 |
except subprocess.CalledProcessError as e:
|
|
|
|
| 626 |
def SillyTavern():
|
| 627 |
print('-----------SillyTavern开始-------------')
|
| 628 |
# 创建目录并写入 kaggle.json
|
| 629 |
+
os.system("mkdir -p ~/.kaggle")
|
| 630 |
+
file_path = '/root/.kaggle/kaggle.json'
|
| 631 |
+
with open(file_path, 'w') as json_file:
|
| 632 |
+
json.dump(ini_content, json_file, indent=4)
|
| 633 |
+
os.system("chmod 600 ~/.kaggle/kaggle.json")
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
+
clear_output()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
|
| 637 |
+
os.system(f"rm -r /a /sillytavern /*.zi* {data_folder}")
|
| 638 |
+
os.system(f"mkdir -p {data_folder}")
|
| 639 |
+
os.chdir('/')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
print(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}")
|
| 641 |
# os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}")
|
| 642 |
download_n = 0
|
|
|
|
| 644 |
# 执行下载命令
|
| 645 |
if download_n > 6:
|
| 646 |
break
|
| 647 |
+
os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name} -p /")
|
| 648 |
# 检查文件是否存在
|
| 649 |
+
if os.path.exists(f'/{huggingface_Data_name}.zip'):
|
| 650 |
print(f"{huggingface_Data_name}.zip 下载成功!")
|
| 651 |
break # 跳出循环
|
| 652 |
print(f"{huggingface_Data_name}.zip 下载失败,正在重试...")
|
|
|
|
| 654 |
time.sleep(300) # 等待一段时间再重试(例如5秒
|
| 655 |
# os.system('kaggle datasets download xovale7506/sillytavern-data2')
|
| 656 |
# 检查文件是否存在
|
| 657 |
+
if not os.path.exists(f'/{huggingface_Data_name}.zip'):
|
| 658 |
print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。")
|
| 659 |
+
generate_ssh_key()
|
| 660 |
+
copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan")
|
| 661 |
+
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)
|
| 662 |
else:
|
| 663 |
+
|
| 664 |
# 如果文件存在,可以继续执行后续代码
|
| 665 |
+
print(f"文件 /{huggingface_Data_name}.zip 存在,继续执行程序。")
|
|
|
|
|
|
|
| 666 |
# # 解压 sillytavern.zip
|
| 667 |
# os.system("rm *.zip")
|
| 668 |
+
|
| 669 |
+
os.system(f"7z x /{huggingface_Data_name}.zip -o/ -y")
|
| 670 |
+
# os.system("mv /sillytavern.zip1 /sillytavern.zip")
|
| 671 |
+
# os.system("7z x /sillytavern.zip -o/sillytavern -y")
|
| 672 |
+
os.system("mv /sillytavern.tck sillytavern.tar.gz")
|
| 673 |
+
os.system("mv /sillytavern.ctk sillytavern.tar.gz")
|
| 674 |
+
os.system("ls /")
|
| 675 |
+
# os.system("tar -xvpf /sillytavern.tar.gz -C / --use-compress-program=pigz")
|
| 676 |
+
os.system(f"tar -xvpf /sillytavern.tar.gz -C / --use-compress-program=pigz > /dev/null")
|
| 677 |
# os.system("pv /sillytavern.tar.gz | tar -xvpf - -C / --use-compress-program=pigz")
|
| 678 |
+
|
| 679 |
+
print('更新文件')
|
| 680 |
+
# os.system('git pull --rebase --autostash')
|
| 681 |
+
os.system("rm-r ip.py")
|
| 682 |
+
os.system("wget -O /root/SillyTavern/ip.py https://huggingface.co/datasets/Qilan2/st-server/raw/main/ip.py")
|
| 683 |
+
os.system("python /root/SillyTavern/ip.py")
|
| 684 |
+
os.chdir(data_folder)
|
| 685 |
os.system(f"ls {data_folder}")
|
|
|
|
| 686 |
os.system("nvm install node")
|
| 687 |
os.system("nvm use node")
|
| 688 |
os.system("npm install -y")
|
| 689 |
+
try:
|
| 690 |
+
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, check=True)
|
| 691 |
+
except subprocess.CalledProcessError as e:
|
| 692 |
+
print(f"Command '{e.cmd}' returned non-zero exit status {e.returncode}.")
|
| 693 |
+
print("Output:", e.output)
|
| 694 |
+
os.system(f"ls {data_folder}")
|
|
|
|
|
|
|
|
|
|
| 695 |
backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
|
| 696 |
backup_thread.start()
|
|
|
|
|
|
|
| 697 |
|
| 698 |
print('-----------SillyTavern结束-------------')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
threading.Thread(target=SillyTavern, daemon=True).start()
|
|
|
|
| 700 |
time.sleep(60)
|
| 701 |
check_api1()
|
| 702 |
+
|
| 703 |
|
| 704 |
# 创建 ConfigParser 对象
|
| 705 |
config = configparser.ConfigParser()
|
|
|
|
| 708 |
# 设置 'monitor_port_enabled' 选项的值为 True
|
| 709 |
config.set('general', 'monitor_port_enabled', 'True')
|
| 710 |
# 将配置写入到 'config.ini' 文件中
|
| 711 |
+
with open('/config.ini', 'w') as configfile:
|
| 712 |
config.write(configfile)
|
| 713 |
+
os.system("rm -r /qilan-st9.zip /sillytavern.tar.gz")
|
| 714 |
+
if os.path.exists(f'{data_folder}/start.sh'):
|
| 715 |
+
replace_info_in_file(f'{data_folder}/public/login.html')
|
| 716 |
backup_thread = threading.Thread(target=repeat_task, daemon=True)#压缩备份
|
| 717 |
backup_thread.start()
|
| 718 |
print("开始衔接")
|
| 719 |
Service_status = True
|
| 720 |
frp(configs, True)
|
| 721 |
threading.Thread(target=monitor_port, daemon=True).start()#检测端口状态
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
while True:
|
| 723 |
+
if backup_thread.is_alive():
|
| 724 |
+
print("备份线程仍在运行...")
|
| 725 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 726 |
print("备份线程已停止.")
|
| 727 |
backup_thread = threading.Thread(target=repeat_task, daemon=True)
|
| 728 |
backup_thread.start()
|
| 729 |
+
# break
|
| 730 |
time.sleep(5)
|
| 731 |
+
|
| 732 |
else:
|
| 733 |
+
print("/sillytavern 文件不存在结束执行")
|
| 734 |
+
compress_folder()
|
|
|
|
|
|