-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·74 lines (61 loc) · 2.13 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Add public keys to authorized_keys
if [ -n "$PUBLIC_KEY" ]; then
mkdir -p /root/.ssh
echo "$PUBLIC_KEY" > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
# if OW_COMMIT is set, checkout the commit
if [ -n "$OW_COMMIT" ]; then
rm -rf openweights
git clone https://github.com/longtermrisk/openweights.git openweights_dev
cd openweights_dev
git checkout $OW_COMMIT
mv openweights ../openweights
cd ..
rm -rf openweights_dev
fi
# Login to huggingface
python3 -c "from huggingface_hub.hf_api import HfFolder; import os; HfFolder.save_token(os.environ['HF_TOKEN'])"
# Generate SSH host keys
ssh-keygen -A
# Start SSH service
service ssh start
# Print sshd logs to stdout
tail -f /var/log/auth.log &
# Start a simple server that serves the content of main.log on port 10101
# Create main.log if it doesn't exist
touch main.log
# Start a simple Python HTTP server to serve files from logs/
python3 -c '
import http.server
import socketserver
import os
class LogHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
# If path is /logs, serve logs/main
if self.path == "/logs":
file_path = "logs/main"
else:
# Remove leading slash and ensure path is within logs directory
path = self.path.lstrip("/")
file_path = os.path.join("logs", path)
# Check if file exists and is within logs directory
if os.path.exists(file_path) and os.path.commonprefix([os.path.abspath(file_path), os.path.abspath("logs")]) == os.path.abspath("logs"):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
with open(file_path, "rb") as f:
self.wfile.write(f.read())
else:
self.send_error(404, "File not found")
with socketserver.TCPServer(("", 10101), LogHandler) as httpd:
httpd.serve_forever()
' &
mkdir logs
# Execute the main application or run in dev mode
if [ "$OW_DEV" = "true" ]; then
exec tail -f /dev/null
else
exec python3 openweights/worker/main.py > logs/main 2>&1
fi