somratpro commited on
Commit
7cd1716
Β·
1 Parent(s): 9535223

refactor: delay workspace sync and guardian startup until after gateway initialization

Browse files
Files changed (2) hide show
  1. start.sh +8 -8
  2. workspace-sync.py +9 -7
start.sh CHANGED
@@ -349,14 +349,6 @@ HEALTH_PID=$!
349
  /home/node/app/keep-alive.sh &
350
  KEEP_ALIVE_PID=$!
351
 
352
- # 12. Start WhatsApp Guardian (Automates pairing)
353
- node /home/node/app/wa-guardian.js &
354
- GUARDIAN_PID=$!
355
- echo "πŸ›‘οΈ WhatsApp Guardian started (PID: $GUARDIAN_PID)"
356
-
357
- # 13. Start Workspace Sync
358
- python3 -u /home/node/app/workspace-sync.py &
359
-
360
  # ── Launch gateway ──
361
  echo "πŸš€ Launching OpenClaw gateway on port 7860..."
362
  echo ""
@@ -376,5 +368,13 @@ if ! kill -0 $GATEWAY_PID 2>/dev/null; then
376
  exit 1
377
  fi
378
 
 
 
 
 
 
 
 
 
379
  # Wait for gateway (allows trap to fire)
380
  wait $GATEWAY_PID
 
349
  /home/node/app/keep-alive.sh &
350
  KEEP_ALIVE_PID=$!
351
 
 
 
 
 
 
 
 
 
352
  # ── Launch gateway ──
353
  echo "πŸš€ Launching OpenClaw gateway on port 7860..."
354
  echo ""
 
368
  exit 1
369
  fi
370
 
371
+ # 12. Start WhatsApp Guardian after the gateway is accepting connections
372
+ node /home/node/app/wa-guardian.js &
373
+ GUARDIAN_PID=$!
374
+ echo "πŸ›‘οΈ WhatsApp Guardian started (PID: $GUARDIAN_PID)"
375
+
376
+ # 13. Start Workspace Sync after startup settles
377
+ python3 -u /home/node/app/workspace-sync.py &
378
+
379
  # Wait for gateway (allows trap to fire)
380
  wait $GATEWAY_PID
workspace-sync.py CHANGED
@@ -21,6 +21,7 @@ WHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")
21
  WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"
22
  RESET_MARKER = WORKSPACE / ".reset_credentials"
23
  INTERVAL = int(os.environ.get("SYNC_INTERVAL", "600"))
 
24
  HF_TOKEN = os.environ.get("HF_TOKEN", "")
25
  HF_USERNAME = os.environ.get("HF_USERNAME", "")
26
  BACKUP_DATASET = os.environ.get("BACKUP_DATASET_NAME", "huggingclaw-backup")
@@ -179,24 +180,25 @@ def sync_with_git():
179
 
180
 
181
  def main():
182
- # Wait for workspace to initialize
183
- time.sleep(30)
184
-
185
  if not WORKSPACE.exists():
186
  print("πŸ“ Workspace sync: workspace not found, exiting.")
187
  return
188
 
189
  use_hf_hub = bool(HF_TOKEN and HF_USERNAME)
 
 
 
 
 
 
 
 
190
 
191
  snapshot_state_into_workspace()
192
 
193
  if use_hf_hub:
194
  print(f"πŸ”„ Workspace sync started (huggingface_hub): every {INTERVAL}s β†’ {HF_USERNAME}/{BACKUP_DATASET}")
195
  else:
196
- git_dir = WORKSPACE / ".git"
197
- if not git_dir.exists():
198
- print("πŸ“ Workspace sync: no git repo and no HF credentials, skipping.")
199
- return
200
  print(f"πŸ”„ Workspace sync started (git): every {INTERVAL}s")
201
 
202
  while running:
 
21
  WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"
22
  RESET_MARKER = WORKSPACE / ".reset_credentials"
23
  INTERVAL = int(os.environ.get("SYNC_INTERVAL", "600"))
24
+ INITIAL_DELAY = int(os.environ.get("SYNC_START_DELAY", "10"))
25
  HF_TOKEN = os.environ.get("HF_TOKEN", "")
26
  HF_USERNAME = os.environ.get("HF_USERNAME", "")
27
  BACKUP_DATASET = os.environ.get("BACKUP_DATASET_NAME", "huggingclaw-backup")
 
180
 
181
 
182
  def main():
 
 
 
183
  if not WORKSPACE.exists():
184
  print("πŸ“ Workspace sync: workspace not found, exiting.")
185
  return
186
 
187
  use_hf_hub = bool(HF_TOKEN and HF_USERNAME)
188
+ git_dir = WORKSPACE / ".git"
189
+
190
+ if not use_hf_hub and not git_dir.exists():
191
+ print("πŸ“ Workspace sync: no git repo and no HF credentials, skipping.")
192
+ return
193
+
194
+ # Give the gateway a short head start before the first sync probe.
195
+ time.sleep(INITIAL_DELAY)
196
 
197
  snapshot_state_into_workspace()
198
 
199
  if use_hf_hub:
200
  print(f"πŸ”„ Workspace sync started (huggingface_hub): every {INTERVAL}s β†’ {HF_USERNAME}/{BACKUP_DATASET}")
201
  else:
 
 
 
 
202
  print(f"πŸ”„ Workspace sync started (git): every {INTERVAL}s")
203
 
204
  while running: