megadl1 commited on
Commit
c73e334
·
verified ·
1 Parent(s): ce410a6

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +11 -15
start.sh CHANGED
@@ -24,20 +24,20 @@ else
24
  echo "⚠️ No requirements.txt found."
25
  fi
26
 
 
 
 
 
27
  # ----------------------------------------------------------------
28
  # 1. Start Web App (Background)
29
  # ----------------------------------------------------------------
30
  echo "🚀 Starting Web App (Uvicorn)..."
31
  uvicorn main:app --host 0.0.0.0 --port 7860 &
32
- APP_PID=$! # Save PID to keep script running later
33
 
34
  # ----------------------------------------------------------------
35
  # 2. Tor Management Loop
36
  # ----------------------------------------------------------------
37
- # Initialize status
38
- export Tor_stat="failed"
39
-
40
- # Use a named pipe to read logs live without writing to disk
41
  PIPE=/tmp/tor_log_pipe
42
  mkfifo $PIPE
43
 
@@ -45,43 +45,39 @@ while true; do
45
  echo "------------------------------------------------"
46
  echo "🧅 Starting Tor Proxy..."
47
  echo "------------------------------------------------"
 
48
 
49
- # Start Tor in background, redirect both stdout/stderr to the pipe
50
  tor > $PIPE 2>&1 &
51
  TOR_PID=$!
52
 
53
  start_time=$(date +%s)
54
  bootstrapped=false
55
 
56
- # Read the pipe line-by-line
57
  while read -r line; do
58
- # 1. Show live log to terminal
59
  echo "$line"
60
 
61
- # 2. Check for Success
62
  if echo "$line" | grep -q "Bootstrapped 100%"; then
63
  if [ "$bootstrapped" = "false" ]; then
64
  echo "✅ Tor Status: SUCCESS (100% Bootstrapped)"
65
- export Tor_stat="Success"
66
  bootstrapped=true
67
  fi
68
  fi
69
 
70
- # 3. Check Timeout (Only if not yet success)
71
  if [ "$bootstrapped" = "false" ]; then
72
  current_time=$(date +%s)
73
  elapsed=$((current_time - start_time))
74
 
75
- # If 3 minutes (180 seconds) passed without success
76
  if [ "$elapsed" -ge 180 ]; then
77
- echo "⚠️ Timeout: Tor stuck for 3 mins. Killing and Restarting..."
78
  kill -9 $TOR_PID
79
- break # Break the read loop to trigger restart
80
  fi
81
  fi
82
  done < $PIPE
83
 
84
- # If the loop breaks (timeout) or Tor exits, we clean up and retry
85
  wait $TOR_PID
86
  echo "🔄 Tor process ended. Re-looping..."
87
  rm -f $PIPE
 
24
  echo "⚠️ No requirements.txt found."
25
  fi
26
 
27
+ # Define Status File
28
+ STATUS_FILE="/tmp/tor_status"
29
+ echo "initializing" > "$STATUS_FILE"
30
+
31
  # ----------------------------------------------------------------
32
  # 1. Start Web App (Background)
33
  # ----------------------------------------------------------------
34
  echo "🚀 Starting Web App (Uvicorn)..."
35
  uvicorn main:app --host 0.0.0.0 --port 7860 &
36
+ APP_PID=$!
37
 
38
  # ----------------------------------------------------------------
39
  # 2. Tor Management Loop
40
  # ----------------------------------------------------------------
 
 
 
 
41
  PIPE=/tmp/tor_log_pipe
42
  mkfifo $PIPE
43
 
 
45
  echo "------------------------------------------------"
46
  echo "🧅 Starting Tor Proxy..."
47
  echo "------------------------------------------------"
48
+ echo "restarting" > "$STATUS_FILE"
49
 
 
50
  tor > $PIPE 2>&1 &
51
  TOR_PID=$!
52
 
53
  start_time=$(date +%s)
54
  bootstrapped=false
55
 
 
56
  while read -r line; do
 
57
  echo "$line"
58
 
59
+ # Check for Success
60
  if echo "$line" | grep -q "Bootstrapped 100%"; then
61
  if [ "$bootstrapped" = "false" ]; then
62
  echo "✅ Tor Status: SUCCESS (100% Bootstrapped)"
63
+ echo "working" > "$STATUS_FILE"
64
  bootstrapped=true
65
  fi
66
  fi
67
 
68
+ # Check Timeout
69
  if [ "$bootstrapped" = "false" ]; then
70
  current_time=$(date +%s)
71
  elapsed=$((current_time - start_time))
72
 
 
73
  if [ "$elapsed" -ge 180 ]; then
74
+ echo "⚠️ Timeout: Tor stuck. Restarting..."
75
  kill -9 $TOR_PID
76
+ break
77
  fi
78
  fi
79
  done < $PIPE
80
 
 
81
  wait $TOR_PID
82
  echo "🔄 Tor process ended. Re-looping..."
83
  rm -f $PIPE