Ahmedik95316 commited on
Commit
b8b6cad
·
1 Parent(s): 2abcc57

Update health_check.sh

Browse files
Files changed (1) hide show
  1. health_check.sh +59 -15
health_check.sh CHANGED
@@ -1,37 +1,81 @@
1
- # Health check script for Docker container
 
 
2
  set -e
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # Check if FastAPI is responding
5
- if ! curl -s -f "http://127.0.0.1:8000/docs" > /dev/null; then
 
6
  echo "FastAPI health check failed"
7
  exit 1
8
  fi
 
9
 
10
- # Check if Streamlit is responding
11
- if ! curl -s -f "http://127.0.0.1:7860/_stcore/health" > /dev/null; then
12
- echo "Streamlit health check failed"
13
- exit 1
 
 
 
14
  fi
15
 
16
- # Check if required files exist
 
 
17
  required_files=(
18
- "/tmp/model.pkl"
19
- "/tmp/vectorizer.pkl"
20
- "/tmp/data/combined_dataset.csv"
21
  )
22
 
 
23
  for file in "${required_files[@]}"; do
24
  if [ ! -f "$file" ]; then
25
  echo "Required file missing: $file"
26
- exit 1
 
 
 
27
  fi
28
  done
29
 
30
- # Check if processes are running
31
- if ! pgrep -f "schedule_tasks.py" > /dev/null; then
32
- echo "Scheduler process not running"
33
  exit 1
34
  fi
35
 
36
- echo "All health checks passed"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  exit 0
 
1
+ #!/bin/bash
2
+
3
+ # Health check script for Docker container with dynamic path detection
4
  set -e
5
 
6
+ # Environment and path detection
7
+ if [ "$HF_SPACES_BUILD" = "1" ] || [ -n "$SPACE_ID" ]; then
8
+ BASE_DIR="/app/persistent"
9
+ ENVIRONMENT="huggingface_spaces"
10
+ else
11
+ BASE_DIR="/tmp"
12
+ ENVIRONMENT="local"
13
+ fi
14
+
15
+ MODEL_DIR="$BASE_DIR/model"
16
+ DATA_DIR="$BASE_DIR/data"
17
+
18
+ echo "Health check running in $ENVIRONMENT environment"
19
+ echo "Base directory: $BASE_DIR"
20
+
21
  # Check if FastAPI is responding
22
+ echo "Checking FastAPI health..."
23
+ if ! curl -s -f "http://127.0.0.1:8000/health" > /dev/null; then
24
  echo "FastAPI health check failed"
25
  exit 1
26
  fi
27
+ echo "FastAPI health check passed"
28
 
29
+ # Check if Streamlit is responding (optional)
30
+ echo "Checking Streamlit health..."
31
+ if ! curl -s -f "http://127.0.0.1:7860/_stcore/health" > /dev/null 2>&1; then
32
+ echo "Streamlit health check failed (this might be normal during startup)"
33
+ # Don't exit on Streamlit failure as it might not be started yet
34
+ else
35
+ echo "Streamlit health check passed"
36
  fi
37
 
38
+ # Check required files with dynamic paths
39
+ echo "Checking required files..."
40
+
41
  required_files=(
42
+ "$MODEL_DIR/pipeline.pkl"
43
+ "$BASE_DIR/metadata.json"
44
+ "$DATA_DIR/combined_dataset.csv"
45
  )
46
 
47
+ missing_files=0
48
  for file in "${required_files[@]}"; do
49
  if [ ! -f "$file" ]; then
50
  echo "Required file missing: $file"
51
+ missing_files=$((missing_files + 1))
52
+ else
53
+ file_size=$(stat -c%s "$file" 2>/dev/null || echo "unknown")
54
+ echo "Required file found: $file (${file_size} bytes)"
55
  fi
56
  done
57
 
58
+ if [ $missing_files -gt 0 ]; then
59
+ echo "Health check failed: $missing_files required files missing"
 
60
  exit 1
61
  fi
62
 
63
+ # Check background processes (optional)
64
+ echo "Checking background processes..."
65
+
66
+ if pgrep -f "schedule_tasks.py" > /dev/null; then
67
+ echo "Scheduler process is running"
68
+ else
69
+ echo "Scheduler process not running (this might be normal)"
70
+ fi
71
+
72
+ if pgrep -f "monitor_drift.py" > /dev/null; then
73
+ echo "Monitor process is running"
74
+ else
75
+ echo "Monitor process not running (this might be normal)"
76
+ fi
77
+
78
+ echo "All critical health checks passed"
79
+ echo "Environment: $ENVIRONMENT"
80
+ echo "Base directory: $BASE_DIR"
81
  exit 0