Update server.py
Browse files
server.py
CHANGED
|
@@ -23,6 +23,22 @@ local_ip = 127.0.0.1
|
|
| 23 |
local_port = 873
|
| 24 |
remote_port = 7075
|
| 25 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
kaggle_metadata = {
|
| 27 |
"title": "Your Dataset Title",
|
| 28 |
"id": "xovale7506/sillytavern-data",
|
|
@@ -160,12 +176,15 @@ def sync():
|
|
| 160 |
copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
|
| 161 |
commands = [
|
| 162 |
"rm -rf /rsync.py /sync.sh",
|
| 163 |
-
"wget -O /rsync.py https://huggingface.co/datasets/Qilan2/st-server/resolve/main/rsync.py",
|
| 164 |
-
"wget -O /sync.sh https://huggingface.co/datasets/Qilan2/st-server/resolve/main/sync.sh",
|
| 165 |
"chmod +x /sync.sh",
|
| 166 |
"chmod +x /rsync.py"
|
| 167 |
]
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
| 169 |
for command in commands:
|
| 170 |
print(f"Running: {command}")
|
| 171 |
if os.system(command) != 0:
|
|
@@ -173,13 +192,9 @@ def sync():
|
|
| 173 |
return # 如果有命令失败,则退出函数
|
| 174 |
|
| 175 |
# 启动 sync.sh 脚本,并传递参数
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
stdout, stderr = process.communicate()
|
| 179 |
|
| 180 |
-
|
| 181 |
-
if stderr:
|
| 182 |
-
print("Error:", stderr.decode())
|
| 183 |
|
| 184 |
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|
| 185 |
"""创建一个带重试机制的请求会话"""
|
|
|
|
| 23 |
local_port = 873
|
| 24 |
remote_port = 7075
|
| 25 |
"""
|
| 26 |
+
script_content = f"""#!/bin/bash
|
| 27 |
+
|
| 28 |
+
# 定义源和目标路径
|
| 29 |
+
SOURCE="/a/"
|
| 30 |
+
DESTINATION="root@{frp_url}:/a/"
|
| 31 |
+
PORT={ssh_port}
|
| 32 |
+
PASSWORD="qilan" # 将你的密码放在这里
|
| 33 |
+
|
| 34 |
+
# 使用 inotifywait 监控源目录的变化
|
| 35 |
+
while true; do
|
| 36 |
+
# 等待文件创建、修改或删除事件,并执行 rsync 同步命令。
|
| 37 |
+
inotifywait -r -e modify,create,delete "$SOURCE"
|
| 38 |
+
# 执行 rsync 同步命令,使用 sshpass 自动输入密码。
|
| 39 |
+
rsync -avz -e "ssh -p $PORT -o StrictHostKeyChecking=no" "$SOURCE" "$DESTINATION"
|
| 40 |
+
done
|
| 41 |
+
"""
|
| 42 |
kaggle_metadata = {
|
| 43 |
"title": "Your Dataset Title",
|
| 44 |
"id": "xovale7506/sillytavern-data",
|
|
|
|
| 176 |
copy_public_key_to_remote(frp_url, ssh_port, "root", "qilan")
|
| 177 |
commands = [
|
| 178 |
"rm -rf /rsync.py /sync.sh",
|
| 179 |
+
# "wget -O /rsync.py https://huggingface.co/datasets/Qilan2/st-server/resolve/main/rsync.py",
|
| 180 |
+
# "wget -O /sync.sh https://huggingface.co/datasets/Qilan2/st-server/resolve/main/sync.sh",
|
| 181 |
"chmod +x /sync.sh",
|
| 182 |
"chmod +x /rsync.py"
|
| 183 |
]
|
| 184 |
+
# 写入到 /sync.sh 文件中
|
| 185 |
+
with open('/sync.sh', 'w') as file:
|
| 186 |
+
file.write(script_content)
|
| 187 |
+
|
| 188 |
for command in commands:
|
| 189 |
print(f"Running: {command}")
|
| 190 |
if os.system(command) != 0:
|
|
|
|
| 192 |
return # 如果有命令失败,则退出函数
|
| 193 |
|
| 194 |
# 启动 sync.sh 脚本,并传递参数
|
| 195 |
+
subprocess.run('sh /sync.sh', shell=True, check=True)
|
|
|
|
|
|
|
| 196 |
|
| 197 |
+
|
|
|
|
|
|
|
| 198 |
|
| 199 |
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|
| 200 |
"""创建一个带重试机制的请求会话"""
|