Arshit Malik commited on
Commit
5b9367d
·
1 Parent(s): edbbeec

fix: python status server on 8080 so nginx never 502s regardless of openclaw

Browse files
Files changed (1) hide show
  1. start.sh +50 -61
start.sh CHANGED
@@ -1,22 +1,22 @@
1
  #!/bin/bash
2
 
3
- echo "[boot] Kaggle creds..."
4
  if [ -n "$KAGGLE_USERNAME" ] && [ -n "$KAGGLE_KEY" ]; then
5
  mkdir -p ~/.kaggle
6
  printf '{"username":"%s","key":"%s"}' "$KAGGLE_USERNAME" "$KAGGLE_KEY" > ~/.kaggle/kaggle.json
7
  chmod 600 ~/.kaggle/kaggle.json
8
  fi
9
 
10
- echo "[boot] YouTube secrets..."
11
  if [ -n "$YOUTUBE_CLIENT_ID" ] && [ -n "$YOUTUBE_CLIENT_SECRET" ]; then
12
  python3 -c "
13
  import json,os
14
  d={'installed':{'client_id':os.environ['YOUTUBE_CLIENT_ID'],'project_id':'yt-ai-bot','auth_uri':'https://accounts.google.com/o/oauth2/auth','token_uri':'https://oauth2.googleapis.com/token','auth_provider_x509_cert_url':'https://www.googleapis.com/oauth2/v1/certs','client_secret':os.environ['YOUTUBE_CLIENT_SECRET'],'redirect_uris':['http://localhost']}}
15
- open('/app/client_secrets.json','w').write(json.dumps(d))"
16
- echo "[boot] client_secrets.json written"
17
  fi
18
 
19
- echo "[boot] HF Dataset pull..."
20
  python3 -c "
21
  import sys; sys.path.insert(0,'/app')
22
  try:
@@ -24,75 +24,64 @@ try:
24
  from pathlib import Path
25
  pull_state(Path('/app'))
26
  except Exception as e:
27
- print('[boot] pull skipped:', e)
28
  "
29
 
30
- echo "[boot] Nginx..."
31
  nginx
32
 
33
- echo "[boot] Ollama..."
34
  OLLAMA_HOST=127.0.0.1 ollama serve &
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  for i in $(seq 1 60); do
36
- curl -sf http://127.0.0.1:11434/api/tags > /dev/null 2>&1 && echo "[boot] Ollama ready after ${i}s" && break
 
 
37
  sleep 2
38
  done
39
- ollama pull qwen2.5-coder:7b-instruct
40
 
41
- echo "[boot] OpenClaw config..."
42
- mkdir -p ~/.openclaw
43
- GPASS="${OPENCLAW_PASSWORD:-arshit2025}"
44
- python3 -c "
45
- import json, os
46
- cfg = {
47
- 'models': {
48
- 'providers': {
49
- 'ollama': {
50
- 'baseUrl': 'http://127.0.0.1:11434/v1',
51
- 'apiKey': 'ollama-local',
52
- 'api': 'openai-responses',
53
- 'models': [{
54
- 'id': 'qwen2.5-coder:7b-instruct',
55
- 'name': 'Qwen2.5-Coder 7B',
56
- 'contextWindow': 8192,
57
- 'maxTokens': 2048,
58
- 'cost': {'input':0,'output':0,'cacheRead':0,'cacheWrite':0},
59
- 'input': ['text']
60
- }]
61
- }
62
- }
63
- },
64
- 'agents': {'defaults': {'model': {'primary': 'ollama/qwen2.5-coder:7b-instruct'}}},
65
- 'gateway': {'port': 8080, 'password': os.environ.get('OPENCLAW_PASSWORD','arshit2025')}
66
- }
67
- json.dump(cfg, open(os.path.expanduser('~/.openclaw/openclaw.json'),'w'), indent=2)
68
- print('[boot] openclaw.json written, gateway.password =', cfg['gateway']['password'])
69
- "
70
- cp /app/SOUL.md ~/.openclaw/SOUL.md
71
 
72
- echo "[boot] Pipeline..."
73
  python3 /app/automation.py >> /app/pipeline.log 2>&1 &
74
  echo "[boot] Pipeline PID: $!"
75
 
76
- echo "[boot] Starting OpenClaw gateway..."
77
- export OPENCLAW_API_PORT=8080
78
  export OLLAMA_HOST=http://127.0.0.1:11434
79
- openclaw gateway start &
80
- OC_PID=$!
81
- sleep 5
82
-
83
- if ! kill -0 $OC_PID 2>/dev/null; then
84
- echo "[boot] OpenClaw died, starting fallback HTTP server on 8080..."
85
- python3 -c "
86
- from http.server import HTTPServer, BaseHTTPRequestHandler
87
- class H(BaseHTTPRequestHandler):
88
- def do_GET(self):
89
- msg = b'<h1>Pipeline Running</h1><p>OpenClaw UI starting...</p>'
90
- self.send_response(200); self.send_header('Content-Type','text/html')
91
- self.end_headers(); self.wfile.write(msg)
92
- def log_message(self, *a): pass
93
- HTTPServer(('0.0.0.0', 8080), H).serve_forever()
94
- " &
95
- fi
96
 
97
- echo "[boot] Done. Sleeping..."
98
  sleep infinity
 
1
  #!/bin/bash
2
 
3
+ echo "[boot] Configuring Kaggle credentials..."
4
  if [ -n "$KAGGLE_USERNAME" ] && [ -n "$KAGGLE_KEY" ]; then
5
  mkdir -p ~/.kaggle
6
  printf '{"username":"%s","key":"%s"}' "$KAGGLE_USERNAME" "$KAGGLE_KEY" > ~/.kaggle/kaggle.json
7
  chmod 600 ~/.kaggle/kaggle.json
8
  fi
9
 
10
+ echo "[boot] Configuring YouTube client secrets..."
11
  if [ -n "$YOUTUBE_CLIENT_ID" ] && [ -n "$YOUTUBE_CLIENT_SECRET" ]; then
12
  python3 -c "
13
  import json,os
14
  d={'installed':{'client_id':os.environ['YOUTUBE_CLIENT_ID'],'project_id':'yt-ai-bot','auth_uri':'https://accounts.google.com/o/oauth2/auth','token_uri':'https://oauth2.googleapis.com/token','auth_provider_x509_cert_url':'https://www.googleapis.com/oauth2/v1/certs','client_secret':os.environ['YOUTUBE_CLIENT_SECRET'],'redirect_uris':['http://localhost']}}
15
+ open('/app/client_secrets.json','w').write(json.dumps(d))
16
+ print('[boot] client_secrets.json written')"
17
  fi
18
 
19
+ echo "[boot] Pulling state from HF Dataset..."
20
  python3 -c "
21
  import sys; sys.path.insert(0,'/app')
22
  try:
 
24
  from pathlib import Path
25
  pull_state(Path('/app'))
26
  except Exception as e:
27
+ print(f'[boot] Hub pull skipped: {e}')
28
  "
29
 
30
+ echo "[boot] Starting nginx..."
31
  nginx
32
 
33
+ echo "[boot] Starting Ollama..."
34
  OLLAMA_HOST=127.0.0.1 ollama serve &
35
+
36
+ echo "[boot] Starting status server on port 8080..."
37
+ python3 -c "
38
+ import http.server, threading, os, time
39
+
40
+ class Handler(http.server.BaseHTTPRequestHandler):
41
+ def do_GET(self):
42
+ try:
43
+ log = open('/app/pipeline.log').read()[-3000:]
44
+ except:
45
+ log = 'No log yet.'
46
+ body = f'''<!DOCTYPE html><html><head><meta charset=utf-8>
47
+ <meta http-equiv=refresh content=30>
48
+ <title>YT Pipeline</title>
49
+ <style>body{{font-family:monospace;background:#111;color:#0f0;padding:20px}}
50
+ pre{{background:#000;padding:10px;overflow-x:auto;white-space:pre-wrap}}</style>
51
+ </head><body>
52
+ <h2>YouTube Shorts Pipeline</h2>
53
+ <p>Space is running. Pipeline log (last 3000 chars, auto-refreshes every 30s):</p>
54
+ <pre>{log}</pre>
55
+ </body></html>'''.encode()
56
+ self.send_response(200)
57
+ self.send_header('Content-Type','text/html')
58
+ self.send_header('Content-Length',str(len(body)))
59
+ self.end_headers()
60
+ self.wfile.write(body)
61
+ def log_message(self, *a): pass
62
+
63
+ httpd = http.server.HTTPServer(('0.0.0.0', 8080), Handler)
64
+ print('[status] Server running on port 8080')
65
+ httpd.serve_forever()
66
+ " &
67
+
68
+ echo "[boot] Waiting for Ollama..."
69
  for i in $(seq 1 60); do
70
+ if curl -sf http://127.0.0.1:11434/api/tags > /dev/null 2>&1; then
71
+ echo "[boot] Ollama ready after ${i}s"; break
72
+ fi
73
  sleep 2
74
  done
 
75
 
76
+ echo "[boot] Pulling qwen2.5-coder:7b-instruct..."
77
+ ollama pull qwen2.5-coder:7b-instruct
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
+ echo "[boot] Starting pipeline..."
80
  python3 /app/automation.py >> /app/pipeline.log 2>&1 &
81
  echo "[boot] Pipeline PID: $!"
82
 
83
+ echo "[boot] Trying OpenClaw (optional)..."
 
84
  export OLLAMA_HOST=http://127.0.0.1:11434
85
+ openclaw gateway start || echo "[boot] OpenClaw unavailable, status server is active"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
 
87
  sleep infinity