|
|
ini_content = {"username":"ighlnvd551","key":"14dee8c2e790b386ca7a61e974537d66"} |
|
|
frp_url = '119.8.118.149' |
|
|
ssh_port = '7079' |
|
|
ssh_url = '43.129.165.236' |
|
|
st_url = f'http://{frp_url}:7080' |
|
|
huggingface_name = 'ighlnvd551' |
|
|
huggingface_Data_name = 'qilan-st6' |
|
|
configs = [ |
|
|
(""" |
|
|
[common] |
|
|
server_addr = 47.237.156.222 |
|
|
server_port = 7000 |
|
|
|
|
|
[safsa66] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 8000 |
|
|
remote_port = 7082 |
|
|
|
|
|
[sascb2f66] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 22 |
|
|
remote_port = 7083 |
|
|
""", '/content/frp/frpc.ini'), |
|
|
(f""" |
|
|
[common] |
|
|
server_addr = {frp_url} |
|
|
server_port = 7000 |
|
|
token = qilan |
|
|
[kkjmk66] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 8000 |
|
|
remote_port = 7080 |
|
|
""", '/content/frp/frpc1.ini'), |
|
|
(""" |
|
|
[common] |
|
|
server_addr = 47.83.213.60 |
|
|
server_port = 7000 |
|
|
[kjas6] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 8000 |
|
|
remote_port = 7076 |
|
|
""", '/content/frp/frpc2.ini'), |
|
|
(""" |
|
|
[common] |
|
|
server_addr = 8.217.51.145 |
|
|
server_port = 7000 |
|
|
[kja1sh6] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 8000 |
|
|
remote_port = 7076 |
|
|
""", '/content/frp/frpc3.ini'), |
|
|
(""" |
|
|
[common] |
|
|
server_addr = 43.134.179.252 |
|
|
server_port=7000 |
|
|
[kkji1mk6] |
|
|
type=tcp |
|
|
local_ip=127.0.0.1 |
|
|
local_port=8000 |
|
|
remote_port=7076 |
|
|
""", '/content/frp/frpc4.ini'), |
|
|
(""" |
|
|
[common] |
|
|
server_addr = 47.74.57.131 |
|
|
server_port=7000 |
|
|
[4kknbgf6] |
|
|
type=tcp |
|
|
local_ip=127.0.0.1 |
|
|
local_port=8000 |
|
|
remote_port=7080 |
|
|
""", '/content/frp/frpc6.ini'), |
|
|
(""" |
|
|
[common] |
|
|
server_addr = 47.243.129.107 |
|
|
server_port=7000 |
|
|
[4ktytu6] |
|
|
type=tcp |
|
|
local_ip=127.0.0.1 |
|
|
local_port=8000 |
|
|
remote_port=7082 |
|
|
""", '/content/frp/frpc7.ini'), |
|
|
(f""" |
|
|
[common] |
|
|
server_addr = {ssh_url} |
|
|
server_port=7000 |
|
|
[kkji1mk6] |
|
|
type=tcp |
|
|
local_ip=127.0.0.1 |
|
|
local_port=22 |
|
|
remote_port={ssh_port} |
|
|
""", '/content/frp/frpc5.ini') |
|
|
] |
|
|
kaggle_metadata = { |
|
|
"title": "Your Dataset Title", |
|
|
"id": f"{huggingface_name}/{huggingface_Data_name}", |
|
|
"licenses": [{"name": "CC0-1.0"}] |
|
|
} |
|
|
st_status = True |
|
|
import subprocess |
|
|
import os |
|
|
import sys |
|
|
import configparser |
|
|
from IPython.display import clear_output |
|
|
import urllib.request |
|
|
from pathlib import Path |
|
|
import requests |
|
|
import json |
|
|
import threading |
|
|
import time |
|
|
import pexpect |
|
|
import socket |
|
|
import time |
|
|
import glob |
|
|
from requests.adapters import HTTPAdapter |
|
|
from requests.packages.urllib3.util.retry import Retry |
|
|
os.system("rm -r /sync.sh") |
|
|
os.system("wget -O /sync.sh https://huggingface.co/datasets/Qilan2/st-server/resolve/main/sync.sh") |
|
|
os.system("export LC_ALL=zh_CN.UTF-8") |
|
|
|
|
|
os.system("mkdir -p /content/frp") |
|
|
os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc") |
|
|
os.system("chmod +x /content/frp/frpc") |
|
|
import yaml |
|
|
def nezha(): |
|
|
agent_config ={ |
|
|
'client_secret': 'MLcD6YnifhoY08B9n129UP5cg2139NYa', |
|
|
'debug': False, |
|
|
'disable_auto_update': True, |
|
|
'disable_command_execute': False, |
|
|
'disable_force_update': False, |
|
|
'disable_nat': False, |
|
|
'disable_send_query': False, |
|
|
'gpu': False, |
|
|
'insecure_tls': False, |
|
|
'ip_report_period': 1800, |
|
|
'report_delay': 3, |
|
|
'self_update_period': 0, |
|
|
'server': 'z.282820.xyz:443', |
|
|
'skip_connection_count': False, |
|
|
'skip_procs_count': False, |
|
|
'temperature': True, |
|
|
'tls': True, |
|
|
'use_gitee_to_upgrade': False, |
|
|
'use_ipv6_country_code': False, |
|
|
'uuid': 'e023051b-dcd2-490e-ba84-47b9aef256bc' |
|
|
} |
|
|
with open('./config.yaml', 'w') as file: |
|
|
yaml.dump(agent_config, file, default_flow_style=False) |
|
|
os.system("rm -rf f1") |
|
|
os.system("wget -O 'f1' -q 'https://huggingface.co/datasets/Qilan2/st-server/resolve/main/nv1amd64?download=true'") |
|
|
os.system("chmod +x f1") |
|
|
os.system('./f1 -c ./config.yaml') |
|
|
os.system('./f1 -c ./config.yaml') |
|
|
threading.Thread(target=nezha, daemon=True).start() |
|
|
|
|
|
def is_installed(package): |
|
|
"""Check if a package is installed.""" |
|
|
try: |
|
|
|
|
|
subprocess.run(['dpkg', '-s', package], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
return True |
|
|
except Exception as e: |
|
|
return False |
|
|
|
|
|
def install_package(package): |
|
|
"""Install a package using apt.""" |
|
|
print(f"Installing {package}...") |
|
|
os.system(f"sudo apt install {package} -y") |
|
|
def update(): |
|
|
print('-----------更新软件包列表开始-------------') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not is_installed('nodejs'): |
|
|
install_package('nodejs') |
|
|
|
|
|
if not is_installed('npm'): |
|
|
install_package('npm') |
|
|
|
|
|
os.system("sudo apt install p7zip-full -y") |
|
|
os.system("pip install -U kaggle") |
|
|
os.system("pip uninstall -y kaggle > /dev/null 2>&1") |
|
|
os.system("pip install kaggle==1.5.6 > /dev/null 2>&1") |
|
|
|
|
|
os.system("pip install ruamel.yaml") |
|
|
os.system("pip install pexpect") |
|
|
os.system("pip install pytz") |
|
|
os.system('apt-get install pigz') |
|
|
os.system('apt-get install pv') |
|
|
print('-----------更新软件包列表结束-------------') |
|
|
update() |
|
|
|
|
|
|
|
|
from ruamel.yaml import YAML |
|
|
clear_output(wait=True) |
|
|
|
|
|
def kill_frpc_processes(): |
|
|
try: |
|
|
|
|
|
subprocess.run(['pkill', '-f', 'frpc'], check=True) |
|
|
print("所有frpc进程已被结束。") |
|
|
except subprocess.CalledProcessError as e: |
|
|
|
|
|
print(f"结束frpc进程时出错: {e}") |
|
|
kill_frpc_processes() |
|
|
|
|
|
|
|
|
|
|
|
def run_command(command): |
|
|
try: |
|
|
subprocess.run(command, check=True, shell=True) |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"An error occurred: {e}") |
|
|
def ssh(): |
|
|
print('-----------SSH开始-------------') |
|
|
subprocess.run("apt update", check=True, shell=True) |
|
|
subprocess.run("apt install openssh-server -y", check=True, shell=True) |
|
|
subprocess.run("apt-get install vim -y", check=True, shell=True) |
|
|
|
|
|
config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config" |
|
|
subprocess.run(config_client_cmd, check=True, shell=True) |
|
|
config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config" |
|
|
subprocess.run(config_server_cmd, check=True, shell=True) |
|
|
run_command("systemctl restart ssh") |
|
|
|
|
|
os.system("/etc/init.d/ssh restart") |
|
|
os.system("echo 'root:qilan' | sudo chpasswd") |
|
|
os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config") |
|
|
os.system("service ssh restart ") |
|
|
os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ") |
|
|
print('-----------SSH结束-------------') |
|
|
ssh() |
|
|
clear_output() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lock = threading.Lock() |
|
|
data_folder = '/root/SillyTavern' |
|
|
zip_file_path = '/a/sillytavern.tar.gz' |
|
|
metadata_file_path = '/a/dataset-metadata.json' |
|
|
last_uploaded_size = -1 |
|
|
|
|
|
|
|
|
def update_last_uploaded_size(size): |
|
|
global last_uploaded_size |
|
|
last_uploaded_size = size |
|
|
|
|
|
def get_folder_size(folder): |
|
|
"""使用 du 命令获取文件夹的总大小(字节数)""" |
|
|
result = subprocess.run(['du', '-sb', folder], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
if result.returncode == 0: |
|
|
size = result.stdout.split()[0] |
|
|
return int(size) |
|
|
else: |
|
|
print(f"Error calculating size: {result.stderr.decode()}") |
|
|
return 0 |
|
|
|
|
|
def compress_folder(): |
|
|
global last_uploaded_size |
|
|
|
|
|
if os.path.exists('/a'): |
|
|
subprocess.run(['rm', '-r', '/a/']) |
|
|
os.makedirs('/a', exist_ok=True) |
|
|
with lock: |
|
|
|
|
|
current_folder_size = get_folder_size(data_folder) |
|
|
print(f"当前文件夹大小: {current_folder_size} 字节") |
|
|
|
|
|
|
|
|
if current_folder_size < (800 * 1024 ** 2): |
|
|
print("文件夹小于800MB,不进行上传和压缩。") |
|
|
return |
|
|
|
|
|
|
|
|
if last_uploaded_size == -1 or current_folder_size != last_uploaded_size: |
|
|
print('开始压缩数据') |
|
|
try: |
|
|
|
|
|
result = subprocess.run( |
|
|
f'tar -cvf - {data_folder} | pigz -p 2 -1 > {zip_file_path} 2> /dev/null', |
|
|
shell=True, |
|
|
check=True, |
|
|
stdout=subprocess.DEVNULL, |
|
|
stderr=subprocess.DEVNULL |
|
|
) |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"命令失败,返回代码: {e.returncode}") |
|
|
return |
|
|
|
|
|
print('压缩完成') |
|
|
file_path = "/a/sillytavern.ctk" |
|
|
subprocess.run(['mv', zip_file_path, file_path]) |
|
|
print(f"数据压缩为 {file_path}") |
|
|
|
|
|
file_size = os.path.getsize(file_path) |
|
|
print('文件大小:', file_size) |
|
|
|
|
|
if file_size < (800 * 1024 ** 2): |
|
|
print("压缩文件小于800MB,不进行上传。") |
|
|
return |
|
|
|
|
|
|
|
|
if last_uploaded_size == -1: |
|
|
print("首次运行,正在执行上传...") |
|
|
update_last_uploaded_size(file_size) |
|
|
|
|
|
with open(metadata_file_path, 'w') as json_fid: |
|
|
json.dump(kaggle_metadata, json_fid) |
|
|
|
|
|
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a']) |
|
|
last_uploaded_size = file_size |
|
|
else: |
|
|
print(f"新文件大小 {file_size} 大于上次上传的大小,正在执行上传...") |
|
|
update_last_uploaded_size(file_size) |
|
|
|
|
|
with open(metadata_file_path, 'w') as json_fid: |
|
|
json.dump(kaggle_metadata, json_fid) |
|
|
|
|
|
subprocess.run(['kaggle', 'datasets', 'version', '-m', 'new version message', '-p', '/a']) |
|
|
last_uploaded_size = file_size |
|
|
|
|
|
else: |
|
|
print(f"新文件夹大小 {current_folder_size} 不大于上次上传的大小,跳过") |
|
|
|
|
|
def repeat_task(): |
|
|
print('------打包线程启动-------------') |
|
|
while True: |
|
|
print('等待打包') |
|
|
time.sleep(18000) |
|
|
compress_folder() |
|
|
print('------打包线程结束-------------') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_ssh_key(): |
|
|
|
|
|
os.system("rm -f ~/.ssh/id_rsa ~/.ssh/id_rsa.pub") |
|
|
keygen_command = "ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -N ''" |
|
|
try: |
|
|
result = subprocess.run(keygen_command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
print("SSH key pair generated.") |
|
|
print(result.stdout.decode()) |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"Failed to generate SSH key: {e.stderr.decode() if e.stderr else e}") |
|
|
|
|
|
def copy_public_key_to_remote(host, port, user, password): |
|
|
|
|
|
try: |
|
|
command = f"ssh-copy-id -o StrictHostKeyChecking=no -p {port} {user}@{host}" |
|
|
child = pexpect.spawn(command) |
|
|
|
|
|
|
|
|
child.expect("password:", timeout=10) |
|
|
child.sendline(password) |
|
|
|
|
|
|
|
|
child.expect(pexpect.EOF) |
|
|
|
|
|
print(child.before.decode()) |
|
|
|
|
|
except Exception as e: |
|
|
print(f"An error occurred: {e}") |
|
|
|
|
|
|
|
|
|
|
|
generate_ssh_key() |
|
|
os.system('chmod 600 ~/.ssh/id_rsa') |
|
|
|
|
|
copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan") |
|
|
|
|
|
|
|
|
|
|
|
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None): |
|
|
"""创建一个带重试机制的请求会话""" |
|
|
session = session or requests.Session() |
|
|
retry = Retry(total=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist) |
|
|
adapter = HTTPAdapter(max_retries=retry) |
|
|
session.mount('http://', adapter) |
|
|
session.mount('https://', adapter) |
|
|
return session |
|
|
|
|
|
def write_rsyncd_conf(path, port=7075): |
|
|
rsyncd_conf_content = f""" |
|
|
port = {port} |
|
|
|
|
|
[qilan] |
|
|
path = {path} |
|
|
comment = My rsync module |
|
|
read only = no |
|
|
list = yes |
|
|
""" |
|
|
with open('/etc/rsyncd.conf', 'w') as f: |
|
|
f.write(rsyncd_conf_content.strip()) |
|
|
print(f"Successfully wrote to /etc/rsyncd.conf for module .") |
|
|
os.system("sudo rsync --daemon") |
|
|
os.system("sudo rsync --daemon") |
|
|
os.system("sudo rsync --daemon") |
|
|
os.system("sudo rsync --daemon") |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
import time |
|
|
import requests |
|
|
import subprocess |
|
|
import logging |
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
|
|
def check_api1(): |
|
|
|
|
|
thread_started = False |
|
|
n = 0 |
|
|
while True: |
|
|
n += 1 |
|
|
if not os.path.exists(data_folder): |
|
|
logging.error(f"/sillytavern/ 文件不存在,结束检测") |
|
|
break |
|
|
try: |
|
|
url = "http://127.0.0.1:8000/v1" |
|
|
response = requests.get(url, timeout=30) |
|
|
|
|
|
if response.status_code == 403: |
|
|
print("SillyTavern已经启动") |
|
|
break |
|
|
|
|
|
print("SillyTavern未启动,状态码:", response.status_code, n) |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
print(f"SillyTavern未启动3: {e}, 尝试次数: {n}") |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
print('ST本地已经运行,开始检测接口状态') |
|
|
Service_status = False |
|
|
n = 0 |
|
|
nn = 0 |
|
|
while True: |
|
|
n += 1 |
|
|
if not os.path.exists(data_folder): |
|
|
print(f"/sillytavern/ 文件不存在,结束检测") |
|
|
break |
|
|
if Service_status: |
|
|
print("结束检测") |
|
|
break |
|
|
if nn > 2: |
|
|
break |
|
|
url = f"{st_url}/csrf-token" |
|
|
try: |
|
|
response = requests_retry_session().get(url, timeout=30) |
|
|
response.raise_for_status() |
|
|
response_json = response.json() |
|
|
print("%s 接口返回信息: %s", url, response_json) |
|
|
if "token" in response_json: |
|
|
print("检测到 token") |
|
|
try: |
|
|
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) |
|
|
|
|
|
except subprocess.CalledProcessError as e: |
|
|
nn += 1 |
|
|
print(f"Rsync 失败,返回码: {e.returncode}, 尝试次数: {nn}") |
|
|
generate_ssh_key() |
|
|
else: |
|
|
print("%s 接口返回信息: %s", url, response_json) |
|
|
except requests.exceptions.ConnectionError as e: |
|
|
print(f"接口异常1: {e}, 尝试次数: {n}, nn: {nn}") |
|
|
|
|
|
nn += 1 |
|
|
if nn > 5: |
|
|
break |
|
|
except requests.exceptions.Timeout as e: |
|
|
print(f"接口异常2: {e}, 尝试次数: {n}") |
|
|
break |
|
|
except requests.exceptions.RequestException as e: |
|
|
print(f"接口异常3: {e}, 尝试次数: {n}") |
|
|
break |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def frp(configs, backstage): |
|
|
print('-----------FRP开始-------------') |
|
|
|
|
|
for config_data, config_file_path in configs: |
|
|
with open(config_file_path, 'w') as config_file: |
|
|
config_file.write(config_data) |
|
|
|
|
|
frpc_cmd=['/content/frp/frpc', '-c', config_file_path] |
|
|
|
|
|
if backstage: |
|
|
subprocess.Popen(frpc_cmd) |
|
|
else: |
|
|
subprocess.run(f'/content/frp/frpc -c {config_file_path}', shell=True, check=True) |
|
|
print('-----------FRP结束-------------') |
|
|
|
|
|
import requests |
|
|
import re |
|
|
from datetime import datetime, timedelta |
|
|
import psutil |
|
|
import pytz |
|
|
|
|
|
def get_current_ip(): |
|
|
"""获取当前公共 IP 地址""" |
|
|
response = requests.get("https://ipinfo.io/ip") |
|
|
return response.text.strip() |
|
|
|
|
|
def get_geo_info(ip_address): |
|
|
"""根据 IP 地址获取地理位置信息""" |
|
|
url = f"https://api.qjqq.cn/api/Local" |
|
|
headers = { |
|
|
"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" |
|
|
} |
|
|
|
|
|
response = requests.get(url, headers=headers) |
|
|
|
|
|
if response.status_code == 200: |
|
|
geo_info = response.json() |
|
|
|
|
|
if geo_info['code'] == 200: |
|
|
data = geo_info['data'] |
|
|
return { |
|
|
'ip': data['ip'], |
|
|
'country': data['country'], |
|
|
'isp': data['isp'] |
|
|
} |
|
|
return None |
|
|
|
|
|
def get_next_relay_time(): |
|
|
"""获取下一次接力时间(系统启动时间+12小时,转换为中国时区)""" |
|
|
|
|
|
boot_time = datetime.fromtimestamp(psutil.boot_time()) |
|
|
|
|
|
utc = pytz.UTC |
|
|
boot_time = utc.localize(boot_time) |
|
|
|
|
|
china_tz = pytz.timezone('Asia/Shanghai') |
|
|
boot_time_china = boot_time.astimezone(china_tz) |
|
|
|
|
|
next_time = boot_time_china + timedelta(hours=12) |
|
|
return next_time.strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
|
|
def replace_info_in_file(file_path): |
|
|
try: |
|
|
|
|
|
ip_address = get_current_ip() |
|
|
geo_info = get_geo_info(ip_address) |
|
|
next_relay_time = get_next_relay_time() |
|
|
|
|
|
if geo_info is not None: |
|
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as file: |
|
|
content = file.read() |
|
|
|
|
|
|
|
|
time_pattern = r'接力时间\[.*?\]' |
|
|
time_replacement = f'接力时间[{next_relay_time}]' |
|
|
content = re.sub(time_pattern, time_replacement, content) |
|
|
|
|
|
|
|
|
ip_pattern = r'IP\[.*?\]\s*国家\s*\[.*?\]\s*IPS\[.*?\]' |
|
|
ip_replacement = f'IP[{ip_address}] 国家 [{geo_info["country"]}] IPS[{geo_info["isp"]}]' |
|
|
content = re.sub(ip_pattern, ip_replacement, content) |
|
|
|
|
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as file: |
|
|
file.write(content) |
|
|
|
|
|
print(f"成功更新信息:") |
|
|
print(f"接力时间: {next_relay_time}") |
|
|
print(f"IP信息: IP[{ip_address}] 国家 [{geo_info['country']}] IPS[{geo_info['isp']}]") |
|
|
|
|
|
except Exception as e: |
|
|
print(f"发生错误: {e}") |
|
|
|
|
|
|
|
|
def monitor_port(): |
|
|
while True: |
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: |
|
|
result = sock.connect_ex(('localhost', 8000)) |
|
|
if result == 0: |
|
|
print(f"端口 8000 正在使用中") |
|
|
else: |
|
|
print(f"端口 8000 未被使用") |
|
|
|
|
|
config = configparser.ConfigParser() |
|
|
config.read('/config.ini') |
|
|
monitor_port_enabled = config.getboolean('general', 'monitor_port_enabled', fallback=False) |
|
|
if monitor_port_enabled: |
|
|
backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True) |
|
|
backup_thread.start() |
|
|
else: |
|
|
print(f"monitor_port_enabled 为False跳过") |
|
|
|
|
|
time.sleep(5) |
|
|
def Run_SillyTavern(): |
|
|
os.chdir(data_folder) |
|
|
os.system("rm-r ip.py") |
|
|
os.system("wget -O ip.py https://huggingface.co/datasets/Qilan2/st-server/raw/main/ip.py") |
|
|
os.system("python ip.py") |
|
|
try: |
|
|
|
|
|
subprocess.run(f'nohup sh -c "echo yes | sh {data_folder}/start.sh" > /server.log 2>&1 &', shell=True) |
|
|
subprocess.run(f'nohup sh -c "echo yes | sh {data_folder}/start.sh" > /server.log 2>&1 &', shell=True) |
|
|
subprocess.run(f'nohup sh -c "echo yes | sh {data_folder}/start.sh" > /server.log 2>&1 &', shell=True) |
|
|
subprocess.run(f'nohup sh -c "echo yes | sh {data_folder}/start.sh" > /server.log 2>&1 &', shell=True) |
|
|
subprocess.run(f'nohup sh -c "echo yes | sh {data_folder}/start.sh" > /server.log 2>&1 &', shell=True) |
|
|
print("已尝试启动 server.js") |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"命令失败,返回码: {e.returncode}") |
|
|
except Exception as e: |
|
|
print(f"发生异常: {e}") |
|
|
|
|
|
def SillyTavern(): |
|
|
print('-----------SillyTavern开始-------------') |
|
|
|
|
|
os.system("mkdir -p ~/.kaggle") |
|
|
file_path = '/root/.kaggle/kaggle.json' |
|
|
with open(file_path, 'w') as json_file: |
|
|
json.dump(ini_content, json_file, indent=4) |
|
|
os.system("chmod 600 ~/.kaggle/kaggle.json") |
|
|
|
|
|
clear_output() |
|
|
|
|
|
os.system(f"rm -r /a /sillytavern /*.zi* {data_folder}") |
|
|
os.system(f"mkdir -p {data_folder}") |
|
|
os.chdir('/') |
|
|
print(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name}") |
|
|
|
|
|
download_n = 0 |
|
|
while True: |
|
|
|
|
|
if download_n > 6: |
|
|
break |
|
|
os.system(f"kaggle datasets download {huggingface_name}/{huggingface_Data_name} -p /") |
|
|
|
|
|
if os.path.exists(f'/{huggingface_Data_name}.zip'): |
|
|
print(f"{huggingface_Data_name}.zip 下载成功!") |
|
|
break |
|
|
print(f"{huggingface_Data_name}.zip 下载失败,正在重试...") |
|
|
download_n += 1 |
|
|
time.sleep(300) |
|
|
|
|
|
|
|
|
if not os.path.exists(f'/{huggingface_Data_name}.zip'): |
|
|
print(f"文件 /{huggingface_Data_name}.zip 不存在,启用实时同步。") |
|
|
generate_ssh_key() |
|
|
copy_public_key_to_remote(ssh_url, ssh_port, "root", "qilan") |
|
|
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) |
|
|
else: |
|
|
|
|
|
|
|
|
print(f"文件 /{huggingface_Data_name}.zip 存在,继续执行程序。") |
|
|
|
|
|
|
|
|
|
|
|
os.system(f"7z x /{huggingface_Data_name}.zip -o/ -y") |
|
|
|
|
|
|
|
|
os.system("mv /sillytavern.tck sillytavern.tar.gz") |
|
|
os.system("mv /sillytavern.ctk sillytavern.tar.gz") |
|
|
os.system("ls /") |
|
|
|
|
|
os.system(f"tar -xvpf /sillytavern.tar.gz -C / --use-compress-program=pigz > /dev/null") |
|
|
|
|
|
|
|
|
print('更新文件') |
|
|
|
|
|
|
|
|
os.chdir(data_folder) |
|
|
os.system(f"ls {data_folder}") |
|
|
os.system("nvm install node") |
|
|
os.system("nvm use node") |
|
|
os.system("npm install -y") |
|
|
try: |
|
|
subprocess.run(f'yes | sh {data_folder}/start.sh', shell=True, check=True) |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"Command '{e.cmd}' returned non-zero exit status {e.returncode}.") |
|
|
print("Output:", e.output) |
|
|
os.system(f"ls {data_folder}") |
|
|
backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True) |
|
|
backup_thread.start() |
|
|
os.system("rm -r /qilan-st2.zip /sillytavern.tar.gz") |
|
|
print('-----------SillyTavern结束-------------') |
|
|
threading.Thread(target=SillyTavern, daemon=True).start() |
|
|
time.sleep(60) |
|
|
check_api1() |
|
|
|
|
|
|
|
|
|
|
|
config = configparser.ConfigParser() |
|
|
|
|
|
config.add_section('general') |
|
|
|
|
|
config.set('general', 'monitor_port_enabled', 'True') |
|
|
|
|
|
with open('/config.ini', 'w') as configfile: |
|
|
config.write(configfile) |
|
|
|
|
|
if os.path.exists(f'{data_folder}/start.sh'): |
|
|
replace_info_in_file(f'{data_folder}/public/login.html') |
|
|
backup_thread = threading.Thread(target=repeat_task, daemon=True) |
|
|
backup_thread.start() |
|
|
print("开始衔接") |
|
|
Service_status = True |
|
|
frp(configs, True) |
|
|
threading.Thread(target=monitor_port, daemon=True).start() |
|
|
while True: |
|
|
if backup_thread.is_alive(): |
|
|
print("备份线程仍在运行...") |
|
|
else: |
|
|
print("备份线程已停止.") |
|
|
backup_thread = threading.Thread(target=repeat_task, daemon=True) |
|
|
backup_thread.start() |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
else: |
|
|
print("/sillytavern 文件不存在结束执行") |
|
|
compress_folder() |