Qilan2 commited on
Commit
c406f41
·
verified ·
1 Parent(s): 7ea2c53

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +24 -19
server.py CHANGED
@@ -1,8 +1,10 @@
1
  ini_content = {"username":"xovale7506","key":"502e30bafc004c02aa668a279df23f3e"}
2
- st_url = 'http://8.217.96.17:7073'
3
- config_data = """
 
 
4
  [common]
5
- server_addr = 8.217.96.17
6
  server_port = 7000
7
 
8
  [safgasdha]
@@ -14,7 +16,7 @@ remote_port = 7073
14
  type = tcp
15
  local_ip = 127.0.0.1
16
  local_port = 22
17
- remote_port = 7074
18
  [safsdffg]
19
  type = tcp
20
  local_ip = 127.0.0.1
@@ -36,6 +38,8 @@ import json
36
  import threading
37
  import time
38
  import glob # 导入 glob 模块
 
 
39
  # 更新软件包列表
40
  def update():
41
  print('-----------更新软件包列表开始-------------')
@@ -113,11 +117,16 @@ def ssh():
113
  # ssh()
114
  clear_output()
115
 
116
- import requests
117
- import time
118
- import threading
119
- from requests.adapters import HTTPAdapter
120
- from requests.packages.urllib3.util.retry import Retry
 
 
 
 
 
121
 
122
  def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
123
  """创建一个带重试机制的请求会话"""
@@ -128,10 +137,6 @@ def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500,
128
  session.mount('https://', adapter)
129
  return session
130
 
131
- def Frpc():
132
- # 在这里定义 Frpc 函数的逻辑
133
- print("启动 Frpc...")
134
-
135
  def check_api1():
136
  # 第一次检查 SillyTavern 是否启动
137
  while True:
@@ -172,16 +177,19 @@ def check_api1():
172
 
173
  # 检查返回信息是否包含特定内容
174
  if "detail" in response_json and response_json["detail"] in ("Method Not Allowed", "Not Found"):
175
- print("接口正常")
176
  else:
177
  print("接口返回信息:", response_json)
178
 
179
  except requests.exceptions.HTTPError as e:
180
  if e.response.status_code == 403:
181
- print("SillyTavern已经启动") # 再次确认服务已启动
 
 
 
182
  break
183
 
184
- print("接口正常2")
185
 
186
  except requests.exceptions.ConnectionError as e:
187
  print(f"接口异常1: {e}")
@@ -201,9 +209,6 @@ def check_api1():
201
  time.sleep(5) # 等待5秒后重试
202
 
203
 
204
-
205
-
206
-
207
  def frp():
208
  print('-----------FRP开始-------------')
209
  '''FRP配置'''
 
1
  ini_content = {"username":"xovale7506","key":"502e30bafc004c02aa668a279df23f3e"}
2
+ frp_url = '8.217.96.17'
3
+ ssh_port = '7074'
4
+ st_url = f'http://{frp_url}:7073'
5
+ config_data = f"""
6
  [common]
7
+ server_addr = {frp_url}
8
  server_port = 7000
9
 
10
  [safgasdha]
 
16
  type = tcp
17
  local_ip = 127.0.0.1
18
  local_port = 22
19
+ remote_port = {ssh_port}
20
  [safsdffg]
21
  type = tcp
22
  local_ip = 127.0.0.1
 
38
  import threading
39
  import time
40
  import glob # 导入 glob 模块
41
+ from requests.adapters import HTTPAdapter
42
+ from requests.packages.urllib3.util.retry import Retry
43
  # 更新软件包列表
44
  def update():
45
  print('-----------更新软件包列表开始-------------')
 
117
  # ssh()
118
  clear_output()
119
 
120
+ def sync2():
121
+ os.system(f"rsync -avz -e 'ssh -p {ssh_port} -o StrictHostKeyChecking=no' /sillytavern/ root@{frp_url}:/sillytavern/")
122
+ threading.Thread(target=sync2, daemon=True).start()
123
+ def sync():
124
+ os.system("rm -r /rsync.py /sync.sh")
125
+ os.system("wget -O /rsync.py https://huggingface.co/datasets/Qilan2/st-server/resolve/main/rsync.py")
126
+ os.system("wget -O /sync.sh https://huggingface.co/datasets/Qilan2/st-server/resolve/main/sync.sh")
127
+ os.system("chmod +x /sync.sh")
128
+ os.system("chmod +x /sync.py")
129
+ subprocess.Popen(['sh','/sync.sh'])
130
 
131
  def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
132
  """创建一个带重试机制的请求会话"""
 
137
  session.mount('https://', adapter)
138
  return session
139
 
 
 
 
 
140
  def check_api1():
141
  # 第一次检查 SillyTavern 是否启动
142
  while True:
 
177
 
178
  # 检查返回信息是否包含特定内容
179
  if "detail" in response_json and response_json["detail"] in ("Method Not Allowed", "Not Found"):
180
+ print("接口正常1")
181
  else:
182
  print("接口返回信息:", response_json)
183
 
184
  except requests.exceptions.HTTPError as e:
185
  if e.response.status_code == 403:
186
+ print("接口正常2") # 再次确认服务已启动
187
+ if thread_started:
188
+ threading.Thread(target=sync, daemon=True).start()
189
+ thread_started = True # 设置标志为 True,表示线程已经启动过了
190
  break
191
 
192
+ print("接口正常3")
193
 
194
  except requests.exceptions.ConnectionError as e:
195
  print(f"接口异常1: {e}")
 
209
  time.sleep(5) # 等待5秒后重试
210
 
211
 
 
 
 
212
  def frp():
213
  print('-----------FRP开始-------------')
214
  '''FRP配置'''