Update server.py
Browse files
server.py
CHANGED
|
@@ -449,28 +449,16 @@ def replace_ip_and_country_in_file(file_path):
|
|
| 449 |
except Exception as e:
|
| 450 |
print(f"发生其他错误: {e}")
|
| 451 |
|
| 452 |
-
def
|
| 453 |
-
|
| 454 |
-
#
|
| 455 |
-
result =
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
stderr=subprocess.PIPE,
|
| 459 |
-
text=True
|
| 460 |
-
)
|
| 461 |
-
|
| 462 |
-
# 检查返回码和输出
|
| 463 |
-
if result.returncode == 0:
|
| 464 |
-
print(f"{script_name} 正在运行,进程 ID: {result.stdout.strip()}")
|
| 465 |
return True
|
| 466 |
else:
|
| 467 |
-
print(f"{
|
| 468 |
-
subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True)
|
| 469 |
return False
|
| 470 |
-
|
| 471 |
-
except Exception as e:
|
| 472 |
-
print(f"发生错误: {e}")
|
| 473 |
-
return False
|
| 474 |
|
| 475 |
def SillyTavern():
|
| 476 |
print('-----------SillyTavern开始-------------')
|
|
@@ -553,7 +541,9 @@ if os.path.exists('/sillytavern/start.sh'):
|
|
| 553 |
# frp_thread2 = threading.Thread(target=frp, args=(config_data, '/content/frp/frpc.ini', False))
|
| 554 |
# frp_thread2.start()
|
| 555 |
while True:
|
| 556 |
-
|
|
|
|
|
|
|
| 557 |
if backup_thread.is_alive():
|
| 558 |
print("备份线程仍在运行...")
|
| 559 |
else:
|
|
|
|
| 449 |
except Exception as e:
|
| 450 |
print(f"发生其他错误: {e}")
|
| 451 |
|
| 452 |
+
def is_port_in_use(port):
|
| 453 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 454 |
+
# 尝试绑定到指定的端口
|
| 455 |
+
result = sock.connect_ex(('localhost', port))
|
| 456 |
+
if result == 0:
|
| 457 |
+
print(f"端口 {port} 正在使用中")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
return True
|
| 459 |
else:
|
| 460 |
+
print(f"端口 {port} 未被使用")
|
|
|
|
| 461 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
def SillyTavern():
|
| 464 |
print('-----------SillyTavern开始-------------')
|
|
|
|
| 541 |
# frp_thread2 = threading.Thread(target=frp, args=(config_data, '/content/frp/frpc.ini', False))
|
| 542 |
# frp_thread2.start()
|
| 543 |
while True:
|
| 544 |
+
if not is_port_in_use(8000):
|
| 545 |
+
os.chdir('/sillytavern')
|
| 546 |
+
subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True)
|
| 547 |
if backup_thread.is_alive():
|
| 548 |
print("备份线程仍在运行...")
|
| 549 |
else:
|