Update server.py
Browse files
server.py
CHANGED
|
@@ -25,24 +25,33 @@ kaggle_metadata = {
|
|
| 25 |
"id": "xovale7506/sillytavern-data",
|
| 26 |
"licenses": [{"name": "CC0-1.0"}]
|
| 27 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
import subprocess
|
| 29 |
import os
|
| 30 |
from IPython.display import clear_output
|
| 31 |
import urllib.request
|
| 32 |
from pathlib import Path
|
|
|
|
| 33 |
import json
|
| 34 |
import threading
|
| 35 |
import time
|
| 36 |
import glob # 导入 glob 模块
|
| 37 |
-
# 更新软件包列表
|
| 38 |
-
os.system("sudo apt update")
|
| 39 |
-
# 安装 Node.js 和 npm
|
| 40 |
-
os.system("sudo apt install nodejs npm -y")
|
| 41 |
-
# 全局安装 forever
|
| 42 |
-
os.system("sudo npm install -g forever")
|
| 43 |
-
# 安装 p7zip-full
|
| 44 |
-
os.system("sudo apt install p7zip-full -y")
|
| 45 |
clear_output(wait=True) # 清除输出
|
|
|
|
| 46 |
def kill_frpc_processes():
|
| 47 |
try:
|
| 48 |
# 使用pkill命令结束所有frpc进程
|
|
@@ -59,43 +68,28 @@ def Oneapi():
|
|
| 59 |
# 删除旧的 one-api 文件夹(如果存在)
|
| 60 |
os.system("rm -rf /one/one-api") # 使用 -f 参数以避免错误
|
| 61 |
os.system("mkdir -p /one") # 创建目录
|
| 62 |
-
|
| 63 |
# 下载 one-api 文件
|
| 64 |
url = "https://github.com/songquanpeng/one-api/releases/download/v0.6.8/one-api"
|
| 65 |
os.system(f"wget {url} -O /one/one-api") # 正确下载并重命名为 /one/one-api
|
| 66 |
-
|
| 67 |
# 修改文件权限,使其可执行
|
| 68 |
os.system("chmod +x /one/one-api")
|
| 69 |
-
|
| 70 |
# 设置环境变量
|
| 71 |
os.environ["THEME"] = "berry"
|
| 72 |
os.environ["TIKTOKEN_CACHE_DIR"] = os.getcwd() # 使用Python的os.getcwd()获取当前工作目录
|
| 73 |
-
|
| 74 |
# 设置MySQL数据库的环境变量
|
| 75 |
db_user = "oneapi"
|
| 76 |
db_password = "epBjK5ZKysCe6yr3"
|
| 77 |
db_host = "106.52.51.116"
|
| 78 |
db_port = "3306"
|
| 79 |
db_name = "oneapi"
|
| 80 |
-
|
| 81 |
dsn = f"{db_user}:{db_password}@tcp({db_host}:{db_port})/{db_name}"
|
| 82 |
-
|
| 83 |
os.environ["SQL_DSN"] = dsn
|
| 84 |
-
|
| 85 |
command = ['/one/one-api', '--port', '3000']
|
| 86 |
-
|
| 87 |
process = subprocess.Popen(command) # 启动程序并将其放到后台执行
|
| 88 |
-
|
| 89 |
print(f"OneAPI程序已在后台启动,进程ID为:{process.pid}")
|
| 90 |
-
|
| 91 |
# Oneapi()
|
| 92 |
|
| 93 |
# SSH
|
| 94 |
-
def run_command(command):
|
| 95 |
-
try:
|
| 96 |
-
subprocess.run(command, check=True, shell=True)
|
| 97 |
-
except subprocess.CalledProcessError as e:
|
| 98 |
-
print(f"An error occurred: {e}")
|
| 99 |
def ssh():
|
| 100 |
subprocess.run("apt update", check=True, shell=True)
|
| 101 |
subprocess.run("apt install openssh-server -y", check=True, shell=True)
|
|
@@ -111,61 +105,65 @@ def ssh():
|
|
| 111 |
os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config")
|
| 112 |
os.system("service ssh restart ")
|
| 113 |
os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ")
|
| 114 |
-
os.system("pip install ruamel.yaml") # install ruamel.yaml to solve the import issue
|
| 115 |
ssh()
|
| 116 |
clear_output()
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
os.system("
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
os.system("mkdir -p /sillytavern")
|
| 133 |
-
os.system("cd /")
|
| 134 |
-
os.system("pip install -U kaggle")
|
| 135 |
-
os.system("kaggle datasets download xovale7506/sillytavern-data")
|
| 136 |
-
|
| 137 |
-
# # 解压 sillytavern.zip
|
| 138 |
-
os.system("7z x /sillytavern-data.zip -o/ -y")
|
| 139 |
-
os.system("mv /sillytavern.zip1 /sillytavern.zip")
|
| 140 |
-
os.system("7z x /sillytavern.zip -o/sillytavern -y")
|
| 141 |
-
os.system("rm *.zip")
|
| 142 |
-
clear_output()
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
#
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
os.system("
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
os.system("
|
| 163 |
-
os.system("
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
#
|
| 169 |
-
#
|
| 170 |
-
#
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
"id": "xovale7506/sillytavern-data",
|
| 26 |
"licenses": [{"name": "CC0-1.0"}]
|
| 27 |
}
|
| 28 |
+
|
| 29 |
+
# 更新软件包列表
|
| 30 |
+
def update():
|
| 31 |
+
print('-----------更新软件包列表开始-------------')
|
| 32 |
+
os.system("sudo apt update")
|
| 33 |
+
# 安装 Node.js 和 npm
|
| 34 |
+
os.system("sudo apt install nodejs npm -y")
|
| 35 |
+
# 全局安装 forever
|
| 36 |
+
os.system("sudo npm install -g forever")
|
| 37 |
+
# 安装 p7zip-full
|
| 38 |
+
os.system("sudo apt install p7zip-full -y")
|
| 39 |
+
os.system("pip install -U kaggle")
|
| 40 |
+
os.system("pip install ruamel.yaml") # install ruamel.yaml to solve the import issue
|
| 41 |
+
print('-----------更新软件包列表结束-------------')
|
| 42 |
+
|
| 43 |
import subprocess
|
| 44 |
import os
|
| 45 |
from IPython.display import clear_output
|
| 46 |
import urllib.request
|
| 47 |
from pathlib import Path
|
| 48 |
+
from ruamel.yaml import YAML
|
| 49 |
import json
|
| 50 |
import threading
|
| 51 |
import time
|
| 52 |
import glob # 导入 glob 模块
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
clear_output(wait=True) # 清除输出
|
| 54 |
+
|
| 55 |
def kill_frpc_processes():
|
| 56 |
try:
|
| 57 |
# 使用pkill命令结束所有frpc进程
|
|
|
|
| 68 |
# 删除旧的 one-api 文件夹(如果存在)
|
| 69 |
os.system("rm -rf /one/one-api") # 使用 -f 参数以避免错误
|
| 70 |
os.system("mkdir -p /one") # 创建目录
|
|
|
|
| 71 |
# 下载 one-api 文件
|
| 72 |
url = "https://github.com/songquanpeng/one-api/releases/download/v0.6.8/one-api"
|
| 73 |
os.system(f"wget {url} -O /one/one-api") # 正确下载并重命名为 /one/one-api
|
|
|
|
| 74 |
# 修改文件权限,使其可执行
|
| 75 |
os.system("chmod +x /one/one-api")
|
|
|
|
| 76 |
# 设置环境变量
|
| 77 |
os.environ["THEME"] = "berry"
|
| 78 |
os.environ["TIKTOKEN_CACHE_DIR"] = os.getcwd() # 使用Python的os.getcwd()获取当前工作目录
|
|
|
|
| 79 |
# 设置MySQL数据库的环境变量
|
| 80 |
db_user = "oneapi"
|
| 81 |
db_password = "epBjK5ZKysCe6yr3"
|
| 82 |
db_host = "106.52.51.116"
|
| 83 |
db_port = "3306"
|
| 84 |
db_name = "oneapi"
|
|
|
|
| 85 |
dsn = f"{db_user}:{db_password}@tcp({db_host}:{db_port})/{db_name}"
|
|
|
|
| 86 |
os.environ["SQL_DSN"] = dsn
|
|
|
|
| 87 |
command = ['/one/one-api', '--port', '3000']
|
|
|
|
| 88 |
process = subprocess.Popen(command) # 启动程序并将其放到后台执行
|
|
|
|
| 89 |
print(f"OneAPI程序已在后台启动,进程ID为:{process.pid}")
|
|
|
|
| 90 |
# Oneapi()
|
| 91 |
|
| 92 |
# SSH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
def ssh():
|
| 94 |
subprocess.run("apt update", check=True, shell=True)
|
| 95 |
subprocess.run("apt install openssh-server -y", check=True, shell=True)
|
|
|
|
| 105 |
os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config")
|
| 106 |
os.system("service ssh restart ")
|
| 107 |
os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ")
|
|
|
|
| 108 |
ssh()
|
| 109 |
clear_output()
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
+
def frp():
|
| 114 |
+
'''FRP配置'''
|
| 115 |
+
os.system("mkdir -p /content/frp")
|
| 116 |
+
os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc")
|
| 117 |
+
os.system("chmod +x /content/frp/frpc")
|
| 118 |
+
config_file_path = '/content/frp/frpc.ini'
|
| 119 |
+
with open(config_file_path, 'w') as config_file:
|
| 120 |
+
config_file.write(config_data)
|
| 121 |
+
# frpc 启动命令和参数
|
| 122 |
+
frpc_cmd = ['/content/frp/frpc', '-c', config_file_path]
|
| 123 |
+
subprocess.Popen(frpc_cmd)
|
| 124 |
+
# /content/frp/frpc -c /content/frp/frpc.ini
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
+
def SillyTavern():
|
| 127 |
+
|
| 128 |
+
# 创建目录并写入 kaggle.json
|
| 129 |
+
os.system("mkdir -p ~/.kaggle")
|
| 130 |
+
file_path = '/root/.kaggle/kaggle.json'
|
| 131 |
+
with open(file_path, 'w') as json_file:
|
| 132 |
+
json.dump(ini_content, json_file, indent=4)
|
| 133 |
+
os.system("chmod 600 ~/.kaggle/kaggle.json")
|
| 134 |
+
|
| 135 |
+
clear_output()
|
| 136 |
+
|
| 137 |
+
os.system("rm -r /a /sillytavern /*.zi* /SillyTavern/")
|
| 138 |
+
os.system("mkdir -p /sillytavern")
|
| 139 |
+
os.system("cd /")
|
| 140 |
+
os.system("kaggle datasets download xovale7506/sillytavern-data")
|
| 141 |
+
|
| 142 |
+
# # 解压 sillytavern.zip
|
| 143 |
+
os.system("7z x /sillytavern-data.zip -o/ -y")
|
| 144 |
+
os.system("mv /sillytavern.zip1 /sillytavern.zip")
|
| 145 |
+
os.system("7z x /sillytavern.zip -o/sillytavern -y")
|
| 146 |
+
os.system("rm *.zip")
|
| 147 |
+
clear_output()
|
| 148 |
+
|
| 149 |
+
# # 拉取最新版本
|
| 150 |
+
# !git clone https://github.com/SillyTavern/SillyTavern.git
|
| 151 |
+
# 强制替换掉备份
|
| 152 |
+
# !rsync -a --delete /SillyTavern/* /sillytavern/
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
# threading.Thread(target=repeat_task, daemon=True).start()
|
| 156 |
+
# threading.Thread(target=Oneapi, daemon=True).start()
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
os.system("cd /sillytavern")
|
| 160 |
+
os.system("ls")
|
| 161 |
+
subprocess.Popen(['yes | sh start.sh'])
|
| 162 |
+
subprocess.Popen(['yes | sh start.sh'])
|
| 163 |
+
# os.system("yes | sh start.sh -y")
|
| 164 |
+
|
| 165 |
+
# commands = [
|
| 166 |
+
# 'yes | sh start.sh -y'
|
| 167 |
+
# ]
|
| 168 |
+
# run_commands(commands)
|
| 169 |
+
SillyTavern()
|