Spaces:
Sleeping
Sleeping
Rename app-old.py to entrypoint.sh
Browse files- app-old.py +0 -0
- entrypoint.sh +84 -0
app-old.py
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# ------------------------------------------------------------------------------
|
| 5 |
+
# 1. Start sshd on port 22 (internal)
|
| 6 |
+
# ------------------------------------------------------------------------------
|
| 7 |
+
echo "[*] Starting SSH server..."
|
| 8 |
+
/usr/sbin/sshd
|
| 9 |
+
|
| 10 |
+
# Verify sshd is running
|
| 11 |
+
sleep 1
|
| 12 |
+
if ! pgrep sshd > /dev/null; then
|
| 13 |
+
echo "[!] sshd failed to start. Check /etc/ssh/sshd_config"
|
| 14 |
+
exit 1
|
| 15 |
+
fi
|
| 16 |
+
echo "[*] sshd running on port 22"
|
| 17 |
+
|
| 18 |
+
# ------------------------------------------------------------------------------
|
| 19 |
+
# 2. Start gsocket to expose sshd over the gsocket network
|
| 20 |
+
# Connect to it from anywhere with:
|
| 21 |
+
# gsocket -s mypass ssh user@gsocket
|
| 22 |
+
# ------------------------------------------------------------------------------
|
| 23 |
+
echo "[*] Starting gsocket tunnel for SSH (passkey: mypass)..."
|
| 24 |
+
gs-netcat -s mypass -l -e /usr/sbin/sshd &
|
| 25 |
+
GSOCKET_PID=$!
|
| 26 |
+
|
| 27 |
+
# ------------------------------------------------------------------------------
|
| 28 |
+
# 3. Start code-server (VS Code) on port 8080 (internal, optional)
|
| 29 |
+
# ------------------------------------------------------------------------------
|
| 30 |
+
echo "[*] Starting code-server on port 8080..."
|
| 31 |
+
code-server --bind-addr 0.0.0.0:8080 --auth none /app &
|
| 32 |
+
|
| 33 |
+
# ------------------------------------------------------------------------------
|
| 34 |
+
# 4. CRITICAL: Serve HTTP on port 7860
|
| 35 |
+
# Hugging Face Spaces REQUIRES port 7860 to respond with HTTP.
|
| 36 |
+
# Without this the Space shows as "unhealthy" and gets killed.
|
| 37 |
+
# This page also shows connection instructions.
|
| 38 |
+
# ------------------------------------------------------------------------------
|
| 39 |
+
echo "[*] Starting HTTP status page on port 7860..."
|
| 40 |
+
python3 - <<'PYEOF' &
|
| 41 |
+
import http.server, socketserver, os
|
| 42 |
+
|
| 43 |
+
HTML = """<!DOCTYPE html>
|
| 44 |
+
<html>
|
| 45 |
+
<head><title>Dev Space</title>
|
| 46 |
+
<style>
|
| 47 |
+
body { font-family: monospace; background: #1e1e2e; color: #cdd6f4; padding: 2em; }
|
| 48 |
+
h1 { color: #89b4fa; }
|
| 49 |
+
code { background: #313244; padding: 2px 8px; border-radius: 4px; }
|
| 50 |
+
pre { background: #313244; padding: 1em; border-radius: 8px; }
|
| 51 |
+
</style>
|
| 52 |
+
</head>
|
| 53 |
+
<body>
|
| 54 |
+
<h1>🟢 Dev Space is Running</h1>
|
| 55 |
+
<p>Connect via gsocket SSH from any machine:</p>
|
| 56 |
+
<pre>gsocket -s mypass ssh user@localhost</pre>
|
| 57 |
+
<p>Or connect to VS Code:</p>
|
| 58 |
+
<pre>code-server is on internal port 8080</pre>
|
| 59 |
+
</body>
|
| 60 |
+
</html>"""
|
| 61 |
+
|
| 62 |
+
class Handler(http.server.BaseHTTPRequestHandler):
|
| 63 |
+
def do_GET(self):
|
| 64 |
+
self.send_response(200)
|
| 65 |
+
self.send_header("Content-Type", "text/html")
|
| 66 |
+
self.end_headers()
|
| 67 |
+
self.wfile.write(HTML.encode())
|
| 68 |
+
def log_message(self, *args):
|
| 69 |
+
pass # suppress access logs
|
| 70 |
+
|
| 71 |
+
with socketserver.TCPServer(("", 7860), Handler) as httpd:
|
| 72 |
+
print("[*] HTTP status page serving on port 7860")
|
| 73 |
+
httpd.serve_forever()
|
| 74 |
+
PYEOF
|
| 75 |
+
|
| 76 |
+
HTTP_PID=$!
|
| 77 |
+
|
| 78 |
+
# ------------------------------------------------------------------------------
|
| 79 |
+
# 5. Keep the container alive — wait on gsocket
|
| 80 |
+
# ------------------------------------------------------------------------------
|
| 81 |
+
echo "[*] All services started. Space is ready."
|
| 82 |
+
echo " - SSH via gsocket: gsocket -s mypass ssh user@localhost"
|
| 83 |
+
echo " - HTTP status page: http://<your-space>.hf.space"
|
| 84 |
+
wait $GSOCKET_PID
|