Qilan2 commited on
Commit
e62adae
·
verified ·
1 Parent(s): 304f9ab

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +77 -7
server.py CHANGED
@@ -30,6 +30,10 @@ import os
30
  from IPython.display import clear_output
31
  import urllib.request
32
  from pathlib import Path
 
 
 
 
33
  # 更新软件包列表
34
  os.system("sudo apt update")
35
  # 安装 Node.js 和 npm
@@ -50,11 +54,7 @@ def kill_frpc_processes():
50
  kill_frpc_processes()
51
 
52
 
53
-
54
-
55
- import os
56
- import subprocess
57
-
58
  def Oneapi():
59
  # 删除旧的 one-api 文件夹(如果存在)
60
  os.system("rm -rf /one/one-api") # 使用 -f 参数以避免错误
@@ -88,9 +88,79 @@ def Oneapi():
88
 
89
  print(f"OneAPI程序已在后台启动,进程ID为:{process.pid}")
90
 
91
- # 调用函数以启动 OneAPI 服务
92
- Oneapi()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
 
 
 
 
 
 
94
 
 
 
 
 
95
 
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
54
  kill_frpc_processes()
55
 
56
 
57
+ # Oneapi中转
 
 
 
 
58
  def Oneapi():
59
  # 删除旧的 one-api 文件夹(如果存在)
60
  os.system("rm -rf /one/one-api") # 使用 -f 参数以避免错误
 
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
+ run_command("apt update")
100
+ run_command("apt install openssh-server -y")
101
+ run_command("apt-get install vim -y")
102
+ config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config"
103
+ run_command(config_client_cmd)
104
+ config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config"
105
+ run_command(config_server_cmd)
106
+ run_command("systemctl restart ssh")
107
+ os.system("/etc/init.d/ssh restart")
108
+
109
+ os.system("echo 'root:qilan' | sudo chpasswd")
110
+ os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config")
111
+ os.system("service ssh restart ")
112
+ os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ")
113
+ clear_output()
114
+
115
+
116
+ os.system("pip install ruamel.yaml") # install ruamel.yaml to solve the import issue
117
+ from ruamel.yaml import YAML
118
+
119
+ # 创建目录并写入 kaggle.json
120
+ os.system("mkdir -p ~/.kaggle")
121
+ file_path = '/root/.kaggle/kaggle.json'
122
+ with open(file_path, 'w') as json_file:
123
+ json.dump(ini_content, json_file, indent=4)
124
+ os.system("chmod 600 ~/.kaggle/kaggle.json")
125
+
126
+ clear_output()
127
+
128
+ os.system("rm -r /a /sillytavern /*.zi* /SillyTavern/")
129
+ os.system("mkdir -p /sillytavern")
130
+ os.system("cd /")
131
+ os.system("pip install -U kaggle")
132
+ os.system("kaggle datasets download xovale7506/sillytavern-data")
133
 
134
+ # # 解压 sillytavern.zip
135
+ os.system("7z x /sillytavern-data.zip -o/ -y")
136
+ os.system("mv /sillytavern.zip1 /sillytavern.zip")
137
+ os.system("7z x /sillytavern.zip -o/sillytavern -y")
138
+ os.system("rm *.zip")
139
+ clear_output()
140
 
141
+ # # 拉取最新版本
142
+ # !git clone https://github.com/SillyTavern/SillyTavern.git
143
+ # 强制替换掉备份
144
+ # !rsync -a --delete /SillyTavern/* /sillytavern/
145
 
146
 
147
+ # threading.Thread(target=repeat_task, daemon=True).start()
148
+ # threading.Thread(target=Oneapi, daemon=True).start()
149
+ '''FRP配置'''
150
+ os.system("mkdir -p /content/frp")
151
+ os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc")
152
+ os.system("chmod +x /content/frp/frpc")
153
+ config_file_path = '/content/frp/frpc.ini'
154
+ with open(config_file_path, 'w') as config_file:
155
+ config_file.write(config_data)
156
+ # frpc 启动命令和参数
157
+ frpc_cmd = ['/content/frp/frpc', '-c', config_file_path]
158
+ subprocess.Popen(frpc_cmd)
159
+ os.system("cd /sillytavern")
160
+ os.system("ls")
161
+ os.system("yes | sh start.sh -y")
162
+ os.system("yes | sh start.sh -y")
163
+ # commands = [
164
+ # 'yes | sh start.sh -y'
165
+ # ]
166
+ # run_commands(commands)