Zheng Qu
commited on
Commit
•
fb9f53e
1
Parent(s):
a761098
testmongdb port
Browse files- app_utils.py +21 -0
- reboot.py +1 -0
app_utils.py
CHANGED
@@ -11,6 +11,8 @@ from tinydb_serialization import SerializationMiddleware
|
|
11 |
from tinydb_sqlite import SQLiteStorage
|
12 |
import tempfile
|
13 |
|
|
|
|
|
14 |
# Configure logging
|
15 |
logging.basicConfig(
|
16 |
level=logging.INFO,
|
@@ -29,6 +31,25 @@ logger.info(f"Session ID: {SESSION_ID}")
|
|
29 |
ADMIN_PASSWD = os.getenv('ADMIN_PASSWD', 'default_password')
|
30 |
import os
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
def explore_persistent_volumes():
|
33 |
# Known persistent directories in Hugging Face Spaces
|
34 |
persistent_dirs = [
|
|
|
11 |
from tinydb_sqlite import SQLiteStorage
|
12 |
import tempfile
|
13 |
|
14 |
+
import socket
|
15 |
+
|
16 |
# Configure logging
|
17 |
logging.basicConfig(
|
18 |
level=logging.INFO,
|
|
|
31 |
ADMIN_PASSWD = os.getenv('ADMIN_PASSWD', 'default_password')
|
32 |
import os
|
33 |
|
34 |
+
|
35 |
+
def is_mongodb_port_open(ip: str, port: int) -> bool:
|
36 |
+
"""Check if the MongoDB port is open on the given IP address."""
|
37 |
+
try:
|
38 |
+
with socket.create_connection((ip, port), timeout=5):
|
39 |
+
return True
|
40 |
+
except (socket.timeout, ConnectionRefusedError, OSError):
|
41 |
+
return False
|
42 |
+
|
43 |
+
# Example usage:
|
44 |
+
MongoDBDomain = os.environ.get("MONGODB_DOMAIN")
|
45 |
+
port_number = 27017 # Default MongoDB port
|
46 |
+
|
47 |
+
if is_mongodb_port_open(MongoDBDomain, port_number):
|
48 |
+
print(f"The MongoDB port {port_number} is open.")
|
49 |
+
else:
|
50 |
+
print(f"The MongoDB port {port_number} on is blocked.")
|
51 |
+
|
52 |
+
|
53 |
def explore_persistent_volumes():
|
54 |
# Known persistent directories in Hugging Face Spaces
|
55 |
persistent_dirs = [
|
reboot.py
CHANGED
@@ -2,6 +2,7 @@ from huggingface_hub import HfApi
|
|
2 |
from dotenv import load_dotenv
|
3 |
import os
|
4 |
|
|
|
5 |
# Replace with your actual token and space details
|
6 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
7 |
REPO_ID = "zqu2004/Test"
|
|
|
2 |
from dotenv import load_dotenv
|
3 |
import os
|
4 |
|
5 |
+
load_dotenv()
|
6 |
# Replace with your actual token and space details
|
7 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
8 |
REPO_ID = "zqu2004/Test"
|